Skip to content

Commit 5fd0e7b

Browse files
authored
Fix the bug in new RunONNXModel.py (#3259)
* fix Signed-off-by: Tong Chen <[email protected]> * fix Signed-off-by: Tong Chen <[email protected]> * fix Signed-off-by: Tong Chen <[email protected]> --------- Signed-off-by: Tong Chen <[email protected]>
1 parent 0b4489e commit 5fd0e7b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

utils/RunONNXModel.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ def execute_commands(cmds):
415415
def extend_model_output(model, intermediate_outputs):
416416
# Run shape inference to make sure we have valid tensor value infos for all
417417
# intermediate tensors available
418+
import onnx
419+
418420
model = onnx.shape_inference.infer_shapes(model)
419421
value_infos = {vi.name: vi for vi in model.graph.value_info}
420422
graph_inputs = {vi.name: vi for vi in model.graph.input}
@@ -454,6 +456,7 @@ def read_input_from_refs(num_inputs, load_ref_filename, is_load_ref):
454456
inputs = []
455457

456458
if is_load_ref:
459+
import onnx
457460
from onnx import numpy_helper
458461

459462
for i in range(num_inputs):
@@ -488,6 +491,7 @@ def read_output_from_refs(num_outputs, load_ref_filename, is_load_ref):
488491
reference_output = []
489492

490493
if is_load_ref:
494+
import onnx
491495
from onnx import numpy_helper
492496

493497
for i in range(num_outputs):
@@ -875,13 +879,14 @@ def __init__(self, session_wrapper, model_file=None, **kwargs):
875879
else:
876880
# Compile the ONNX model.
877881
# Prepare input and output paths.
878-
import onnx
879882

880883
if args.model.endswith(".onnx"):
881884
if args.verify and args.verify == "onnxruntime" and args.verify_all_ops:
882885
input_model_path = os.path.join(
883886
self.model_dir, f"{self.default_model_name}.onnx"
884887
)
888+
import onnx
889+
885890
onnx.save(model, input_model_path)
886891
else:
887892
input_model_path = args.model

0 commit comments

Comments
 (0)