7
7
Export a PyTorch model to ONNX
8
8
==============================
9
9
10
- **Author**: `Thiago Crepaldi <https://github.com/thiagocrepaldi >`_
10
+ **Author**: `Ti-Tai Wang <https://github.com/titaiwangms>`_ and `Xavier Dupré <https://github.com/xadupre >`_
11
11
12
12
.. note::
13
13
As of PyTorch 2.1, there are two versions of ONNX Exporter.
@@ -127,7 +127,7 @@ def forward(self, x):
127
127
# Once Netron is open, we can drag and drop our ``my_image_classifier.onnx`` file into the browser or select it after
128
128
# clicking the **Open model** button.
129
129
#
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
131
131
# :width: 50%
132
132
#
133
133
#
@@ -155,7 +155,7 @@ def forward(self, x):
155
155
156
156
import onnxruntime
157
157
158
- onnx_input = onnx_program . adapt_torch_inputs_to_onnx ( torch_input )
158
+ onnx_input = [ torch_input ]
159
159
print (f"Input length: { len (onnx_input )} " )
160
160
print (f"Sample input: { onnx_input } " )
161
161
@@ -166,7 +166,8 @@ def to_numpy(tensor):
166
166
167
167
onnxruntime_input = {k .name : to_numpy (v ) for k , v in zip (ort_session .get_inputs (), onnx_input )}
168
168
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 ]
170
171
171
172
####################################################################
172
173
# 7. Compare the PyTorch results with the ones from the ONNX Runtime
@@ -179,7 +180,6 @@ def to_numpy(tensor):
179
180
# Before comparing the results, we need to convert the PyTorch's output to match ONNX's format.
180
181
181
182
torch_outputs = torch_model (torch_input )
182
- torch_outputs = onnx_program .adapt_torch_outputs_to_onnx (torch_outputs )
183
183
184
184
assert len (torch_outputs ) == len (onnxruntime_outputs )
185
185
for torch_output , onnxruntime_output in zip (torch_outputs , onnxruntime_outputs ):
0 commit comments