Welcome to the tutorial on setting up the ExecuTorch iOS Demo App!
This app uses the MobileNet v3 model to process live camera images leveraging three different backends: XNNPACK, Core ML and Metal Performance Shaders (MPS).
Before we start, make sure you have the following tools installed:
Install Xcode 15 from the Mac App Store and then install the Command Line Tools using the terminal:
xcode-select --install
Python 3.10 or above, along with pip, should be pre-installed on MacOS 13.5+. If needed, download Python and install it. Verify the Python and pip versions using these commands:
which python3 pip python3 --version pip --version
Before proceeding, follow the Setting Up ExecuTorch tutorial to configure the basic environment.
Also, follow the corresponding sections from Core ML and MPS tutorials to install additional dependencies for those backends. Do not build anything just yet!
Now let's move on to exporting and bundling the MobileNet v3 model.
Export the MobileNet v3 model with CoreML, MPS and XNNPACK delegates, and move the exported model to a specific location where the Demo App will pick them up:
python3 -m examples.portable.scripts.export --model_name="mv3" python3 -m examples.xnnpack.aot_compiler --delegate --model_name="mv3" python3 -m examples.apple.coreml.scripts.export_and_delegate --model_name="mv3" python3 -m examples.apple.mps.scripts.mps_example --model_name="mv3" mkdir -p examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/ mv mv3*.pte examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/
Download the MobileNet model labels required for image classification:
curl https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt \ -o examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/imagenet_classes.txt
Next, we will build the necessary frameworks for ExecuTorch and move them over for app linking.
./build/build_apple_frameworks.sh --Release --coreml --mps --xnnpack
Make sure to have all the .xcframework bundles generated at the previous step at a specific location where the Demo App will pick them up:
mv cmake-out examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Frameworks
We're almost done! Now, we just need to open the project in Xcode, run the tests, and finally run the app.
Double-click on the project file under examples/demo-apps/apple_ios/ExecuTorchDemo or run the command:
open examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo.xcodeproj
You can run tests on Simulaltor directly in Xcode with Cmd + U or use the command line:
xcrun simctl create executorch "iPhone 15" xcodebuild clean test \ -project examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo.xcodeproj \ -scheme App \ -destination name=executorch xcrun simctl delete executorch
Finally, set up Code Signing in Xcode, and then run the app using Cmd + R.
Congratulations! You've successfully set up the ExecuTorch iOS Demo App. Now, you can explore and enjoy the power of ExecuTorch on your iOS device!