laugh12321 / TensorRT-YOLO

🚀 你的YOLO部署神器。TensorRT Plugin、CUDA Kernel、CUDA Graphs三管齐下,享受闪电般的推理速度。| Your YOLO Deployment Powerhouse. With the synergy of TensorRT Plugins, CUDA Kernels, and CUDA Graphs, experience lightning-fast inference speeds.
https://github.com/laugh12321/TensorRT-YOLO
GNU General Public License v3.0
638 stars 78 forks source link

[Help]: Unable to build and use the 'tensorrt_yolo' package correctly #36

Closed dyhisbig closed 4 months ago

dyhisbig commented 4 months ago

较为详细的教程.docx 希望作者可以将大家遇到的问题整理成一个reamde文件,这样后续找到者这的人会少一些弯路

laugh12321 commented 4 months ago

3.0 的推理也是GPU推理,只不过没有cudaGraph加速。而且你图上贴的是4.0的报错,我怀疑你没有卸载之前安装的tensorrt_yolopip install tensorrt_yolo安装3.0版本,3.0版本是不可能出现找不到指定模块的错误的。

laugh12321 commented 4 months ago

https://github.com/user-attachments/assets/dcb0e078-c736-49cd-84ab-5393cbf78c20

@dyhisbig 这是在一个新环境上的TensorRT-YOLO 使用教程,其中的CUDA、cuDNN、TensorRT、Xmake的配置我这里不去赘述。你看看你和这个流程一样吗?都是README上面的指令一个都没变。

dyhisbig commented 4 months ago

TensorRT-YOLO.Tutorial.mp4

@dyhisbig 这是在一个新环境上的TensorRT-YOLO 使用教程,其中的CUDA、cuDNN、TensorRT、Xmake的配置我这里不去赘述。你看看你和这个流程一样吗?都是README上面的指令一个都没变。

我按照视频里,重新建了个环境,前边一切顺利,和视频里一样,最后执行推理trtyolo infer这个命令就是上述错误

laugh12321 commented 4 months ago

@dyhisbig 你的Python版本和xmake.lua要求的一样吗?xmake.lua中默认是3.10

dyhisbig commented 4 months ago

我在试试,不挂梯子报错那个图片传不上来

laugh12321 commented 4 months ago

@dyhisbig 根据你上面的文档,我怀疑你编译的是3.10的包,然后又给3.11环境去安装,那么同样是会出现找不到指定模块的错误的。

dyhisbig commented 4 months ago

换了个3.10的python环境执infer命令出现了新的问题,刚才是3.8的环境,是导包的问题, Traceback (most recent call last): File "C:\dyh\annconda\envs\py10\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, return callback(*args, **kwargs) File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\cli.py", line 161, in infer model = DeployDet(engine) File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\infer\detection.py", line 45, in init__ self._model = C.detection.DeployDet(engine_file, use_cuda_memory, device) File "C:\dyh\annconda\envs\py10\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\dyh\annconda\envs\py10\Scripts\trtyolo.exe__main.py", line 7, in File "C:\dyh\annconda\envs\py10\lib\site-packages\rich_click\rich_command.py", line 367, in call return super().call(*args, **kwargs) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 1157, in call return self.main(*args, kwargs) File "C:\dyh\annconda\envs\py10\lib\site-packages\rich_click\rich_command.py", line 152, in main rv = self.invoke(ctx) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 1434, in invoke return ctx.invoke(self.callback, ctx.params) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 783, in invoke return callback(*args, **kwargs) File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\cli.py", line 161, in infer model = DeployDet(engine) File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\infer\detection.py", line 45, in init self._model = C.detection.DeployDet(engine_file, use_cuda_memory, device) RuntimeError: Failed to construct engine context.

dyhisbig commented 4 months ago

python --version Python 3.10.14

dyhisbig commented 4 months ago

