You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/CoreML/ONNXLive/README.md
+11-12Lines changed: 11 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
# ONNXLive Tutorial:
2
-
This tutorial will show you to convert a neural style transfer model that has been exported from PyTorch and into the Apple Core ML format using ONNX. THis will allow you to easily run deep learning models on Apple devices and, in this case, live stream from the camera.
2
+
This tutorial will show you to convert a neural style transfer model that has been exported from PyTorch and into the Apple CoreML format using ONNX. THis will allow you to easily run deep learning models on Apple devices and, in this case, live stream from the camera.
3
3
4
4
## What is ONNX?
5
5
ONNX (Open Neural Network Exchange is an open format to represent deep learning models. With ONNX, AI developers can more easily move models between state-of-the-art tools and choose the combination that is best for them. ONNX is developed and supported by a community of partners. You can learn more about ONNX and what tools are supported by going to [onnx.ai](http://onnx.ai/).
@@ -86,17 +86,16 @@ created from the corresponding `.pth` files.
86
86
87
87
## Convert the ONNX models to CoreML models
88
88
89
-
Now that we have the ONNX models, we can convert them to CoreML models to run on iOS devices.
89
+
Now that we have ONNX models, we can convert them to CoreML models in order to run them on Apple devices.
90
90
For this, we use the onnx-coreml converter we installed previously.
91
-
The converter comes with a `convert-onnx-to-coreml` script, which the installation steps above added to our path,
92
-
but unfortunately that doesn't work for us, because we need to mark the input and output of the network as an image
93
-
and while this is supported by the converter, it is only supported when calling the converter from python.
91
+
The converter comes with a `convert-onnx-to-coreml` script, which the installation steps above added to our path. Unfortunately that won't work for us as we need to mark the input and output of the network as an image
92
+
and, while this is supported by the converter, it is only supported when calling the converter from python.
94
93
95
94
Looking at the style transfer model (for example opening the .onnx file in an application like [Netron](https://github.com/lutzroeder/Netron)),
96
95
we see that the input is named '0' and the output is named '186'. These are just numeric ids assigned by PyTorch.
97
-
These are the ones we need to mark as images.
96
+
We will need to mark these as images.
98
97
99
-
So let's write a small python file `onnx_to_coreml.py`
98
+
So let's create a small python file and call it `onnx_to_coreml.py`. This can be created by using the touch command and edited with your favorite editor to add the following lines of code.
100
99
101
100
import sys
102
101
from onnx import onnx_pb2
@@ -111,7 +110,7 @@ So let's write a small python file `onnx_to_coreml.py`
@@ -122,8 +121,7 @@ Now, there should be 4 CoreML models in your `saved_models` directory: `candy.ml
122
121
123
122
## Run the CoreML models in a style transfer iOS App
124
123
125
-
This repository (i.e. the one you're currently reading the README.md of) contains an iOS app able to run CoreML style transfer models
126
-
on a live camera stream from your phone camera. Let's clone the repository
124
+
This repository (i.e. the one you're currently reading the README.md of) contains an iOS app able to run CoreML style transfer models on a live camera stream from your phone camera. Let's clone the repository
127
125
128
126
git clone https://github.com/onnx/tutorials
129
127
@@ -132,12 +130,13 @@ We recommend using XCode 9.3 and an iPhone X. There might be issues running on o
132
130
133
131
In the `Models/` folder, the project contains some .mlmodel files. We're going to replace them with the models we just created.
134
132
135
-
Then, run the app on your iPhone and your all set. Tapping on the screen switches through the models.
133
+
You then, run the app on your iPhone and you are all set. Tapping on the screen switches through the models.
136
134
137
135
## Conclusion
138
136
139
137
We hope this tutorial gave you an overview of what ONNX is about and how you can use it to convert neural networks
140
-
between frameworks, in this case a few style transfer models from PyTorch to CoreML.
138
+
between frameworks, in this case neural style transfer models moving from PyTorch to CoreML.
141
139
142
140
Feel free to experiment with these steps and test them on your own models.
143
141
Please let us know if you hit any issues or want to give feedback. We'd like to hear what you think.
0 commit comments