Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing lastest pycocotools fails on numpy.ufunc size changed error #248

Open
guysoft opened this issue Jan 16, 2019 · 18 comments
Open

Comments

@guysoft
Copy link

guysoft commented Jan 16, 2019

Ran pip3 install pycocotools

Then when I trying to import I get:

>>> from pycocotools.coco import COCO
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/venv/lib/python3.5/site-packages/pycocotools/coco.py", line 55, in <module>
    from . import mask as maskUtils
  File "/venv/lib/python3.5/site-packages/pycocotools/mask.py", line 3, in <module>
    import pycocotools._mask as _mask
  File "__init__.pxd", line 918, in init pycocotools._mask
ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObject
>>> 

Related:
hooram/ownphotos#56

@joyyang1215
Copy link

The same error!

@PrakrutiChandak
Copy link

image
same issue. It would be a great help. Thank you in advance!

@learner0903
Copy link

Same error!

@PrakrutiChandak
Copy link

PrakrutiChandak commented Jan 29, 2019

instead of using pip, try using this:

(pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI)

I guess pip doesn't install everything, and git clone does.
Also, keep your cache clean.

@sinter-w
Copy link

The same error!!!

@LarissaCasteluci
Copy link

LarissaCasteluci commented Feb 5, 2019

I tried using older versions of cocoapi as well as older versions of cython. I am really clueless to where the problem is from.

I get this error when the code tries to import pycocotools._mask:

File "__init__.pxd", line 918, in init pycocotools._mask

ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObject

@guysoft
Copy link
Author

guysoft commented Feb 5, 2019

We switched to install via conda to avoid this. Which is a pretty bad workaround.

@guysoft
Copy link
Author

guysoft commented Feb 5, 2019

@PrakrutiChandak Your solution is to use a different repository, its not a real solution to this current codebase. If there is a fix there it would be a good idea to PR it.

@LarissaCasteluci
Copy link

LarissaCasteluci commented Feb 6, 2019

I found out what I was doing wrong. I was compiling the pycocotools folder on my host OS, while trying to use it with a docker container. If you are using virtual environments be sure to be consistent with them.

@woshisj
Copy link

woshisj commented Feb 27, 2019

I solve it like #14 (comment)

$ git clone https://github.com/pdollar/coco.git
$ cd coco/PythonAPI
$ make
$python setup.py install

@gouthamvgk
Copy link

I faced the same problem. Solved it by installing the numpy version 1.15.1

@chAwater
Copy link

I faced the same problem.

In my case, I think it because the numpy version changed after I installed pycocotools by pip (Both conda and pip might cause that version change).

So, I solved it by clear the Python environment, make sure there is only ONE version of numpy in the environment.

@buncybunny
Copy link

I found out what I was doing wrong. I was compiling the pycocotools folder on my host OS, while trying to use it with a docker container. If you are using virtual environments be sure to be consistent with them.

can you please give me some specific ways to solve this problem? I think my problem is exactly same as yours...

@duffjay
Copy link

duffjay commented Mar 6, 2021

I faced the same problem - not windows, not a docker situation.
Not sure where I went wrong.
numpy was not the problem
Ubuntu 18.04 (and 20.04)
TF 2.4 (I was following the object detection tutorial install instructions)
Python 3.7 (Ubuntu 18.04), 3.8 (20.04)

error:
File "/home/jay/anaconda3/envs/tf24/lib/python3.7/site-packages/pycocotools/mask.py", line 3, in
import pycocotools._mask as _mask
File "pycocotools/_mask.pyx", line 1, in init pycocotools._mask
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

here's how I flxed it.
go to the env directory, in my case:
/home/jay/anaconda3/envs/tf24/lib/python3.7/site-packages/pycocotools
list the files

git clone the coco project, make per the instructions
you'll have compiled products in (my example):
/project/cocoapi/PythonAPI/pycocotools/

the two lists should be about the same.
delete the files in: /home/jay/anaconda3/envs/tf24/lib/python3.7/site-packages/pycocotools
copy over the files from: /project/cocoapi/PythonAPI/pycocotools/

evidently, the _mask.pyx file has a problem
Not sure why this worked but it worked for me

@antedesk
Copy link

@duffjay you kinda save my day.

Your solution worked for me.

BTW fun fact:
I didn't experience this issue on Google Colab. Then I moved to GCP using the Deep Learning VM product in order to have an already configured env and I experienced this issue.

@jason-su
Copy link

I have the same error, and solve it by:

pip uninstall pycocotools
pip install pycocotools

update pycocotools from 2.0 to 2.0.2,

@vriez
Copy link

vriez commented Apr 20, 2021

pycocotools==2.0.2
numpy==1.20.2

did the trick.

@dreamgonsalves
Copy link

pycocotools==2.0.2
numpy==1.20.2

did the trick.

Tried this but now getting different error:
NotImplementedError: Cannot convert a symbolic Tensor (strided_slice:0) to a numpy array.

