This guide explains how to setup ExecuTorch for Android using a demo app. The app employs a DeepLab v3 model for image segmentation tasks. Models are exported to ExecuTorch using XNNPACK FP32 backend.
- Download and install Android Studio and SDK 34.
- (For exporting the DL3 model) Python 3.10+ with
executorch
package installed.
Run the script in dl3/python/export.py
to export the model.
The app loads a hardcoded model path (/data/local/tmp/dl3_xnnpack_fp32.pte
) on the phone.
Run the following adb command to push the model.
adb push dl3_xnnpack_fp32.pte /data/local/tmp/dl3_xnnpack_fp32.pte
(cd dl3/android/DeepLabV3Demo
first)
./gradlew installDebug
adb shell am start -W -S -n org.pytorch.executorchexamples.dl3/.MainActivity
Open Android Studio and open the project path dl3/android/DeepLanV3Demo
. Wait for gradle sync to complete.
Then simply press "Run app" button (Control + r).
./gradlew connectedAndroidTest
In Android Studio project, open file app/src/androidTest/java/org/pytorch/executorchexamples/dl3/SanityCheck.java
,
and click the "Play" button for public class SanityCheck
(Control + Shift + r).