def build_engine():
flag = 1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)
“”“Takes an ONNX file and creates a TensorRT engine to run inference with”“”
with trt.Builder(TRT_LOGGER) as builder, builder.create_network(flag) as network, trt.OnnxParser(network, TRT_LOGGER) as parser:
builder.max_workspace_size = 1 << 28 # 256MiB
builder.max_batch_size = 1
# Parse model file
print(‘Loading ONNX file from path {}…’.format(onnx_file_path))
with open(onnx_file_path, ‘rb’) as model:
print(‘Beginning ONNX file parsing’)
parser.parse(model.read())
print(‘Completed parsing of ONNX file’)
print(‘Building an engine from file {}; this may take a while…’.format(onnx_file_path))
engine = builder.build_cuda_engine(network)
print(“Completed creating Engine”)
with open(engine_file_path, “wb”) as f:
f.write(engine.serialize())
return engine
Hello, I am using this script to convert onnx into trt engine for ssd mobilenet model.
And then, I have the following error.
Beginning ONNX file parsing
[TensorRT] ERROR: Parameter check failed at: …/builder/Network.cpp::addInput::671, condition: isValidDims(dims, hasImplicitBatchDimension())
Completed parsing of ONNX file
Building an engine from file ssd_mobilenet_v2_coco_2018_03_29/model_edit.onnx; this may take a while…
[TensorRT] ERROR: Network must have at least one output
Completed creating Engine
Traceback (most recent call last):
File “onnx_runtime_pretrained.py”, line 87, in
engine = get_engine(onnx_file_path, engine_file_path)
File “onnx_runtime_pretrained.py”, line 82, in get_engine
return build_engine()
File “onnx_runtime_pretrained.py”, line 78, in build_engine
f.write(engine.serialize())
AttributeError: ‘NoneType’ object has no attribute ‘serialize’
What is wrong?
I tried with many articles related to that, but not working.
Could you please give me detailed help directly here?
I appreciate for that.