再次执行那行命令,中间多了个错误 ERROR: 1: [stdArchiveReader.cpp::nvinfer1::rt::StdArchiveReader::StdArchiveReaderInitCommon::46] Error Code 1: Serialization (Serialization assertion stdVersionRead == serializationVersion failed.Version tag does not match. Note: Current Version: 236, Serialized Engine Version: 238) 原地起飞

laugh12321 commented 4 months ago

换了个3.10的python环境执infer命令出现了新的问题,刚才是3.8的环境,是导包的问题, Traceback (most recent call last): File "C:\dyh\annconda\envs\py10\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, return __callback(*args, kwargs) File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\cli.py", line 161, in infer model = DeployDet(engine) File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\infer\detection.py", line 45, in init self._model = C.detection.DeployDet(engine_file, use_cuda_memory, device) File "C:\dyh\annconda\envs\py10\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\dyh\annconda\envs\py10\Scripts\trtyolo.exemain.py", line 7, in File "C:\dyh\annconda\envs\py10\lib\site-packages\rich_click\rich_command.py", line 367, in call return super().call(*args, kwargs) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 1157, in call* return self.main(args, kwargs) File "C:\dyh\annconda\envs\py10\lib\site-packages\rich_click\rich_command.py", line 152, in main rv = self.invoke(ctx) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 1434, in invoke return ctx.invoke(self.callback, *ctx.params) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 783, in invoke return __callback(args, kwargs) File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\cli.py", line 161, in infer model = DeployDet(engine) File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\infer\detection.py", line 45, in init** self._model = C.detection.DeployDet(engine_file, use_cuda_memory, device) RuntimeError: Failed to construct engine context.

这一行出发的报错 检查一下模型路径是否正确,或者重新用trtexec导出模型并给出正确的路径。

laugh12321 commented 4 months ago

再次执行那行命令,中间多了个错误 ERROR: 1: [stdArchiveReader.cpp::nvinfer1::rt::StdArchiveReader::StdArchiveReaderInitCommon::46] Error Code 1: Serialization (Serialization assertion stdVersionRead == serializationVersion failed.Version tag does not match. Note: Current Version: 236, Serialized Engine Version: 238) 原地起飞

你是不是有多个版本的TensorRT,错误意思是编译的TensorRT版本与Engine的版本不一致。

dyhisbig commented 4 months ago

[I] Successfully found necessary library paths: { "cudart": "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.1\bin", "nvinfer": "E:\TensorRT-10.2.0.19.Windows.win10.cuda-12.5\TensorRT-10.2.0.19\bin", "cudnn": "D:\anaconda3\envs\oytorch\Lib\site-packages\torch\lib" } File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 1434, in invoke return ctx.invoke(self.callback, *ctx.params) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 783, in invoke return __callback(args, **kwargs) File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\cli.py", line 151, in infer from .infer import CpuTimer, DeployCGDet, DeployDet, GpuTimer, generate_labels_with_colors, visualize_detections File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\infer__init__.py", line 1, in from .detection import Box, DeployCGDet, DeployDet, DetectionResult File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\infer\detection.py", line 27, in from .. import c_lib_wrap as C File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\c_lib_wrap.py", line 150, in raise RuntimeError(f"Deploy initialization failed! Error: {e}") RuntimeError: Deploy initialization failed! Error: DLL load failed while importing pydeploy: 找不到指定的模块。 我现在用etnsorrt10.2编译,deploy,导出engine,好像又回到了起点,哈哈哈

laugh12321 commented 4 months ago

@dyhisbig 首先前面报错[Version tag does not match. Note: Current Version: 236, Serialized Engine Version: 238]证明之前那个是打包步骤正确的,所以没有出现[找不到指定的模块]这个错误,只不过是你打包的TensorRT版本与让它推理的engine版本不一致而已,所以你只需要使用打包版本的trtexec重新生成engine即可。

其次,对于你这次出现这个问题。有以下几种原因

最后,因为你环境配置出现差错导致的tensorrt_yolo无法正常使用的问题,这里将不再解答。建议参考【Windows 开发环境配置——NVIDIA 篇】CUDA、cuDNN、TensorRT 三件套安装 正确的配置相关环境。

