Susan19900316 / yolov5_tensorrt_int8

yolov5 tensorrt int8量化方法汇总
57 stars 13 forks source link

准备工作中onnx导出模型的问题 #15

Open Yehechao opened 3 months ago

Yehechao commented 3 months ago

是 python --weights xxx --include onnx --dynamic吗,我这样导出的onnx,在ptq中用不了,请问我该如何正确导出准备工作中的onnx

Yehechao commented 3 months ago

报错。batch也调整为640,640了,ptq转engine报错: [07/25/2024-09:30:30] [TRT] [W] onnx2trt_utils.cpp:374: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32. .\onnx2trt_ptq.py:113: DeprecationWarning: Use set_memory_pool_limit instead. config.max_workspace_size = workspace_size (1024 1024) # workspace_sizeMiB trt.DataType.INT8 Completed parsing of ONNX file Building an engine from file F:\YHC\yolov5_7.0_yhc\runs\train\exp\weights\best.onnx; this may take a while... .\onnx2trt_ptq.py:136: DeprecationWarning: Use build_serialized_network instead. engine = builder.build_engine(network,config) [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 215) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 216) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 227) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 228) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor /model.24/Reshape_1_output_0, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor /model.24/Reshape_2_output_0, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 310) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 351) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 355) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 358) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 361) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 393) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 394) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 405) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 406) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor /model.24/Reshape_9_output_0, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor /model.24/Reshape_10_output_0, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 488) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 529) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 533) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 536) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 539) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 571) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 572) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 583) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 584) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor /model.24/Reshape_17_output_0, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor /model.24/Reshape_18_output_0, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 666) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 707) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 711) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 714) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer* 717) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:45:10] [TRT] [E] 2: Assertion w != 0.F failed. [07/25/2024-09:45:11] [TRT] [E] 2: [reformatBuilder.cpp::nvinfer1::builder::ReformatBuilder::writeGlob::::operator ()::213] Error Code 2: Internal Error (Assertion w != 0.F failed. ) Completed creating Engine Traceback (most recent call last): File ".\onnx2trt_ptq.py", line 163, in main(onnx_file_path, engine_file_path, cali_img_path, mode='int8') File ".\onnx2trt_ptq.py", line 156, in main get_engine(onnx_file_path, engine_file_path, cali_img_path, mode) File ".\onnx2trt_ptq.py", line 149, in get_engine return build_engine() File ".\onnx2trt_ptq.py", line 140, in build_engine f.write(engine.serialize()) AttributeError: 'NoneType' object has no attribute 'serialize'

Susan19900316 commented 2 months ago

报错。batch也调整为640,640了,ptq转engine报错: [07/25/2024-09:30:30] [TRT] [W] onnx2trt_utils.cpp:374: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32. .\onnx2trt_ptq.py:113: DeprecationWarning: Use set_memory_pool_limit instead. config.max_workspace_size = workspace_size (1024 1024) # workspace_sizeMiB trt.DataType.INT8 Completed parsing of ONNX file Building an engine from file F:\YHC\yolov5_7.0_yhc\runs\train\exp\weights\best.onnx; this may take a while... .\onnx2trt_ptq.py:136: DeprecationWarning: Use build_serialized_network instead. engine = builder.build_engine(network,config) [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 215) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 216) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 227) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 228) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor /model.24/Reshape_1_output_0, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor /model.24/Reshape_2_output_0, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 310) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 351) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 355) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 358) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 361) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 393) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 394) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 405) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 406) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor /model.24/Reshape_9_output_0, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor /model.24/Reshape_10_output_0, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 488) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 529) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 533) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 536) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 539) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 571) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 572) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 583) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 584) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor /model.24/Reshape_17_output_0, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor /model.24/Reshape_18_output_0, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 666) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 707) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 711) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer 714) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:30:30] [TRT] [W] Missing scale and zero-point for tensor (Unnamed Layer* 717) [Constant]_output, expect fall back to non-int8 implementation for any layer consuming or producing given tensor [07/25/2024-09:45:10] [TRT] [E] 2: Assertion w != 0.F failed. [07/25/2024-09:45:11] [TRT] [E] 2: [reformatBuilder.cpp::nvinfer1::builder::ReformatBuilder::writeGlob::::operator ()::213] Error Code 2: Internal Error (Assertion w != 0.F failed. ) Completed creating Engine Traceback (most recent call last): File ".\onnx2trt_ptq.py", line 163, in main(onnx_file_path, engine_file_path, cali_img_path, mode='int8') File ".\onnx2trt_ptq.py", line 156, in main get_engine(onnx_file_path, engine_file_path, cali_img_path, mode) File ".\onnx2trt_ptq.py", line 149, in get_engine return build_engine() File ".\onnx2trt_ptq.py", line 140, in build_engine f.write(engine.serialize()) AttributeError: 'NoneType' object has no attribute 'serialize'

解决了吗?128到130行是用于设置动态尺寸的,你用netron看下你的onnx模型输入与你设置的有没有问题