Skip to content

Commit

Permalink
enable TRT parse ONNX model from file (#1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
AllentDan authored and lvhan028 committed Mar 1, 2023
1 parent 44aa3b6 commit f881b6c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mmdeploy/backend/tensorrt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,13 @@ def from_onnx(onnx_model: Union[str, onnx.ModelProto],
parser = trt.OnnxParser(network, logger)

if isinstance(onnx_model, str):
onnx_model = onnx.load(onnx_model)
parse_valid = parser.parse_from_file(onnx_model)
elif isinstance(onnx_model, onnx.ModelProto):
parse_valid = parser.parse(onnx_model.SerializeToString())
else:
raise TypeError('Unsupported onnx model type!')

if not parser.parse(onnx_model.SerializeToString()):
if not parse_valid:
error_msgs = ''
for error in range(parser.num_errors):
error_msgs += f'{parser.get_error(error)}\n'
Expand Down

0 comments on commit f881b6c

Please sign in to comment.