opendr-eu / opendr

A modular, open and non-proprietary toolkit for core robotic functionalities by harnessing deep learning
Apache License 2.0
614 stars 95 forks source link

docker image from v2.2.0 - can't load from opendr.perception.object_detection_2d import YOLOv5DetectorLearner #457

Closed Niknu closed 1 year ago

Niknu commented 1 year ago

When I try load from opendr.perception.object_detection_2d import YOLOv5DetectorLearner from in the docker image from v2.2.0 I get this error:

File "openDr_show_custom_works.py", line 7, in <module> from opendr.perception.object_detection_2d import YOLOv5DetectorLearner File "/opendr/src/opendr/perception/object_detection_2d/__init__.py", line 1, in <module> from opendr.perception.object_detection_2d.centernet.centernet_learner import CenterNetDetectorLearner File "/opendr/src/opendr/perception/object_detection_2d/centernet/centernet_learner.py", line 25, in <module> from gluoncv.data.transforms import presets ModuleNotFoundError: No module named 'gluoncv'

passalis commented 1 year ago

Thanks for catching this. A dependency issue broke the automated CUDA container building process #458

Can you try using this custom image (opendr/opendr-toolkit:cuda_nightly_290823) and verify if this resolves this issue?

Niknu commented 1 year ago

When I have ran source bin/activate.sh and try to do the same again it gives me this error

from opendr.perception.object_detection_2d import YOLOv5DetectorLearner
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opendr/src/opendr/perception/object_detection_2d/__init__.py", line 1, in <module>
    from opendr.perception.object_detection_2d.centernet.centernet_learner import CenterNetDetectorLearner
  File "/opendr/src/opendr/perception/object_detection_2d/centernet/centernet_learner.py", line 25, in <module>
    from gluoncv.data.transforms import presets
  File "/opendr/venv/lib/python3.8/site-packages/gluoncv/__init__.py", line 16, in <module>
    _require_mxnet_version('1.4.0', '2.0.0')
  File "/opendr/venv/lib/python3.8/site-packages/gluoncv/check.py", line 6, in _require_mxnet_version
    import mxnet as mx
  File "/opendr/venv/lib/python3.8/site-packages/mxnet/__init__.py", line 23, in <module>
    from .context import Context, current_context, cpu, gpu, cpu_pinned
  File "/opendr/venv/lib/python3.8/site-packages/mxnet/context.py", line 23, in <module>
    from .base import classproperty, with_metaclass, _MXClassPropertyMetaClass
  File "/opendr/venv/lib/python3.8/site-packages/mxnet/base.py", line 356, in <module>
    _LIB = _load_lib()
  File "/opendr/venv/lib/python3.8/site-packages/mxnet/base.py", line 347, in _load_lib
    lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_LOCAL)
  File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /lib/x86_64-linux-gnu/libcuda.so.1: file too short
passalis commented 1 year ago

Can you share the exacts commands for reproducing the issue? Have you installed nvidia-docker (https://github.com/opendr-eu/opendr/blob/master/docs/reference/installation.md#gpu-docker) ?

I am running the following and I am not getting any error:

sudo docker run --gpus all -it opendr/opendr-toolkit:cuda_nightly_290823  /bin/bash
source ./bin/activate.sh 
python3 -c "from opendr.perception.object_detection_2d import YOLOv5DetectorLearner"
tsampazk commented 1 year ago

I can confirm that what Nikos suggests runs fine on my end too. I also tried to run some demos and i'm getting qt display errors which are to be expected.

Niknu commented 1 year ago

This is not the gpu but the cpu docker image

passalis commented 1 year ago

Can you please try this one opendr/opendr-toolkit:cpu_nightly_300823?

Niknu commented 1 year ago

Can you please try this one opendr/opendr-toolkit:cpu_nightly_300823?

This works now for me, thanks

Niknu commented 1 year ago

Sorry for open this one again, but after digging and trying out the docker image opendr/opendr-toolkit:cpu_nightly_300823 I can't be able to display a picture. I have tried to run my own python script in the docker where the X11 is mounted as volume (-v /tmp/.X11-unix:/tmp/.X11-unix) and also tried the with the jupyter notebook. I have tried to run this code:

import torch
from opendr.engine.data import Image # NOTE: Image load cv2, and can't find it, have call "source bin/activate.sh" mentioned here: https://github.com/opendr-eu/opendr/blob/v2.2.0/docs/reference/installation.md
from opendr.perception.object_detection_2d import YOLOv5DetectorLearner
from opendr.perception.object_detection_2d import draw_bounding_boxes

yolo = YOLOv5DetectorLearner(model_name='custom', path='/mount_deep_learning/weight/june2023v2.pt' , device='cpu')

torch.hub.download_url_to_file('https://ultralytics.com/images/zidane.jpg', 'zidane.jpg')  # download image
im1 = Image.open('zidane.jpg')  # OpenDR image

results = yolo.infer(im1)
draw_bounding_boxes(im1.opencv(), results, yolo.classes, show=True, line_thickness=3)

The error I get in both cases is:

QObject::moveToThread: Current thread (0xc249420) is not the object's thread (0x89796f0).
Cannot move to target thread (0xc249420)

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/opendr/venv/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.

Aborted (core dumped)
passalis commented 1 year ago

This is caused by opencv and getting opencv to work correctly inside docker can be tricky (i.e., the issue does not arise due to OpenDR). The following works for me (but I am not sure if this will work for all systems):

sudo docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix -v "$HOME/.Xauthority:/root/.Xauthority:ro" --network host -e DISPLAY=unix$DISPLAY opendr/opendr-toolkit:cpu_nightly /bin/bash

However, the easiest solution would be to just disable visualization, i.e., set show=False in draw_bounding_boxes and this should work in any case. Then, you can just save the image and examine it.