open-mmlab / mmdeploy

OpenMMLab Model Deployment Framework
https://mmdeploy.readthedocs.io/en/latest/
Apache License 2.0
2.78k stars 636 forks source link

[Bug] ModuleNotFoundError: No module named 'mmdeploy_runtime.mmdeploy_runtime' #2777

Open collinbarnwell opened 5 months ago

collinbarnwell commented 5 months ago

Checklist

Describe the bug

I'm trying to run the object detection demo on a Jetson orin nano inside a docker image. I have a working image that installs mmdeploy for aarch64, but I'm unable to import Detector or mmdeploy_runtime.

>>> from mmdeploy_runtime import Detector
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mmdeploy/tools/package_tools/packaging/mmdeploy_runtime/__init__.py", line 26, in <module>
    from .mmdeploy_runtime import *  # noqa
ModuleNotFoundError: No module named 'mmdeploy_runtime.mmdeploy_runtime'
>>> 

I'm able to import mmdeploy into Python, as well as all the dependencies:

>>> import cv2
>>> import mmdeploy
>>> import torch
>>> import torchvision
>>> print(cv2.__version__)
4.10.0
>>> print(torch.__version__)
2.2.0
>>> print(torchvision.__version__)
0.17.2+c1d70fe
>>> print(mmdeploy.__version__)
1.3.1

I've searched the mmdeploy code for a Python class called Detector, and I'm not finding anything. The mmdeploy_runtime directory is present in my local installation (and PYTHONPATH), but there's no actual code inside mmdeploy_runtime, so I don't know where these classes are supposed to come from.

$ find . | grep mmdeploy_runtime
./tools/package_tools/packaging/mmdeploy_runtime
./tools/package_tools/packaging/mmdeploy_runtime/__init__.py
./tools/package_tools/packaging/mmdeploy_runtime/version.py
./tools/package_tools/packaging/mmdeploy_runtime/_win_dll_path.py
./tools/package_tools/packaging/mmdeploy_runtime/__pycache__
./tools/package_tools/packaging/mmdeploy_runtime/__pycache__/version.cpython-310.pyc
./tools/package_tools/packaging/mmdeploy_runtime/__pycache__/__init__.cpython-310.pyc

$ python3 ./tools/package_tools/packaging/mmdeploy_runtime/__init__.py
Traceback (most recent call last):
  File "/mmdeploy/./tools/package_tools/packaging/mmdeploy_runtime/__init__.py", line 8, in <module>
    from .version import __version__
ImportError: attempted relative import with no known parent package

Reproduction

I built a Docker image for Jetson Orin Nano with this Dockerfile:

FROM dustynv/l4t-pytorch:r36.2.0

RUN pip3 install -U openmim

RUN mim install "mmcv>=2.0.0rc2"

RUN apt update -y && apt install -y libass-dev libfdk-aac-dev libavcodec-dev libavformat-dev libavdevice-dev \
    libavfilter-dev libpostproc-dev libswresample-dev libswscale-dev libmp3lame-dev libopus-dev \
    libvpx-dev libx264-dev libx265-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev libfontconfig1-dev \
    build-essential yasm nasm

RUN apt clean && rm -rf /var/lib/apt/lists/*

ENV TENSORRT_DIR=/usr/src/tensorrt

# Install MMDeploy
RUN git clone --recursive https://github.com/open-mmlab/mmdeploy.git
WORKDIR /mmdeploy
RUN mkdir -p build && cd build && \
    cmake .. -DMMDEPLOY_TARGET_DEVICES="cuda" \
    -DMMDEPLOY_TARGET_BACKENDS="trt" \
    -DMMDEPLOY_CODEBASES=all \
    -DTENSORRT_DIR=${TENSORRT_DIR} && \
    make -j$(nproc) && make install

RUN pip3 install -e .

And this docker command, which I build on my host: docker buildx build --platform linux/arm64 -t mmdeploy_image I put that docker image on my Jetson, then run a terminal inside of it:

sudo docker run -it --rm --runtime nvidia --network=host mmdeploy_image

Then I run this:

export PYTHONPATH=/mmdeploy/mmdeploy:/mmdeploy/tools/package_tools/packaging
python3 -c "from mmdeploy_runtime import Detector ; print(Detector.__version__)"

And I get the error described above.

Environment

Check env didn't seem to work:

root@nvidia:/mmdeploy# python3 tools/check_env.py
Traceback (most recent call last):
  File "/mmdeploy/tools/check_env.py", line 3, in <module>
    from mmcv.utils import collect_env as collect_base_env
ModuleNotFoundError: No module named 'mmcv.utils'
root@nvidia:/mmdeploy# python3^C
root@nvidia:/mmdeploy# python3 -c "import mmcv"
root@nvidia:/mmdeploy# python3 -c "import mmcv ; print(mmcv.__version__)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'mmcv' has no attribute '__version__'
root@nvidia:/mmdeploy# echo $PYTHONPATH
/mmdeploy/mmdeploy:/mmdeploy/tools/package_tools/packaging
root@nvidia:/mmdeploy# 

Other env vars:

root@nvidia:/mmdeploy# echo $PYTHONPATH
/mmdeploy/mmdeploy:/mmdeploy/tools/package_tools/packaging
root@nvidia:/mmdeploy# echo $PATH
/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@nvidia:/mmdeploy# echo $LD_LIBRARY_PATH
/usr/local/cuda/compat:/usr/local/cuda/lib64:
root@nvidia:/mmdeploy# 

I'm happy to fix this in a PR, I just need to understand more about the mmdeploy_runtime directory and where Detector is located.

JNaranjo-Alcazar commented 2 weeks ago

Hi, I am facing the same problem now with Jetson Orin. I have installed mmdeploy_runtime like:

cd mmdeploy/tools/package_tools/packaging
pip install  -v -e .

When running an import I get the following error:

from .mmdeploy_runtime import *  # noqa
ModuleNotFoundError: No module named 'mmdeploy_runtime.mmdeploy_runtime'

As @collinbarnwell said, when I run tools/check_env.py I get:

from mmcv.utils import collect_env as collect_base_env
ModuleNotFoundError: No module named 'mmcv.utils

It is strange becuase I have been able to convert a model as tutorial suggested and run an inference with c++ bin. However, I am stucked when installing and working with mmdeloy runtime on Jetson Platform

More info: when running pip list | grep mmdeploy

mmdeploy                 1.3.1       /sd_card/repos/external_repos/mmdeploy
mmdeploy-runtime         1.3.1       /sd_card/repos/external_repos/mmdeploy/tools/package_tools/packaging

Any solutions? Did you manage to solve this problem @collinbarnwell ? Thanks in advance!

cg3dland commented 1 week ago

You could reference to the README under tools/package_tools to build the mmdeploy_runtime/mmdeploy_runtime_gpu.