cocodataset / cocoapi

COCO API - Dataset @ http://cocodataset.org/
Other
6.06k stars 3.75k forks source link

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

Open guysoft opened 5 years ago

guysoft commented 5 years ago

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: https://github.com/hooram/ownphotos/issues/56

joyyang1215 commented 5 years ago

The same error!

PrakrutiChandak commented 5 years ago

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

learner0903 commented 5 years ago

Same error!

PrakrutiChandak commented 5 years ago

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 commented 5 years ago

The same error!!!

LarissaCasteluci commented 5 years ago

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 commented 5 years ago

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

guysoft commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

I solve it like https://github.com/cocodataset/cocoapi/issues/14#issuecomment-458525761

$ git clone https://github.com/pdollar/coco.git
$ cd coco/PythonAPI
$ make
$python setup.py install
gouthamvgk commented 5 years ago

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

chAwater commented 5 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago
pycocotools==2.0.2
numpy==1.20.2

did the trick.

dreamgonsalves commented 3 years ago
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