shouxieai / infer

A new tensorrt integrate. Easy to integrate many tasks
MIT License
376 stars 76 forks source link

使用trtexec --onnx=yolov5s.onnx --saveEngine=yolov5s_engine.trt 转换成功,但是进行推理的时候报错 #14

Closed BossCrab-jyj closed 1 year ago

BossCrab-jyj commented 1 year ago

环境: 显卡3080ti 系统:ubuntu20 cuda11.3.1 cudnn8.2.1 tensorrt8.2.0.6 模型:yolov5-6.1 yolov5s.onnx

[infer.cu:396]: Infer 000002327B533F10 [StaticShape] [infer.cu:408]: Inputs: 1 [infer.cu:412]: 0.images : shape {1x3x800x800} [infer.cu:415]: Outputs: 4 [infer.cu:419]: 0.onnx::Sigmoid_339 : shape {1x3x100x100x42} [infer.cu:419]: 1.onnx::Sigmoid_391 : shape {1x3x50x50x42} [infer.cu:419]: 2.onnx::Sigmoid_443 : shape {1x3x25x25x42} [infer.cu:419]: 3.output : shape {1x39375x42}

image name: ./test_imgs/2023-5-5 15-13-27.bmp

[infer.cu:209]: NVInfer: 3: [executionContext.cpp::nvinfer1::rt::ExecutionContext::enqueueInternal::328] Error Code 3: Internal Error (Parameter check failed at: executionContext.cpp::nvinfer1::rt::ExecutionContext::enqueueInternal::328, condition: bindings[x] != nullptr )

有看到别人提过这个问题,您回答的是The infer requires only one output binding. And you provide 4, which is not adapted. 请问如何将output修改成1呢?

BossCrab-jyj commented 1 year ago

我将代码中bbox_headdims = trt_->static_dims(1); 改为bbox_headdims = trt_->static_dims(4); 还是有同样的错误

bboxpredict.gpu(batch_size bbox_headdims[1] bbox_headdims[2]); float bbox_output_device = bboxpredict.gpu(); vector<void > bindings{inputbuffer.gpu(), bbox_outputdevice}; if (!trt->forward(bindings, stream)) { INFO("Failed to tensorRT forward."); return {}; } 其中 bbox_headdims[1] = 39375 bbox_headdims[2] = 42,bindings应该是对的吧,模型是加载成功了的,我不太理解具体是哪里的问题 [infer.cu:396]: Infer 000001F0805BCC70 [StaticShape] [infer.cu:408]: Inputs: 1 [infer.cu:412]: 0.images : shape {1x3x800x800} [infer.cu:415]: Outputs: 4 [infer.cu:419]: 0.onnx::Sigmoid_329 : shape {1x3x100x100x42} [infer.cu:419]: 1.onnx::Sigmoid_371 : shape {1x3x50x50x42} [infer.cu:419]: 2.onnx::Sigmoid_413 : shape {1x3x25x25x42} [infer.cu:419]: 3.output : shape {1x39375x42} [yolo.cu:542]: numclasses 37 [yolo.cu:544]: input_dim[0] 1 [yolo.cu:545]: input_dim[1] 3 [yolo.cu:546]: network_inputwidth 800 [yolo.cu:547]: network_inputheight 800 image name: ./test_imgs/2023-5-5 10-10-52.bmp [yolo.cu:466]: bbox_headdims[0] 1 [yolo.cu:467]: bbox_headdims[1] 39375 [yolo.cu:468]: bbox_headdims[2] 42 [yolo.cu:469]: bbox_headdims[3] 496 [infer.cu:209]: NVInfer: 3: [executionContext.cpp::nvinfer1::rt::ExecutionContext::enqueueInternal::328] Error Code 3: Internal Error (Parameter check failed at: executionContext.cpp::nvinfer1::rt::ExecutionContext::enqueueInternal::328, condition: bindings[x] != nullptr )

BossCrab-jyj commented 1 year ago

已解决,删除其他不需要的outputs model = onnx.load(onnx_file) outputs = list(model.graph.output)

for output in outputs: if output.name != 'output': model.graph.output.remove(output) onnx.save(model, save_path)