shouxieai / tensorRT_Pro

C++ library based on tensorrt integration
MIT License
2.59k stars 549 forks source link

倒出onnx后转trtmodel错误 #141

Open 15171452351 opened 2 years ago

15171452351 commented 2 years ago

[2022-08-23 14:34:48][info][app_yolo.cpp:132]:===================== test YoloX FP32 yolox_m ================================== [2022-08-23 14:34:48][info][trt_builder.cpp:474]:Compile FP32 Onnx Model 'yolox_m.onnx'. [2022-08-23 14:34:49][error][trt_builder.cpp:30]:NVInfer: /home/tcy/dev/tensorRT_Pro-main/src/tensorRT/onnx_parser/ModelImporter.cpp:736: While parsing node number 249 [Resize -> "onnx::Concat_921"]: [2022-08-23 14:34:49][error][trt_builder.cpp:30]:NVInfer: /home/tcy/dev/tensorRT_Pro-main/src/tensorRT/onnx_parser/ModelImporter.cpp:737: --- Begin node --- [2022-08-23 14:34:49][error][trt_builder.cpp:30]:NVInfer: /home/tcy/dev/tensorRT_Pro-main/src/tensorRT/onnx_parser/ModelImporter.cpp:738: input: "input.463" input: "onnx::Resize_920" input: "onnx::Resize_1424" output: "onnx::Concat_921" name: "Resize_249" op_type: "Resize" attribute { name: "coordinate_transformation_mode" s: "asymmetric" type: STRING } attribute { name: "cubic_coeff_a" f: -0.75 type: FLOAT } attribute { name: "mode" s: "nearest" type: STRING } attribute { name: "nearest_mode" s: "floor" type: STRING }

[2022-08-23 14:34:49][error][trt_builder.cpp:30]:NVInfer: /home/tcy/dev/tensorRT_Pro-main/src/tensorRT/onnx_parser/ModelImporter.cpp:739: --- End node --- [2022-08-23 14:34:49][error][trt_builder.cpp:30]:NVInfer: /home/tcy/dev/tensorRT_Pro-main/src/tensorRT/onnx_parser/ModelImporter.cpp:741: ERROR: /home/tcy/dev/tensorRT_Pro-main/src/tensorRT/onnx_parser/builtin_op_importers.cpp:3500 In function importResize: [8] Assertion failed: scales.is_weights() && "Resize scales must be an initializer!" [2022-08-23 14:34:49][error][trt_builder.cpp:519]:Can not parse OnnX file: yolox_m.onnx [2022-08-23 14:34:49][error][cuda_tools.cpp:25]:CUDA Runtime error cudaSetDevice(device_id) # invalid device ordinal, code = cudaErrorInvalidDevice [ 101 ] in file /home/tcy/dev/tensorRT_Pro-main/src/tensorRT/infer/trt_infer.cpp:472 [2022-08-23 14:34:49][error][yolo.cpp:197]:Engine yolox_m.FP32.trtmodel load failed [2022-08-23 14:34:49][error][app_yolo.cpp:52]:Engine is nullptr

OPAT-NaiPing commented 2 years ago

我也是报这个错误【Assertion failed: scales.is_weights() && "Resize scales must be an initializer!】。有解决吗。难道是环境不一致的原因?

oniondai commented 2 years ago

me too, Assertion failed: scales.is_weights() && "Resize scales must be an initializer!" how to solve this problem?

15171452351 commented 2 years ago

