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: _mobile/ios.md
+10-9Lines changed: 10 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -16,38 +16,39 @@ To get started with PyTorch on iOS, we recommend exploring the following [HelloW
16
16
17
17
HelloWorld is a simple image classification application that demonstrates how to use PyTorch C++ libraries on iOS. The code is written in Swift and uses Objective-C as a bridge.
18
18
19
-
Before we jump into details, we highly recommend following the [Pytorch Github page](https://github.com/pytorch/pytorch) to set up the Python development environment on your local machine.
20
-
21
19
### Model preparation
22
20
23
-
Let's start with model preparation. If you are familiar with PyTorch, you probably should already know how to train and save your model. In case you don't, we are going to use a pre-trained image classification model(Resnet18), which is packaged in [TorchVision](https://pytorch.org/docs/stable/torchvision/index.html). To install it, run the command below.
21
+
Let's start with model preparation. If you are familiar with PyTorch, you probably should already know how to train and save your model. In case you don't, we are going to use a pre-trained image classification model - Resnet18, which is already packaged in [TorchVision](https://pytorch.org/docs/stable/torchvision/index.html). To install it, run the command below.
22
+
23
+
> Before running, we highly recommend following the [Pytorch Github page](https://github.com/pytorch/pytorch) to set up the Python development environment on your local machine.
24
24
25
25
```shell
26
26
pip install torchvision
27
27
```
28
28
29
-
Once we have TorchVision installed successfully, let's navigate to the HelloWorld folder and run `trace_model.py` to generate our model. The script contains the code of tracing and saving a [torchscript model](https://pytorch.org/tutorials/beginner/Intro_to_TorchScript_tutorial.html) that can be run on mobile devices. Run the command below to get our model
29
+
Once we have TorchVision installed successfully, let's navigate to the HelloWorld folder and run `trace_model.py`. The script contains the code of tracing and saving a [torchscript model](https://pytorch.org/tutorials/beginner/Intro_to_TorchScript_tutorial.html) that can be run on mobile devices.
30
30
31
31
```shell
32
32
python trace_model.py
33
33
```
34
34
35
-
If everything works well, we should have our model - `model.pt` generated in the same folder. Now copy the model file to our application folder `HelloWorld/model`.
35
+
If everything works well, we should have our model - `model.pt` generated in the `HelloWorld` folder. Now copy the model file to our application folder `HelloWorld/model`.
36
36
37
-
More details about TorchScript you can find in[tutorials on pytorch.org](https://pytorch.org/docs/stable/jit.html)
37
+
> To find out more details about TorchScript, please visit[tutorials on pytorch.org](https://pytorch.org/docs/stable/jit.html)
38
38
39
39
### Install PyTorch C++ libraries via Cocoapods
40
40
41
-
The PyTorch C++ library is available in [Cocoapods](https://cocoapods.org/), to integrate it to our project, we can run
41
+
The PyTorch C++ library is available in [Cocoapods](https://cocoapods.org/), to integrate it to our project, simply run
42
42
43
43
```ruby
44
44
pod install
45
45
```
46
+
46
47
Now it's time to open the `HelloWorld.xcworkspace` in XCode, select an iOS simulator and launch it (cmd + R). If everything works well, we should see a wolf picture on the simulator screen along with the prediction result.
47
48
48
49
### Code Walkthrough
49
50
50
-
In this part, we are going to walk through the code step by step. All logic happens in `ViewController.swift`.
51
+
In this part, we are going to walk through the code step by step.
For more complex use cases, we recommend to check out the PyTorch demo application. The demo app contains two showcases. A camera app that runs a quantized model to predict the images coming from device’s rear-facing camera in real time. And a text-based app that uses a self-trained NLP model to predict the topic from the input string.
145
+
For more complex use cases, we recommend to check out the PyTorch demo application. The demo app contains two showcases. A camera app that runs a quantized model to predict the images coming from device’s rear-facing camera in real time. And a text-based app that uses a text classififcation model to predict the topic from the input string.
0 commit comments