以下是正确编译并使用tensorr_yolo包的前提:

在满足以上基础前提且操作顺序与教程一致的情况下,若仍出现问题再来提问。

dyhisbig commented 4 months ago

[I] Successfully found necessary library paths: { "cudart": "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.5\bin", "cudnn": "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.5\bin", "nvinfer": "C:\Program Files\NVIDIA GPU Computing Toolkit\TensorRT\v8.6.1.6\bin" } Traceback (most recent call last): File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\c_lib_wrap.py", line 148, in from .libs.pydeploy import * rv = self.invoke(ctx) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 1434, in invoke return ctx.invoke(self.callback, *ctx.params) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 783, in invoke return __callback(args, **kwargs) File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\cli.py", line 151, in infer from .infer import CpuTimer, DeployCGDet, DeployDet, GpuTimer, generate_labels_with_colors, visualize_detections File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\infer__init__.py", line 1, in from .detection import Box, DeployCGDet, DeployDet, DetectionResult File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\infer\detection.py", line 27, in from .. import c_lib_wrap as C File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\c_lib_wrap.py", line 150, in raise RuntimeError(f"Deploy initialization failed! Error: {e}") RuntimeError: Deploy initialization failed! Error: DLL load failed while importing pydeploy: 找不到指定的模块。 1、编译环境安装环境都py3.10 2、删掉文件重新执行打包、编译,都试过了,cuda cudnn trt环境变量都配置了,trt换成了8.8.1.6 3、cudnn路径现在也识别队对了 4、构建、生成engine的trt都是8.6.1.6

dyhisbig commented 4 months ago

[I] Successfully found necessary library paths: { "cudart": "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.5\bin", "cudnn": "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.5\bin", "nvinfer": "C:\Program Files\NVIDIA GPU Computing Toolkit\TensorRT\v8.6.1.6\bin" } Traceback (most recent call last): File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\c_lib_wrap.py", line 148, in from .libs.pydeploy import * rv = self.invoke(ctx) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 1434, in invoke return ctx.invoke(self.callback, *ctx.params) File "C:\dyh\annconda\envs\py10\lib\site-packages\click\core.py", line 783, in invoke return __callback(args, **kwargs) File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\cli.py", line 151, in infer from .infer import CpuTimer, DeployCGDet, DeployDet, GpuTimer, generate_labels_with_colors, visualize_detections File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\infer__init__.py", line 1, in from .detection import Box, DeployCGDet, DeployDet, DetectionResult File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\infer\detection.py", line 27, in from .. import c_lib_wrap as C File "C:\dyh\annconda\envs\py10\lib\site-packages\tensorrt_yolo\c_lib_wrap.py", line 150, in raise RuntimeError(f"Deploy initialization failed! Error: {e}") RuntimeError: Deploy initialization failed! Error: DLL load failed while importing pydeploy: 找不到指定的模块。 1、编译环境安装环境都py3.10 2、删掉文件重新执行打包、编译,都试过了,cuda cudnn trt环境变量都配置了,trt换成了8.8.1.6 3、cudnn路径现在也识别队对了 4、构建、生成engine的trt都是8.6.1.6

laugh12321 commented 4 months ago

邮箱私信我,发你Todesk我帮你解决。

dyhisbig commented 4 months ago

解决了,作者亲自上阵,虽然代码不一定对我有用,但是捣鼓两天不死心,是cuda里边的放了别的版本的cudnn,但是也很奇怪,我是下午重新装了的cuda,待我在研究研究

laugh12321 commented 4 months ago

解决了,作者亲自上阵,虽然代码不一定对我有用,但是捣鼓两天不死心,是cuda里边的放了别的版本的cudnn,但是也很奇怪,我是下午重新装了的cuda,待我在研究研究

CUDA卸载时,不会删除手动放置在C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA下的文件,所以你重装后,之前放置的cuDNN还是存在的。