The setup.py for coremltools specifies the numpy dependency range as 'numpy >= 1.14.5'. However using any version before then 1.16.0 causes a segmentation fault. Any version >= to 1.16.0 works.
It would be nice to support versions before 1.16.0. That version is less than a year old. However at the very least the specified dependency ranges should be accurate.
No trace displayed. Only output is Segmentation fault: 11
In a fresh/new Conda environment, run:
pip install Pillow coremltools==3.0b6 numpy==1.15.4
Download the MNIST Model.
Execute the following code:
import coremltools
from PIL import Image
import numpy as np
data = np.empty((28,28), dtype=np.uint8)
input_image = Image.fromarray(data)
model = coremltools.models.MLModel('./Downloads/MNISTClassifier.mlmodel')
print(model.predict({'image': input_image}))
This give a segmentation fault.
If you then run pip install numpy==1.16.0, then the above code works.
Can I work on this issue?
Can I work on this issue?
Hi @Shekharrajak, you're more than welcome to contribute here. Thanks!
Thanks @1duo !
I just need a clarification :
Do we want to make it compatible for version < 1.16.0 or should we constraint version >= 1.16.0 in setup.py ?
Thanks @1duo !
I just need a clarification :
Do we want to make it compatible for version < 1.16.0 or should we constraint version >= 1.16.0 in setup.py ?
Hi @TobyRoseman, it'd be great if you can comment on / clarify the expected version we want to cover here. Thanks!
The most important thing is that the version range listed in setup.py is accurate.
That being said, coremltools should really support numpy versions older than 9 months ago. I believe numpy is very good about backwards compatibility. It would be great if we could actually support numpy >= 1.14.5 or even earlier.
coremltools==2.1.0 works just fine with numpy==1.14.5. What changed? What version of numpy was installed in the environments that built the most recent artifacts for PyPI? The fix could be as simple as just installing an old version of numpy in those environments. I think that is worth a try.
I followed the steps given :
mkdir build
cd build
cmake ../
make
but I got the error :
error: unknown type name 'MLSequence'
py::object convertSequenceValueToPython(MLSequence *seq) API_AVAILABLE(macos(10.14));
^
/Users/coremltools/coremlpython/CoreMLPython.mm:58:13: error: unknown type name 'MLModelConfiguration'
MLModelConfiguration *configuration = [MLModelConfiguration new];
^
/User/coremltools/coremlpython/CoreMLPython.mm:58:52: error: use of undeclared identifier 'MLModelConfiguration'
MLModelConfiguration *configuration = [MLModelConfiguration new];
^
/Users/coremltools/coremlpython/CoreMLPython.mm:60:46: error: use of undeclared identifier 'MLComputeUnitsCPUOnly'
configuration.computeUnits = MLComputeUnitsCPUOnly;
^
8 warnings and 4 errors generated.
make[2]: *** [CMakeFiles/coremlpython.dir/coremlpython/CoreMLPython.mm.o] Error 1
make[1]: *** [CMakeFiles/coremlpython.dir/all] Error 2
make: *** [all] Error 2
Can you please help me to get the setup done ?
I followed the steps given :
mkdir build cd build cmake ../ makebut I got the error :
error: unknown type name 'MLSequence' py::object convertSequenceValueToPython(MLSequence *seq) API_AVAILABLE(macos(10.14)); ^ /Users/coremltools/coremlpython/CoreMLPython.mm:58:13: error: unknown type name 'MLModelConfiguration' MLModelConfiguration *configuration = [MLModelConfiguration new]; ^ /User/coremltools/coremlpython/CoreMLPython.mm:58:52: error: use of undeclared identifier 'MLModelConfiguration' MLModelConfiguration *configuration = [MLModelConfiguration new]; ^ /Users/coremltools/coremlpython/CoreMLPython.mm:60:46: error: use of undeclared identifier 'MLComputeUnitsCPUOnly' configuration.computeUnits = MLComputeUnitsCPUOnly; ^ 8 warnings and 4 errors generated. make[2]: *** [CMakeFiles/coremlpython.dir/coremlpython/CoreMLPython.mm.o] Error 1 make[1]: *** [CMakeFiles/coremlpython.dir/all] Error 2 make: *** [all] Error 2Can you please help me to get the setup done ?
Can you share your system environment info?
Here is the system I am using
coremltools version (e.g., 3.0b5): Didn't install prevously. trying to instal from source
OS (e.g., MacOS, Linux): MacOS
macOS version (if applicable): 10.13
XCode version (if applicable): Not using
How you install python (anaconda, virtualenv, system): conda
python version (e.g. 3.7): 3.7.3
I installed the codemltool using pip not through source but I came across different error messege :
[ 92%] Building CXX object CMakeFiles/caffeconverter.dir/deps/caffe/src/caffe/proto/caffe.pb.cc.o
[ 92%] Building CXX object CMakeFiles/caffeconverter.dir/deps/caffe/src/caffe/util/upgrade_proto.cpp.o
[ 93%] Linking CXX shared library libcaffeconverter.dylib
ld: file not found: /Users/miniconda3/envs/apple-dev/lib/arc/libarclite_macosx.a
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libcaffeconverter.dylib] Error 1
make[1]: *** [CMakeFiles/caffeconverter.dir/all] Error 2
make: *** [all] Error 2
Can you please help me to resolve this? Thanks!
Here is the system I am using
coremltools version (e.g., 3.0b5): Didn't install prevously. trying to instal from source
OS (e.g., MacOS, Linux): MacOS
macOS version (if applicable): 10.13
XCode version (if applicable): Not using
How you install python (anaconda, virtualenv, system): conda
python version (e.g. 3.7): 3.7.3
Hi @Shekharrajak, the build issue you're hitting is because of the out-dated macOS version (10.13). In the error message, you can see it requires a minimum of macOS 10.14.
py::object convertSequenceValueToPython(MLSequence *seq) API_AVAILABLE(macos(10.14));
Oh! Thanks for letting me know this. I have upgraded the system and it is completed now.
Can you please let me know how can I use the cloned repos and generated build to test the code. I tried running
import coremltools
from PIL import Image
import numpy as np
inside the cloned repo.
@Shekharrajak You can now try to build from source again: https://github.com/apple/coremltools#building-from-source
Yes, I tried the same and after that I am running the code snippet (of the issue description):
>>> import coremltools
/Users/miniconda3/envs/apple-dev/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
/Users/miniconda3/envs/apple-dev/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/Users/miniconda3/envs/apple-dev/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
/Users/miniconda3/envs/apple-dev/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/Users/miniconda3/envs/apple-dev/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
/Users/miniconda3/envs/apple-dev/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
WARNING:root:Keras version 2.2.5 detected. Last version known to be fully compatible of Keras is 2.2.4 .
>>> from PIL import Image
>>> import numpy as np
>>> data = np.empty((28,28), dtype=np.uint8)
>>> input_image = Image.fromarray(data)
>>> model = coremltools.models.MLModel('../models/MNISTClassifier.mlmodel')
>>> print(model.predict({'image': input_image}))
exception loading model proxy: No module named 'coremltools.libcoremlpython'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/apple/coremltools/coremltools/models/model.py", line 350, in predict
raise Exception('Unable to load CoreML.framework. Cannot make predictions.')
Exception: Unable to load CoreML.framework. Cannot make predictions.
Hi @Shekharrajak, we'll investigate this build issue, in the meantime, this is due to missing libcoremlpython .so file, you can copy it from <your_build_dir>/coremltools/*.so to <coremltools_repo_root_dir>/coremltools/*.so and run pip install -e . so you have a working developer enviroment. You can verify using python -m pytest coremltools/converters/tensorflow/test/test_convnets.py -v
Installing the oldest version of numpy we want to support, before running cmake and make, solves this issue.
This is not fixed in 3.2. We still get a segfault using the original instructions. Reopening.