build engine ERROR on tensorrt ONNX
I’m trying to use multi-batch for my model. My codes referenced the onnx_to_tensorrt_multibatch.py
But I encountered an issue that I have no ideas to deal with it.
I have uploaded the error output, please take a look.
TensorRT version is 7.1.0 on Jetson NX Xaiver
issue_output.txt (67.6 KB)
I_DEEP = 1
I_WIDTH = 128
I_HEIGHT = 128
INPUT_NAME = "x.1"
INPUT_NAME = "input.1"
def get_engine(onnx_file_path, engine_file_path=""):
"""Attempts to load a serialized engine if available, otherwise builds a new TensorRT engine and saves it."""
def build_engine():
"""Takes an ONNX file and creates a TensorRT engine to run inference with"""
with trt.Builder(TRT_LOGGER) as builder, builder.create_network(
rtr_common.EXPLICIT_BATCH) as network, builder.create_builder_config() as config, \
trt.OnnxParser(network, TRT_LOGGER) as parser:
builder.max_workspace_size = 1 << 28 # 256MiB
builder.max_batch_size = 1
# Parse model file
if not os.path.exists(onnx_file_path):
print('ONNX file {} not found: '.format(onnx_file_path))
exit(0)
print('Loading ONNX file from path {}...'.format(onnx_file_path))
with open(onnx_file_path, 'rb') as model:
print('Beginning ONNX file parsing')
if not parser.parse(model.read()):
print('ERROR: Failed to parse the ONNX file.')
for error in range(parser.num_errors):
print(parser.get_error(error))
return None
network.get_input(0).shape = [-1, I_DEEP, I_WIDTH, I_HEIGHT]
profile = builder.create_optimization_profile()
profile.set_shape(INPUT_NAME, (1, I_DEEP, I_WIDTH, I_HEIGHT), (16, I_DEEP, I_WIDTH, I_HEIGHT),
(32, I_DEEP, I_WIDTH, I_HEIGHT))
config.add_optimization_profile(profile)
# The actual yolov3.onnx is generated with batch size 64. Reshape input to batch size 1
# network.get_input(0).shape = [1, 3, 608, 608]
print('Completed parsing of ONNX file')
print('Building an engine from file {}; this may take a while...'.format(onnx_file_path))
engine = builder.build_engine(network, config)
print("Completed creating Engine")
print(engine)
with open(engine_file_path, "wb") as f:
f.write(engine.serialize())
return engine
if os.path.exists(engine_file_path):
# If a serialized engine exists, use it instead of building an engine.
print("Reading engine from file {}".format(engine_file_path))
with open(engine_file_path, "rb") as f, trt.Runtime(TRT_LOGGER) as runtime:
return runtime.deserialize_cuda_engine(f.read())
else:
return build_engine()