I'm using CoreML Tools to port a trained model created in Keras to iOS.
The accuracy rate has deteriorated significantly, so I was told to update to High Sierra when I tried to do MLModel # predict ()
to check it on my PC.
I couldn't help it, so I updated it, but the situation got worse, so I made a memorandum.
coremltools.converters.keras.convert ()
, MLModel # save ()
) works fine
--When I try to load a model (coremltools.models.MLModel
), I get an OS version error.Download and install from Apple's developer portal. About 40 minutes?
>>> model = coremltools.models.MLModel('HogeModel.mlmodel')
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6
Error loading model
When I tried it in a hurry, the same error occurred when converting the model (to be exact, MLModel # save ()
in the save process).
Looking into the error, it seems that CoreML Tools is for the macOS bundled version of Python. http://qiita.com/hatchinee/items/b16ee02b3c93603aee0c
It seemed that install_name_tool could be used if the details of the object that was throwing the error were known, but since I didn't understand the inside of CoreML Tools well (because I didn't have time), I switched to the bundled version of Python (/ usr / bin / python) for the time being.
However, it didn't work because the old settings of Pyenv remained, so I called the bundled version with the full path and reinstalled only pip. It's hard so I have to clean this area soon.
$ which python
/usr/local/bin/python
$ python --version
Python 2.7.13
$ /usr/bin/python --version
Python 2.7.10
$ which pip
/usr/local/bin/pip
$ pip --version
pip 9.0.1 from /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)
If the pyenv environment wasn't dirty, could I just switch to system ...
Dependent libraries (coremltools, keras, tensorflow, numpy, h5py) need to be reinstalled, but High Sierra fails to install with pip due to SIP (rootless) like Sierra.
I don't like that and run away to the Homebrew version, but this time it doesn't happen, so I run away with the --user
option for the time being.
$ pip install --user tensorflow coremltools
If you are using / Users / username / Library / Python / 2.7 / lib / python / site-packages
with Python 2.7 (for everyday use) such as Homebrew version, the installation destination will be affected, so You need to change the direction of the --user
option.
http://qiita.com/ronin_gw/items/cdf8112b61649ca455f5 or something?
In my case, the Homebrew version was more suitable for /usr/local/lib/python2.7/site-packages
, so it should be okay for the time being. .. ..
--Model conversion: OK --Model loading: NG
The load itself succeeded, but the essential reasoning execution failed.
>>> result = model.predict({'image': x})
~ Omitted ~
Exception: Unable to load CoreML.framework. Cannot make predictions.
Is it useless after all?
--Bundling Python binding & 2.7 binding is troublesome, thinking that it can not be helped because it will use OS functions. .. .. ――Note that CoreML Tools seems to have some members that are methods or quite drastic even if you look at the official API reference. ――I want to try full functionality as soon as possible. --Also, the Python environment has become dirty.
Recommended Posts