|
16 | 16 | """
|
17 | 17 |
|
18 | 18 | import torch
|
19 |
| -import torch.onnx as onnx |
20 | 19 | import torchvision.models as models
|
21 | 20 |
|
22 | 21 |
|
|
58 | 57 | ########################
|
59 | 58 | # .. note:: This approach uses Python `pickle <https://docs.python.org/3/library/pickle.html>`_ module when serializing the model, thus it relies on the actual class definition to be available when loading the model.
|
60 | 59 |
|
61 |
| -####################################################################### |
62 |
| -# Exporting Model to ONNX |
63 |
| -# ----------------------- |
64 |
| -# PyTorch also has native ONNX export support. Given the dynamic nature of the |
65 |
| -# PyTorch execution graph, however, the export process must |
66 |
| -# traverse the execution graph to produce a persisted ONNX model. For this reason, a |
67 |
| -# test variable of the appropriate size should be passed in to the |
68 |
| -# export routine (in our case, we will create a dummy zero tensor of the correct size): |
69 |
| - |
70 |
| -input_image = torch.zeros((1,3,224,224)) |
71 |
| -onnx.export(model, input_image, 'model.onnx') |
72 |
| - |
73 |
| -########################### |
74 |
| -# There are a lot of things you can do with ONNX model, including running inference on different platforms |
75 |
| -# and in different programming languages. For more details, we recommend |
76 |
| -# visiting `ONNX tutorial <https://github.com/onnx/tutorials>`_. |
77 |
| -# |
78 |
| -# Congratulations! You have completed the PyTorch beginner tutorial! Try |
79 |
| -# `revisting the first page <quickstart_tutorial.html>`_ to see the tutorial in its entirety |
80 |
| -# again. We hope this tutorial has helped you get started with deep learning on PyTorch. |
81 |
| -# Good luck! |
82 |
| -# |
| 60 | +####################### |
| 61 | +# Related Tutorials |
| 62 | +# ----------------- |
| 63 | +# `Saving and Loading a General Checkpoint in PyTorch <https://pytorch.org/tutorials/recipes/recipes/saving_and_loading_a_general_checkpoint.html>`_ |
0 commit comments