|
1 | 1 | Loading a PyTorch Model in C++ |
2 | 2 | ============================== |
3 | 3 |
|
| 4 | +**This tutorial was updated to work with PyTorch 1.2** |
| 5 | + |
4 | 6 | As its name suggests, the primary interface to PyTorch is the Python |
5 | 7 | programming language. While Python is a suitable and preferred language for |
6 | 8 | many scenarios requiring dynamism and ease of iteration, there are equally many |
@@ -129,10 +131,11 @@ earlier in the tracing example. To perform this serialization, simply call |
129 | 131 | `save <https://pytorch.org/docs/master/jit.html#torch.jit.ScriptModule.save>`_ |
130 | 132 | on the module and pass it a filename:: |
131 | 133 |
|
132 | | - traced_script_module.save("model.pt") |
| 134 | + my_module.save("custom_model.pt") |
133 | 135 |
|
134 | | -This will produce a ``model.pt`` file in your working directory. We have now |
135 | | -officially left the realm of Python and are ready to cross over to the sphere |
| 136 | +This will produce a ``custom_model.pt`` file in your working directory. |
| 137 | +If you also would like to save our traced version of ``ResNet18``, call ``traced_script_module.save("traced_resnet_model.pt")`` |
| 138 | +We have now officially left the realm of Python and are ready to cross over to the sphere |
136 | 139 | of C++. |
137 | 140 |
|
138 | 141 | Step 3: Loading Your Script Module in C++ |
@@ -285,13 +288,13 @@ distribution. If all goes well, it will look something like this: |
285 | 288 | [100%] Linking CXX executable example-app |
286 | 289 | [100%] Built target example-app |
287 | 290 |
|
288 | | -If we supply the path to the serialized ``ResNet18`` model we created earlier |
| 291 | +If we supply the path to the serialized custom model ``custom_model.pt`` we created earlier |
289 | 292 | to the resulting ``example-app`` binary, we should be rewarded with a friendly |
290 | 293 | "ok": |
291 | 294 |
|
292 | 295 | .. code-block:: sh |
293 | 296 |
|
294 | | - root@4b5a67132e81:/example-app/build# ./example-app model.pt |
| 297 | + root@4b5a67132e81:/example-app/build# ./example-app <path_to_model>/custom_model.pt |
295 | 298 | ok |
296 | 299 |
|
297 | 300 | Step 4: Executing the Script Module in C++ |
|
0 commit comments