gudovskiy/yoloNCS

object detection multiprocessing graph load fail

Opened this issue · 15 comments

The single image test works.
This appears to be a video capture issue.

The object detection is producing a graph.LoadTensor error

[INFO/ForkPoolWorker-1] process shutting down
[DEBUG/ForkPoolWorker-1] running all "atexit" finalizers with priority >= 0
[DEBUG/ForkPoolWorker-1] running the remaining "atexit" finalizers
Process ForkPoolWorker-1:
Traceback (most recent call last):
  File "/usr/lib/python3.5/multiprocessing/process.py", line 249, in _bootstrap
    self.run()
  File "/usr/lib/python3.5/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.5/multiprocessing/pool.py", line 103, in worker
    initializer(*initargs)
  File "py_examples/object_detection_app.py", line 113, in worker
    graph.LoadTensor(resize(frame/255.0,dim,1)[:,:,(2,1,0)].astype(np.float16), 'user object')
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'
[INFO/ForkPoolWorker-1] process exiting with exitcode 1
[DEBUG/MainProcess] cleaning up worker 0
[Level 5/MainProcess] finalizer calling <built-in function close> with args (18,) and kwargs {}
[DEBUG/MainProcess] added worker
[DEBUG/ForkPoolWorker-3] Queue._after_fork()
[DEBUG/ForkPoolWorker-3] Queue._after_fork()
[INFO/ForkPoolWorker-3] child process calling self.run()

@apiszcz look at #1

Solution for this issue was to uninstall opencv-python with pip3
Working!
Thank you for all the work on YoloNCS

https://stackoverflow.com/questions/42325764/python-opencv-videocapture-differences-between-python-2-7-to-python-3-5

1down voteaccepted I had exactly the same problem. OpenCV was installed from the sources. The difference between Python 2 and 3 environment was, that for Python 3 opencv-python was additionally installed via pip3. Apip3 uninstall opencv-pythonsolved it in my case.

@apiszcz thank you.

Finally, I solved this problem by the following two step:

  1. Following this web mentioned OPTION 2, install OPENCV by source code.
  2. Replaced the compiled .so dynamic library with the one that comes with opencv-python python3 package:
    sudo cp <path to opencv source repo>/build/lib/python3/cv2.cpython-35m-x86_64-linux-gnu.so /usr/local/lib/python3.5/dist-packages/cv2/cv2.cpython-35m-x86_64-linux-gnu.so
    Hope it can help you.

Hey, I followed the link to install opencv from source. While executing sample examples, it is working well for C++ and Java example but it shows "No module named cv2" for the Python example. Can anyone please help me with this.

Thanks!

@apiszcz thanks a lot for your reply.
I copied the cv2.so and cv2.py file from /usr/local/lib/python2.7/dist-packages to /usr/local/lib/python2.7/site-packages and added-
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages to ~/.bashrc and now it is getting imported in python2.

But I am still not being able to run it for python3 and when I repeated the same step to add the cv2.so and cv2.py to the python3.6/site-packages and again adding a PYTHON path for it similarly, in bashrc.
But now, on importing cv2 in python3, I am getting a Segmentation fault error.
Let me know if you have any suggestions regarding this.

Thanks!

After a reboot, I am getting this error while importing cv2 using python3

Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/site-packages/cv2/init.py", line 7, in
from . import cv2
ImportError: /usr/local/lib/python2.7/site-packages/cv2/cv2.so: undefined symbol: PyCObject_Type

Output when importing using Python, Python 3.6 and 3.5:
(Also, bashrc now doesn't have any PYTHONPATH to opencv except for Python2.

mashrin@mashrin:~$ python
Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:09:15) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import cv2
>>> quit()
mashrin@mashrin:~$ python3
Python 3.6.3 (default, Oct  3 2017, 21:45:48) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Segmentation fault (core dumped)
mashrin@mashrin:~$ python3.5
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/cv2/__init__.py", line 7, in <module>
    from . import cv2
ImportError: /usr/local/lib/python2.7/site-packages/cv2/cv2.so: undefined symbol: PyCObject_Type
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ImportError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/cv2/__init__.py", line 7, in <module>
    from . import cv2
ImportError: /usr/local/lib/python2.7/site-packages/cv2/cv2.so: undefined symbol: PyCObject_Type
>>> quit()

@zsy372901 on performing step 2 as mentioned by you, I am getting this.

cp: cannot stat '/home/mashrin/OpenCV/build/lib/python3/cv2.cpython-35m-x86_64-linux-gnu.so': No such file or directory

The entire installation was completed without any error and I am even able to import cv2 using python2 after coping the cv2.so and cv2.py to /usr/local/lib/python2.7/site-packages
But, I am unable to import cv2 using python3. Also, I can't find cv2.cpython-35m-x86_64-linux-gnu.so anywhere. Kindly suggest.