[Bug] inference of tensorrt on gpu
Checklist
- [X] I have searched related issues but cannot get the expected help.
- [X] 2. I have read the FAQ documentation but cannot get the expected help.
- [ ] 3. The bug has not been fixed in the latest version.
Describe the bug
I want to inference my tensorrt model on the gpu. But the error appears
Traceback (most recent call last):
File "inference.py", line 1, in <module>
from mmdeploy_runtime import Detector
ImportError: cannot import name 'Detector' from 'mmdeploy_runtime' (unknown location)
Before that I follow the issue to install mmdeploy-runtime-gpu and I can import mmdeploy_runtime correctly.
Reproduction
my script is
from mmdeploy_runtime import Detector
import cv2
img = cv2.imread('../demo/resources/det.jpg')
# create a detector
detector = Detector(model_path='/root/code/mmdeploy/mmdeploy_models/mmdet/ort/dino_fp16/end2end.engine', device_name='cuda', device_id=0)
# perform inference
bboxes, labels, masks = detector(img)
# visualize inference result
indices = [i for i in range(len(bboxes))]
for index, bbox, label_id in zip(indices, bboxes, labels):
[left, top, right, bottom], score = bbox[0:4].astype(int), bbox[4]
if score < 0.3:
continue
cv2.rectangle(img, (left, top), (right, bottom), (0, 255, 0))
cv2.imwrite('output_detection.png', img)
Environment
12/11 14:48:22 - mmengine - INFO -
12/11 14:48:22 - mmengine - INFO - **********Environmental information**********
12/11 14:48:23 - mmengine - INFO - sys.platform: linux
12/11 14:48:23 - mmengine - INFO - Python: 3.7.16 (default, Jan 17 2023, 22:20:44) [GCC 11.2.0]
12/11 14:48:23 - mmengine - INFO - CUDA available: True
12/11 14:48:23 - mmengine - INFO - numpy_random_seed: 2147483648
12/11 14:48:23 - mmengine - INFO - GPU 0: NVIDIA GeForce RTX 3090
12/11 14:48:23 - mmengine - INFO - CUDA_HOME: /usr/local/cuda
12/11 14:48:23 - mmengine - INFO - NVCC: Cuda compilation tools, release 11.3, V11.3.109
12/11 14:48:23 - mmengine - INFO - GCC: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
12/11 14:48:23 - mmengine - INFO - PyTorch: 1.12.1+cu113
12/11 14:48:23 - mmengine - INFO - PyTorch compiling details: PyTorch built with:
- GCC 9.3
- C++ Version: 201402
- Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel(R) 64 architecture applications
- Intel(R) MKL-DNN v2.6.0 (Git Hash 52b5f107dd9cf10910aaa19cb47f3abf9b349815)
- OpenMP 201511 (a.k.a. OpenMP 4.5)
- LAPACK is enabled (usually provided by MKL)
- NNPACK is enabled
- CPU capability usage: AVX2
- CUDA Runtime 11.3
- NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86
- CuDNN 8.2.1
- Built with CuDNN 8.3.2
- Magma 2.5.2
- Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.3, CUDNN_VERSION=8.3.2, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -fabi-version=11 -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.12.1, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=OFF, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF,
12/11 14:48:23 - mmengine - INFO - TorchVision: 0.13.1+cu113
12/11 14:48:23 - mmengine - INFO - OpenCV: 4.8.1
12/11 14:48:23 - mmengine - INFO - MMEngine: 0.10.1
12/11 14:48:23 - mmengine - INFO - MMCV: 2.1.0
12/11 14:48:23 - mmengine - INFO - MMCV Compiler: GCC 9.3
12/11 14:48:23 - mmengine - INFO - MMCV CUDA Compiler: 11.3
12/11 14:48:23 - mmengine - INFO - MMDeploy: 1.3.0+660af62
12/11 14:48:23 - mmengine - INFO -
12/11 14:48:23 - mmengine - INFO - **********Backend information**********
12/11 14:48:23 - mmengine - INFO - tensorrt: 8.5.1.7
12/11 14:48:23 - mmengine - INFO - tensorrt custom ops: Available
12/11 14:48:23 - mmengine - INFO - ONNXRuntime: 1.8.1
12/11 14:48:23 - mmengine - INFO - ONNXRuntime-gpu: None
12/11 14:48:23 - mmengine - INFO - ONNXRuntime custom ops: Available
12/11 14:48:23 - mmengine - INFO - pplnn: None
12/11 14:48:23 - mmengine - INFO - ncnn: None
12/11 14:48:23 - mmengine - INFO - snpe: None
12/11 14:48:23 - mmengine - INFO - openvino: None
12/11 14:48:23 - mmengine - INFO - torchscript: 1.12.1+cu113
12/11 14:48:23 - mmengine - INFO - torchscript custom ops: NotAvailable
12/11 14:48:23 - mmengine - INFO - rknn-toolkit: None
12/11 14:48:23 - mmengine - INFO - rknn-toolkit2: None
12/11 14:48:23 - mmengine - INFO - ascend: None
12/11 14:48:23 - mmengine - INFO - coreml: None
12/11 14:48:23 - mmengine - INFO - tvm: None
12/11 14:48:23 - mmengine - INFO - vacc: None
12/11 14:48:23 - mmengine - INFO -
12/11 14:48:23 - mmengine - INFO - **********Codebase information**********
12/11 14:48:23 - mmengine - INFO - mmdet: 3.2.0
12/11 14:48:23 - mmengine - INFO - mmseg: None
12/11 14:48:23 - mmengine - INFO - mmpretrain: None
12/11 14:48:23 - mmengine - INFO - mmocr: None
12/11 14:48:23 - mmengine - INFO - mmagic: None
12/11 14:48:23 - mmengine - INFO - mmdet3d: None
12/11 14:48:23 - mmengine - INFO - mmpose: None
12/11 14:48:23 - mmengine - INFO - mmrotate: None
12/11 14:48:23 - mmengine - INFO - mmaction: None
12/11 14:48:23 - mmengine - INFO - mmrazor: None
12/11 14:48:23 - mmengine - INFO - mmyolo: None
Error traceback
No response
What is your working directory looks like?
Are there exist a folder named mmdeploy_runtime? If so, please change the working directory or the import will find modules in this folder which is not right.
Hi @irexyc , the problem has been addressed. It is found that the previous mmdeploy_runtime_gpu is not correctly installed so that import mmdeploy_runtime also fails, which happens after I reboot my pc. It is weird. Then I reinstall the package and import is ok. But there is another problem
(mmdeploy) root@autodl-container-775011bb52-56272399:~/code/mmdeploy/mmdeploy_models# python inference.py
loading libmmdeploy_trt_net.so ...
loading libmmdeploy_ort_net.so ...
[2023-12-11 21:55:37.811] [mmdeploy] [info] [zip_model_impl.cpp:38] Failed to open zip file /root/code/mmdeploy/mmdeploy_models/mmdet/ort/dino_fp16/end2end.engine, ret 19
[2023-12-11 21:55:37.811] [mmdeploy] [error] [model.cpp:40] Failed to load model: "/root/code/mmdeploy/mmdeploy_models/mmdet/ort/dino_fp16/end2end.engine", implementations tried: [("DirectoryModel", 0), ("ZipModel", 0)]
[2023-12-11 21:55:37.811] [mmdeploy] [error] [model.cpp:16] Failed to load model "/root/code/mmdeploy/mmdeploy_models/mmdet/ort/dino_fp16/end2end.engine"
[2023-12-11 21:55:37.811] [mmdeploy] [error] [model.cpp:21] failed to create model: not supported (2) @ /__w/mmdeploy/mmdeploy/csrc/mmdeploy/core/model.cpp:41
Traceback (most recent call last):
File "inference.py", line 7, in <module>
detector = Detector(model_path='/root/code/mmdeploy/mmdeploy_models/mmdet/ort/dino_fp16/end2end.engine', device_name='cuda', device_id=0)
RuntimeError: failed to create detector
I make sure that the path to the tensorrt model is correct.
The problem is solved in the issue.