Use optimize to remove the identity layer from the exported onnx model

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年8月28日(星期天) 上午10:39 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [shouxieai/tensorRT_Pro] 倒出onnx后转trtmodel错误 (Issue #141)

me too, Assertion failed: scales.is_weights() && "Resize scales must be an initializer!" how to solve this problem?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

15171452351 commented 2 years ago

Use optimize to remove the identity layer from the exported onnx model

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年8月25日(星期四) 下午5:45 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [shouxieai/tensorRT_Pro] 倒出onnx后转trtmodel错误 (Issue #141)

我也是报这个错误【Assertion failed: scales.is_weights() && "Resize scales must be an initializer!】。有解决吗。难道是环境不一致的原因?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

oniondai commented 2 years ago

node Resize_188 problem, i do not know how to remove the identity layer from the exported onnx model, please paste fixed code. (with yolov5 tag:5.0). Thanks~

[2022-08-28 14:12:17][error][trt_builder.cpp:30]:NVInfer: /home/dc/Desktop/AI/2ai_engineer/tensorRT_Pro-main/src/tensorRT/onnx_parser/ModelImporter.cpp:736: While parsing node number 188 [Resize -> "onnx::Concat_322"]:
[2022-08-28 14:12:17][error][trt_builder.cpp:30]:NVInfer: /home/dc/Desktop/AI/2ai_engineer/tensorRT_Pro-main/src/tensorRT/onnx_parser/ModelImporter.cpp:737: --- Begin node ---
[2022-08-28 14:12:17][error][trt_builder.cpp:30]:NVInfer: /home/dc/Desktop/AI/2ai_engineer/tensorRT_Pro-main/src/tensorRT/onnx_parser/ModelImporter.cpp:738: input: "input.151"
input: "onnx::Resize_321"
input: "onnx::Resize_502"
output: "onnx::Concat_322"
name: "Resize_188"
op_type: "Resize"
attribute {
  name: "coordinate_transformation_mode"
  s: "asymmetric"
  type: STRING
}
attribute {
  name: "cubic_coeff_a"
  f: -0.75
  type: FLOAT
}
attribute {
  name: "mode"
  s: "nearest"
  type: STRING
}
attribute {
  name: "nearest_mode"
  s: "floor"
  type: STRING
}

[2022-08-28 14:12:17][error][trt_builder.cpp:30]:NVInfer: /home/dc/Desktop/AI/2ai_engineer/tensorRT_Pro-main/src/tensorRT/onnx_parser/ModelImporter.cpp:739: --- End node ---
[2022-08-28 14:12:17][error][trt_builder.cpp:30]:NVInfer: /home/dc/Desktop/AI/2ai_engineer/tensorRT_Pro-main/src/tensorRT/onnx_parser/ModelImporter.cpp:742: ERROR: /home/dc/Desktop/AI/2ai_engineer/tensorRT_Pro-main/src/tensorRT/onnx_parser/builtin_op_importers.cpp:3488 In function importResize:
[8] Assertion failed: scales.is_weights() && "Resize scales must be an initializer!"
[2022-08-28 14:12:17][error][trt_builder.cpp:519]:Can not parse OnnX file: /home/dc/Desktop/AI/2ai_engineer/tensorRT_Pro-main/build/yolov5s.onnx
[2022-08-28 14:12:17][error][yolo.cpp:197]:Engine /home/dc/Desktop/AI/2ai_engineer/tensorRT_Pro-main/build/yolov5s.FP32.trtmodel load failed
[2022-08-28 14:12:17][error][app_yolo.cpp:52]:Engine is nullptr
15171452351 commented 2 years ago

from onnx import optimizer

onnx_model = '、home/linux/dev/optimized.onnx' #Derived onnx model passes = ['eliminate_identity'] optimized_model = optimizer.optimize(onnx_model, passes) onnx.save(optimized_model, onnx_optimized)

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年8月28日(星期天) 下午2:36 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [shouxieai/tensorRT_Pro] 倒出onnx后转trtmodel错误 (Issue #141)

node Resize_188 problem, i do not know how to remove the identity layer from the exported onnx model, please paste fixed code. (with yolov5 tag:5.0). Thanks~ [2022-08-28 14:12:17][error][trt_builder.cpp:30]:NVInfer: /home/dc/Desktop/AI/2ai_engineer/tensorRT_Pro-main/src/tensorRT/onnx_parser/ModelImporter.cpp:738: input: "input.151" input: "onnx::Resize_321" input: "onnx::Resize_502" output: "onnx::Concat_322" name: "Resize_188" op_type: "Resize" attribute { name: "coordinate_transformation_mode" s: "asymmetric" type: STRING } attribute { name: "cubic_coeff_a" f: -0.75 type: FLOAT } attribute { name: "mode" s: "nearest" type: STRING } attribute { name: "nearest_mode" s: "floor" type: STRING }
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

oniondai commented 2 years ago

another error raised '_'

from onnx import optimizer
# all_passes = optimizer.get_available_passes()
# print("Available optimization passes:")
# for p in all_passes:
#     print('\t{}'.format(p))
# print()

onnx_model = 'yolov5s.onnx'
passes = ['eliminate_identity']
optimized_model = optimizer.optimize(onnx_model,  passes)
onnx.save(optimized_model,  "yolov5s_optimized.onnx")

Traceback (most recent call last):
  File "models/remove_indentity_layer.py", line 11, in <module>
    optimized_model = optimizer.optimize(onnx_model,  passes)
  File "/home/dc/anaconda3/envs/ai_engineer/lib/python3.8/site-packages/onnx/optimizer.py", line 49, in optimize
    raise ValueError('Optimizer only accepts ModelProto, incorrect type: {}'.format(type(model)))
ValueError: Optimizer only accepts ModelProto, incorrect type: <class 'str'>

image

15171452351 commented 2 years ago

Attach the code you executed

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年8月28日(星期天) 晚上7:23 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [shouxieai/tensorRT_Pro] 倒出onnx后转trtmodel错误 (Issue #141)

another error raised '_' Traceback (most recent call last): File "models/remove_indentity_layer.py", line 11, in <module> optimized_model = optimizer.optimize(onnx_model, passes) File "/home/dc/anaconda3/envs/ai_engineer/lib/python3.8/site-packages/onnx/optimizer.py", line 49, in optimize raise ValueError('Optimizer only accepts ModelProto, incorrect type: {}'.format(type(model))) ValueError: Optimizer only accepts ModelProto, incorrect type: <class 'str'>

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

oniondai commented 2 years ago

code is copied from https://github.com/shouxieai/tensorRT_Pro/issues/141#issuecomment-1229397783

from onnx import optimizer

onnx_model = 'yolov5s.onnx'
passes = ['eliminate_identity']
optimized_model = optimizer.optimize(onnx_model,  passes)
onnx.save(optimized_model,  "yolov5s_optimized.onnx")
15171452351 commented 2 years ago

from onnx import optimizer onnx_model = 'yolov5s.onnx'model = onnx.load(onnx_model)passes = ['eliminate_identity'] optimized_model = optimizer.optimize(model, passes) onnx.save(optimized_model, "yolov5s_optimized.onnx")

Sorry,one line of code to load the model is missing

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年8月28日(星期天) 晚上7:35 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [shouxieai/tensorRT_Pro] 倒出onnx后转trtmodel错误 (Issue #141)

code is copied from #141 (comment) from onnx import optimizer onnx_model = 'yolov5s.onnx' passes = ['eliminate_identity'] optimized_model = optimizer.optimize(onnx_model, passes) onnx.save(optimized_model, "yolov5s_optimized.onnx")

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

oniondai commented 2 years ago

from onnx import optimizer onnx_model = 'yolov5s.onnx'model = onnx.load(onnx_model)passes = ['eliminate_identity'] optimized_model = optimizer.optimize(model, passes) onnx.save(optimized_model, "yolov5s_optimized.onnx") Sorry,one line of code to load the model is missing ------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年8月28日(星期天) 晚上7:35 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [shouxieai/tensorRT_Pro] 倒出onnx后转trtmodel错误 (Issue #141) code is copied from #141 (comment) from onnx import optimizer onnx_model = 'yolov5s.onnx' passes = ['eliminate_identity'] optimized_model = optimizer.optimize(onnx_model, passes) onnx.save(optimized_model, "yolov5s_optimized.onnx") — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

Is it a problem with the version of onnx, protobuf or tensortRT?https://github.com/shouxieai/tensorRT_Pro/issues/141#issuecomment-1229391604 The environment I configured according to the tutorial https://www.bilibili.com/video/BV1Xw411f7FW?p=8&vd_source=af2069e385e61559b2c263e7c3f30b3c uses yolov5 tag5.0

oniondai commented 2 years ago

Can you quickly repeat this tutorial(https://www.bilibili.com/video/BV1Xw411f7FW?p=8&vd_source=af2069e385e61559b2c263e7c3f30b3c)? Thus, this problem(https://github.com/shouxieai/tensorRT_Pro/issues/141#issuecomment-1229391604) is repeated