77Export a PyTorch model to ONNX
88==============================
99
10- **Author**: `Thiago Crepaldi <https://github.com/thiagocrepaldi >`_
10+ **Author**: `Ti-Tai Wang <https://github.com/titaiwangms>`_ and `Xavier Dupré <https://github.com/xadupre >`_
1111
1212.. note::
1313 As of PyTorch 2.1, there are two versions of ONNX Exporter.
@@ -127,7 +127,7 @@ def forward(self, x):
127127# Once Netron is open, we can drag and drop our ``my_image_classifier.onnx`` file into the browser or select it after
128128# clicking the **Open model** button.
129129#
130- # .. image:: ../../_static/img/onnx/image_clossifier_onnx_modelon_netron_web_ui .png
130+ # .. image:: ../../_static/img/onnx/image_classifier_onnx_model_on_netron_web_ui .png
131131# :width: 50%
132132#
133133#
@@ -155,7 +155,7 @@ def forward(self, x):
155155
156156import onnxruntime
157157
158- onnx_input = onnx_program . adapt_torch_inputs_to_onnx ( torch_input )
158+ onnx_input = [ torch_input ]
159159print (f"Input length: { len (onnx_input )} " )
160160print (f"Sample input: { onnx_input } " )
161161
@@ -166,7 +166,8 @@ def to_numpy(tensor):
166166
167167onnxruntime_input = {k .name : to_numpy (v ) for k , v in zip (ort_session .get_inputs (), onnx_input )}
168168
169- onnxruntime_outputs = ort_session .run (None , onnxruntime_input )
169+ # onnxruntime returns a list of outputs
170+ onnxruntime_outputs = ort_session .run (None , onnxruntime_input )[0 ]
170171
171172####################################################################
172173# 7. Compare the PyTorch results with the ones from the ONNX Runtime
@@ -179,7 +180,6 @@ def to_numpy(tensor):
179180# Before comparing the results, we need to convert the PyTorch's output to match ONNX's format.
180181
181182torch_outputs = torch_model (torch_input )
182- torch_outputs = onnx_program .adapt_torch_outputs_to_onnx (torch_outputs )
183183
184184assert len (torch_outputs ) == len (onnxruntime_outputs )
185185for torch_output , onnxruntime_output in zip (torch_outputs , onnxruntime_outputs ):
0 commit comments