FeiYull / TensorRT-Alpha

🔥🔥🔥TensorRT for YOLOv8、YOLOv8-Pose、YOLOv8-Seg、YOLOv8-Cls、YOLOv7、YOLOv6、YOLOv5、YOLONAS......🚀🚀🚀CUDA IS ALL YOU NEED.🍎🍎🍎
GNU General Public License v2.0
1.26k stars 196 forks source link

yolo8推理报错 #42

Open nimeng1299 opened 1 year ago

nimeng1299 commented 1 year ago

编译过程没问题,使用时报错 启动命令.\trt.exe --model=1.trt --size=640 --batch_size=1 --img=1.jpg --show --savePath=../

[07/21/2023-13:29:26] [I] model_path = 1.trt
[07/21/2023-13:29:26] [I] size = 640
[07/21/2023-13:29:26] [I] batch_size = 1
[07/21/2023-13:29:26] [I] image_path = 1.jpg
[07/21/2023-13:29:26] [I] is_show = 1
[07/21/2023-13:29:26] [I] save_path = ../
[07/21/2023-13:29:27] [I] [TRT] Loaded engine size: 16 MiB
[07/21/2023-13:29:27] [I] [TRT] [MemUsageChange] TensorRT-managed allocation in engine deserialization: CPU +0, GPU +12, now: CPU 0, GPU 12 (MiB)
[07/21/2023-13:29:27] [I] [TRT] [MemUsageChange] TensorRT-managed allocation in IExecutionContext creation: CPU +0, GPU +148, now: CPU 0, GPU 160 (MiB)
[07/21/2023-13:29:27] [W] [TRT] CUDA lazy loading is not enabled. Enabling it can significantly reduce device memory usage and speed up TensorRT initialization. See "Lazy Loading" section of CUDA documentation https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#lazy-loading
[07/21/2023-13:29:27] [E] [TRT] 3: [runtime.cpp::nvinfer1::Runtime::~Runtime::346] Error Code 3: API Usage Error (Parameter check failed at: runtime.cpp::nvinfer1::Runtime::~Runtime::346, condition: mEngineCounter.use_count() == 1. Destroying a runtime before destroying deserialized engines created by the runtime leads to undefined behavior.
)
[07/21/2023-13:29:27] [I] the engine's info:
[07/21/2023-13:29:27] [I] idx = 0, images: -1, 3, 640, 640,
[07/21/2023-13:29:27] [I] idx = 1, output0: -1, 6, 8400,
[07/21/2023-13:29:27] [I] the context's info:
[07/21/2023-13:29:27] [I] idx = 0, images: 1, 3, 640, 640,
[07/21/2023-13:29:27] [I] idx = 1, output0: 1, 6, 8400,
[07/21/2023-13:29:27] [I] 1
johQin commented 10 months ago

这个有得到解决吗?同样的问题

johQin commented 10 months ago

[E] [TRT] 3: [runtime.cpp::nvinfer1::Runtime::~Runtime::346] Error Code 3: API Usage Error (Parameter check failed at: runtime.cpp::nvinfer1::Runtime::~Runtime::346, condition: mEngineCounter.use_count() == 1. Destroying a runtime before destroying deserialized engines created by the runtime leads to undefined behavior. ),不知道为什么,出错了还能推理,但性能应该下降了

johQin commented 10 months ago

我有观察到,它在YOLOV8::init中报错了,Parameter check failed在网上有回答说,是因为trt和实际的模型结构不一致导致的,这个希望FeiYull能够解答一下

YiXuan-52 commented 6 months ago

是的,我也遇到了相同的问题。不同的是我使用的是tensorrt8.6.1.6,没有使用8.4.不知道是否存在影响。

johQin commented 6 months ago

是的,我也遇到了相同的问题。不同的是我使用的是tensorrt8.6.1.6,没有使用8.4.不知道是否存在影响。 参考: https://blog.csdn.net/qq_42190134/article/details/135365945

ZJDATY commented 6 months ago

是的,我也遇到了相同的问题。不同的是我使用的是tensorrt8.6.1.6,没有使用8.4.不知道是否存在影响。 参考: https://blog.csdn.net/qq_42190134/article/details/135365945

你好 ,我用的也是8.6 ,也是这个错误。我看了你说的顺序问题导致的报错,但是我看默认的顺序就是对的啊。请问应该如何修改代码

YiXuan-52 commented 6 months ago

是的,我也遇到了相同的问题。不同的是我使用的是tensorrt8.6.1.6,没有使用8.4.不知道是否存在影响。 参考: https://blog.csdn.net/qq_42190134/article/details/135365945

你好 ,我用的也是8.6 ,也是这个错误。我看了你说的顺序问题导致的报错,但是我看默认的顺序就是对的啊。请问应该如何修改代码

我的问题是因为在模型转换时出现的问题,如果使用Ultralytics yolo 命令进行转换的engine模型,会在模型头部加一大堆这个模型的信息,前4字节是这个信息的长度跳过去脚好了。大概就是下面这样的情况

with open(weights_path, 'rb') as f, trt.Runtime(logger) as runtime: meta_len = int.from_bytes(f.read(4), byteorder='little') # read metadata length metadata = json.loads(f.read(meta_len).decode('utf-8')) # read metadata if 'description' not in metadata: # Ultralytics YOLOv8 engine print(" trtexec YOLOv8 engine model") f.seek(0) else: # Trtexec yolov8 engine print(" Ultralytics YOLOv8 engine model") self.model = runtime.deserialize_cuda_engine(f.read()) # read engine