Please help

tianleiwu added a commit to microsoft/onnxruntime that referenced this issue Jul 29, 2023
### Description
Python Package Pipeline failed since there is exception raised in
test_smooth_quant (from #16288):
```
File "/home/cloudtest/.local/lib/python3.8/site-packages/onnxruntime/quantization/quantize.py", line 384, in quantize_static
    importlib.import_module("neural_compressor.adaptor.ox_utils.smooth_quant")
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/__init__.py", line 24, in <module>
    from .contrib import *
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/contrib/__init__.py", line 19, in <module>
    from .strategy import *
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/contrib/strategy/__init__.py", line 26, in <module>
    __import__(basename(f)[:-3], globals(), locals(), level=1)
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/contrib/strategy/sigopt.py", line 22, in <module>
    from neural_compressor.strategy.strategy import strategy_registry, TuneStrategy
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/strategy/__init__.py", line 20, in <module>
    from .strategy import STRATEGIES
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/strategy/strategy.py", line 41, in <module>
    from ..algorithm import AlgorithmScheduler, ALGORITHMS
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/algorithm/__init__.py", line 20, in <module>
    from .algorithm import ALGORITHMS, Algorithm, AlgorithmScheduler, algorithm_registry
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/algorithm/algorithm.py", line 21, in <module>
    from neural_compressor.utils.create_obj_from_config import get_algorithm
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/utils/create_obj_from_config.py", line 20, in <module>
    from neural_compressor.metric import METRICS
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/metric/__init__.py", line 30, in <module>
    __import__(basename(f)[:-3], globals(), locals(), level=1)
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/metric/coco_tools.py", line 54, in <module>
    from pycocotools import coco
  File "/usr/local/lib/python3.8/dist-packages/pycocotools/coco.py", line 52, in <module>
    from . import mask as maskUtils
  File "/usr/local/lib/python3.8/dist-packages/pycocotools/mask.py", line 3, in <module>
    import pycocotools._mask as _mask
  File "pycocotools/_mask.pyx", line 1, in init pycocotools._mask
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```
The cause is pycocotools package uses "oldest-supported-numpy", which
might cause older version numpy in build pycocotools:

https://github.com/ppwwyyxx/cocoapi/blob/9e9164f979fe4265c6f387f10e234f8697a15922/PythonAPI/pyproject.toml#L4

Related issue: cocodataset/cocoapi#248

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
jchen351 pushed a commit to microsoft/onnxruntime that referenced this issue Aug 12, 2023
### Description
Python Package Pipeline failed since there is exception raised in
test_smooth_quant (from #16288):
```
File "/home/cloudtest/.local/lib/python3.8/site-packages/onnxruntime/quantization/quantize.py", line 384, in quantize_static
    importlib.import_module("neural_compressor.adaptor.ox_utils.smooth_quant")
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/__init__.py", line 24, in <module>
    from .contrib import *
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/contrib/__init__.py", line 19, in <module>
    from .strategy import *
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/contrib/strategy/__init__.py", line 26, in <module>
    __import__(basename(f)[:-3], globals(), locals(), level=1)
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/contrib/strategy/sigopt.py", line 22, in <module>
    from neural_compressor.strategy.strategy import strategy_registry, TuneStrategy
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/strategy/__init__.py", line 20, in <module>
    from .strategy import STRATEGIES
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/strategy/strategy.py", line 41, in <module>
    from ..algorithm import AlgorithmScheduler, ALGORITHMS
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/algorithm/__init__.py", line 20, in <module>
    from .algorithm import ALGORITHMS, Algorithm, AlgorithmScheduler, algorithm_registry
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/algorithm/algorithm.py", line 21, in <module>
    from neural_compressor.utils.create_obj_from_config import get_algorithm
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/utils/create_obj_from_config.py", line 20, in <module>
    from neural_compressor.metric import METRICS
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/metric/__init__.py", line 30, in <module>
    __import__(basename(f)[:-3], globals(), locals(), level=1)
  File "/home/cloudtest/.local/lib/python3.8/site-packages/neural_compressor/metric/coco_tools.py", line 54, in <module>
    from pycocotools import coco
  File "/usr/local/lib/python3.8/dist-packages/pycocotools/coco.py", line 52, in <module>
    from . import mask as maskUtils
  File "/usr/local/lib/python3.8/dist-packages/pycocotools/mask.py", line 3, in <module>
    import pycocotools._mask as _mask
  File "pycocotools/_mask.pyx", line 1, in init pycocotools._mask
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```
The cause is pycocotools package uses "oldest-supported-numpy", which
might cause older version numpy in build pycocotools:

https://github.com/ppwwyyxx/cocoapi/blob/9e9164f979fe4265c6f387f10e234f8697a15922/PythonAPI/pyproject.toml#L4

Related issue: cocodataset/cocoapi#248

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests