Description
I am trying to convert an ONNX FasterRCNN based object detection model to a TensorRT engine and running into an error with shapes in the ROI heads.
Here is an example script that will allow one to recreate the error:
import os
import tensorrt as trt
if __name__ == '__main__':
x_shape = (2,2,300,400)
DIR_NAME = os.path.dirname(__file__)
TRT_LOGGER = trt.Logger(trt.Logger.VERBOSE)
trt.init_libnvinfer_plugins(TRT_LOGGER, '')
builder = trt.Builder(TRT_LOGGER)
network = builder.create_network()
parser = trt.OnnxParser(network, builder.logger)
onnx_path = os.path.realpath('model_zoo_rcnn.onnx')
with open(onnx_path, "rb") as f:
if not parser.parse(f.read()):
TRT_LOGGER.log(trt.Logger.ERROR, f"Failed to load ONNX file: {onnx_path}")
for error in range(parser.num_errors):
TRT_LOGGER.log( trt.Logger.ERROR, parser.get_error(error))
raise RuntimeError(f'Failed to load ONNX file: {onnx_path}')
engine_path = os.path.realpath('model_zoo_rcnn.engine')
engine_dir = os.path.dirname(engine_path)
os.makedirs(engine_dir, exist_ok=True)
inputs = [network.get_input(i) for i in range(network.num_inputs)]
config = builder.create_builder_config()
config.profiling_verbosity = trt.ProfilingVerbosity.DETAILED
engine_str = builder.build_serialized_network(network, config)
with open(engine_path, "wb") as f:
f.write(engine_str)
And here is the model used for this example:
This occurs when using the default TensorRT plugin based ROIAlign node. It occurs even when an exported ONNX model includes a fixed batch size/input and output tensor shapes. These issues appear to occur with any RCNN based model, including ones from the ONNX Model Zoo.
Does the input ONNX file/graph need to be modified to use dynamic shapes in this node or set the node’s inputs/outputs to be fixed? If so, how can this be done? If this is not the issue, what is causing this error and how can it be fixed?
Environment
TensorRT Version: 10.5
GPU Type: Nvidia Jetson Orin
Nvidia Driver Version: 540.4.0
CUDA Version: 12.6
CUDNN Version:
Operating System + Version: Ubuntu 22.04.04
Python Version (if applicable): 3.10.15
Baremetal or Container (if container which image + tag): Baremetal
Relevant Files
Log from loading ONNX graph:
faster_rcnn_ex.log (1.5 MB)