ONE - On-device Neural Engine
Loading...
Searching...
No Matches
validate_onnx2circle.OnnxRunner Class Reference

Public Member Functions

 __init__ (self, filepath)
 
 load (self)
 
 feed_random_inputs (self)
 
 run (self)
 
 get_outputs (self)
 

Data Fields

 filepath
 
 session
 
 inputs
 
 inputs_size
 
 inputs_data
 
 outputs
 
 outputs_size
 
 outs
 

Detailed Description

Definition at line 54 of file validate_onnx2circle.py.

Constructor & Destructor Documentation

◆ __init__()

validate_onnx2circle.OnnxRunner.__init__ (   self,
  filepath 
)

Definition at line 55 of file validate_onnx2circle.py.

55 def __init__(self, filepath):
56 self.filepath = filepath
57 self.session = None
58 self.inputs = None
59 self.inputs_size = None
60 self.inputs_data = None
61 self.outputs = None
62 self.outputs_size = None
63

Member Function Documentation

◆ feed_random_inputs()

validate_onnx2circle.OnnxRunner.feed_random_inputs (   self)

Definition at line 77 of file validate_onnx2circle.py.

77 def feed_random_inputs(self):
78 self.inputs = self.session.get_inputs()
79 self.inputs_size = len(self.inputs)
80 # reset input dictionary
81 self.inputs_data = {}
82 for in_idx in range(self.inputs_size):
83 input_shape = self.inputs[in_idx].shape
84 input_type = self.inputs[in_idx].type
85 if input_type == 'tensor(float)':
86 torch_type = torch.float32
87 else:
88 # TODO support other dtype
89 raise SystemExit("Unsupported input dtype")
90
91 x = torch.randn(input_shape, dtype=torch_type)
92 input_npa = to_numpy(x)
93 self.inputs_data.update({self.inputs[in_idx].name: input_npa})
94
95 # save NHWC form of input for luci-interpreter
96 input_npa_nhwc = to_nhwc(input_npa)
97 input_npa_nhwc.tofile(circle_filepath + ".input" + str(in_idx))
98

References Operation.inputs, Request.inputs, circlechef::CircleImport.inputs(), crew::Part.inputs, luci::CircleReader.inputs(), luci::PGroup.inputs, luci::pass::Expression.inputs, mio::circle::Reader.inputs(), moco::ModelSignature.inputs(), tflinspect::Reader.inputs(), tflchef::TFliteImport.inputs(), tflread::Reader.inputs(), luci_interpreter::CircleReader.inputs(), onert_micro::core::reader::OMCircleReader.inputs(), moco::tf::test::TFNodeBuildTester.inputs(), moco::test::TFNodeBuildTester.inputs(), moco::test::TFNodeBuildTester.inputs(), luci::CircleFakeQuant.inputs(), moco::TFFakeQuantWithMinMaxVars.inputs(), luci::CircleAddN.inputs(), luci::CircleCustom.inputs(), luci::CircleAddN.inputs(), luci::CircleCustom.inputs(), loco::Graph.inputs(), nnkit::support::onnx::Runner.inputs(), ann::Operation.inputs(), loco::Graph.inputs(), luci::CircleFakeQuant.inputs(), moco::TFFakeQuantWithMinMaxVars.inputs(), nnc::sir::CallFunction.inputs, validate_onnx2circle.OnnxRunner.inputs, onert_micro::execute::OMRuntimeKernel.inputs, nnfw_custom_kernel_params.inputs, package.infer.session.inputs, onert::exec::IODescription.inputs, validate_onnx2circle.OnnxRunner.inputs_data, onert_micro::execute::OMRuntimeKernel.inputs_data, validate_onnx2circle.OnnxRunner.inputs_size, validate_onnx2circle.OnnxRunner.session, NNFW_SESSION.session, validate_onnx2circle.str, validate_onnx2circle.to_nhwc(), and validate_onnx2circle.to_numpy().

◆ get_outputs()

◆ load()

validate_onnx2circle.OnnxRunner.load (   self)

Definition at line 64 of file validate_onnx2circle.py.

64 def load(self):
65 model = onnx.load(self.filepath)
66 onnx.checker.check_model(model)
67 options = ort.SessionOptions()
68 # NOTE this is needed for U18.04
69 # referenced: https://github.com/microsoft/onnxruntime/issues/10113
70 options.intra_op_num_threads = 4
71 # NOTE set `providers` for https://github.com/microsoft/onnxruntime/issues/17631
72 providers = ort.get_available_providers()
73 self.session = ort.InferenceSession(self.filepath,
74 sess_options=options,
75 providers=providers)
76

References validate_onnx2circle.OnnxRunner.filepath, validate_onnx2circle.OnnxRunner.session, and NNFW_SESSION.session.

◆ run()

validate_onnx2circle.OnnxRunner.run (   self)

Definition at line 99 of file validate_onnx2circle.py.

99 def run(self):
100 self.outs = self.session.run(None, self.inputs_data)
101
void run(std::ofstream &os, const circle::Model *model)

Referenced by package.infer.session.inference().

Field Documentation

◆ filepath

validate_onnx2circle.OnnxRunner.filepath

Definition at line 56 of file validate_onnx2circle.py.

Referenced by validate_onnx2circle.OnnxRunner.load().

◆ inputs

validate_onnx2circle.OnnxRunner.inputs

◆ inputs_data

validate_onnx2circle.OnnxRunner.inputs_data

◆ inputs_size

validate_onnx2circle.OnnxRunner.inputs_size

◆ outputs

validate_onnx2circle.OnnxRunner.outputs

◆ outputs_size

validate_onnx2circle.OnnxRunner.outputs_size

Definition at line 62 of file validate_onnx2circle.py.

Referenced by validate_onnx2circle.OnnxRunner.get_outputs().

◆ outs

validate_onnx2circle.OnnxRunner.outs

Definition at line 100 of file validate_onnx2circle.py.

◆ session


The documentation for this class was generated from the following file: