Search code examples
python-3.xswiftcoreml

ModuleNotFoundError: No module named 'coremltools'


I am new in CoreML and I am facing problem while converting file to mlmodule my code is like this

import coremltools

caffe_model = ('oxford102.caffemodel','deploy.prototxt')

labels = 'flower-labels.txt'

coreml_model = coremltools.converters.caffe.convert(
    caffe_model,
    class_label = labels,
    image_input_name = 'data'
)

coreml_model.save('FlowerClassifer.mlmodel')

when I write a code python convert-script.py I am getting error

import coremltools

ModuleNotFoundError: No module named 'coremltools'

I have tried everything available on internet. My python version is 3.9 and on internet it is showing that coremltools required python version 2.7 How can I solve this problem `I am using Mac


Solution

  • You may be missing the required package. Try

    pip3 install coremltools
    
    python3 convert-script.py
    

    it should do the job.