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: recipes_source/mobile_perf.rst
+42Lines changed: 42 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -221,3 +221,45 @@ Now we are ready to benchmark your model:
221
221
Main run finished. Microseconds per iter: 121318. Iters per second: 8.24281
222
222
223
223
224
+
iOS
225
+
-------
226
+
227
+
For iOS, we'll be using our `TestApp <https://github.com/pytorch/pytorch/tree/master/ios/TestApp>_` as the benchmarking tool.
228
+
229
+
To begin with, let's apply the ``optimize_for_mobile`` method to our python script located at `TestApp/benchmark/trace_mode.py <https://github.com/pytorch/pytorch/blob/master/ios/TestApp/benchmark/trace_model.py>`_. Simply modify the code as below.
230
+
231
+
::
232
+
233
+
import torch
234
+
import torchvision
235
+
from torch.utils.mobile_optimizer import optimize_for_mobile
236
+
237
+
model = torchvision.models.mobilenet_v2(pretrained=True)
Now that we have the optimized model and PyTorch ready, it's time to generate our XCode project and do benchmarking. To do that, we'll be using a ruby script - `setup.rb` which does the heavy lifting jobs of setting up the XCode project.
253
+
254
+
::
255
+
256
+
ruby setup.rb
257
+
258
+
Now open the `TestApp.xcodeproj` and plug in your iPhone, you're ready to go. Below is an example result from iPhoneX
259
+
260
+
::
261
+
262
+
TestApp[2121:722447] Main runs
263
+
TestApp[2121:722447] Main run finished. Milliseconds per iter: 28.767
0 commit comments