2

OS:Ubuntu 18.04 LTS

Python Environment = 3.6.8 (System default version)

I followed this link to install cocoapi.

However, it shows the error below:

ubuntu:~/cocoapi-master/PythonAPI$ make
python setup.py build_ext --inplace
Traceback (most recent call last):
  File "setup.py", line 2, in <module>
    import numpy as np
ImportError: No module named numpy
Makefile:3: recipe for target 'all' failed
make: *** [all] Error 1

I have already installed the needed dependencies mentioned in objection_detection/g3doc/installation.md.

I have also installed Cython and Numpy.

Could somebody help me fix this issue? Thanks in advance.

I run this code

python3 setup.py build_ext --inplace

It doesn't show error.

However, when I tried to run a Tensorflow/models/research/object_detection/model_main.py, it shows error again.

Command line:

ubuntu:~/PycharmProjects/PedestrianDetection$ python object_detection/model_main.py --pipeline_config_path=pretrained/pipeline.config --model_dir=train --num_train_steps=1000 --sample_1_of_n_eval_examples=1 --alsologtostderr

Error:

Traceback (most recent call last):
  File "object_detection/model_main.py", line 26, in <module>
    from object_detection import model_lib
  File "/home/yantong/PycharmProjects/PedestrianDetection/object_detection/model_lib.py", line 28, in <module>
    from object_detection import eval_util
  File "/home/yantong/PycharmProjects/PedestrianDetection/object_detection/eval_util.py", line 28, in <module>
    from object_detection.metrics import coco_evaluation
  File "/home/yantong/PycharmProjects/PedestrianDetection/object_detection/metrics/coco_evaluation.py", line 20, in <module>
    from object_detection.metrics import coco_tools
  File "/home/yantong/PycharmProjects/PedestrianDetection/object_detection/metrics/coco_tools.py", line 47, in <module>
    from pycocotools import coco
  File "/home/yantong/PycharmProjects/PedestrianDetection/pycocotools/coco.py", line 55, in <module>
    from . import mask as maskUtils
  File "/home/yantong/PycharmProjects/PedestrianDetection/pycocotools/mask.py", line 3, in <module>
    import pycocotools._mask as _mask
ModuleNotFoundError: No module named 'pycocotools._mask'

Under ~/PycharmProjects/PedestrianDetection/pycocotools, I have

cocoeval.py      coco.py      __init__.py  mask.py    __pycache__
cocoeval.py.bak  coco.py.bak  _mask.c      _mask.pyx

I'm wondering why it shows No module named 'pycocotools._mask' as well.

pandalai
  • 426
  • 4
  • 15

2 Answers2

4
  1. According to @Joe A 's guidance, finally make pycocotools by prompting:
pip3 install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI

It will be installed in the Ubuntu path /home/USERNAME/.local/lib/python3.6/site-packages

  1. Enter the path /home/USERNAME/.local/lib/python3.6/site-packages

Using Terminal to cd the path above.

NOTICE: USERNAME means your account name on Ubuntu (for me is yantong), replace it with yours.

  1. Copy the downloaded pycocotools from the Step1-2 to your code package.
cp -r pycocotools YOUR_PACKAGE_PATH

NOTICE: You'd better replace YOUR_PACKAGE_PATH with your package's absolute path.

  1. Test Test by open a Python3 script and prompt:
from pycocotools.coco import COCO
from pycocotools import mask as maskUtils

Press ENTER, if not with error, congrats!

Mahesh
  • 175
  • 1
  • 13
pandalai
  • 426
  • 4
  • 15
0

The problem might be the gcc version or installations in your system, follow this if the above solutions fail.

here's how I did it successfully! (the reason is the gcc version)

  1. install the dependencies: cython (pip install python), opencv (pip install opencv-python)

  2. check the gcc version by this command: gcc --version

  3. your output will be like this 'Command 'gcc' not found, but can be installed with: sudo apt install gcc '

  4. Type the below commands to install the gcc: sudo apt update

    sudo apt install build-essential

    sudo apt-get install manpages-dev

  5. now check again the gcc version(step2) if you get below output

    'gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.'

  6. now run the code for pycocotools installations:

    pip install "git+https://github.com/philferriere/cocoapi.git#egg=pycocotools&subdirectory=PythonAPI"

  7. finally wait to check if the installation is successful :

    'Successfully installed pycocotools-2.0'

Faisal Nazik
  • 2,367
  • 4
  • 17
  • 40