Skip to content

Commit e6ccd93

Browse files
committed
feat: Add GitHub Actions workflow for model export and enhance DeepLabV3 Android demo with improved segmentation visualization and inference time display.
1 parent d0d845a commit e6ccd93

9 files changed

Lines changed: 441 additions & 237 deletions

File tree

dl3/android/DeepLabV3Demo/README.md

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ This guide explains how to setup ExecuTorch for Android using a demo app. The ap
66
* Download and install [Android Studio and SDK 34](https://developer.android.com/studio).
77
* (For exporting the DL3 model) Python 3.10+ with `executorch` package installed.
88

9-
## Step 1: Export the model
10-
Run the script in `dl3/python/export.py` to export the model.
9+
## Step 1: Export the model (Optional)
10+
The app can download the model automatically. If you want to export it yourself, run:
11+
```bash
12+
python dl3/python/export.py
13+
```
1114

1215
## Step 2: Set up your device or emulator
13-
You can run the app on either a physical device or an emulator. To set up your device or emulator, follow these steps:
16+
You can run the app on either a physical device or an emulator.
1417

1518
### Using a Physical Device
1619
* Connect your device to your computer via USB.
@@ -20,52 +23,54 @@ You can run the app on either a physical device or an emulator. To set up your d
2023
* Open Android Studio and create a new virtual device.
2124
* Start the emulator by clicking the "Play" button next to the device name.
2225

23-
## Step 3: Build, install, and run the app on your phone
26+
## Step 3: Build, install, and run the app
2427
### On your terminal
25-
(`cd dl3/android/DeepLabV3Demo` first)
26-
```
28+
```bash
29+
cd dl3/android/DeepLabV3Demo
2730
./gradlew installDebug
2831
adb shell am start -W -S -n org.pytorch.executorchexamples.dl3/.MainActivity
2932
```
3033

3134
### On Android Studio
3235
Open Android Studio and open the project path `dl3/android/DeepLabV3Demo`. Wait for gradle sync to complete.
33-
Then simply press "Run app" button (Control + r) to run the app either on physical device / emulator.
36+
Then simply press "Run app" button (Control + r) to run the app.
3437

35-
## Step 4: Push the model to the phone or emulator
36-
The app loads a hardcoded model path (`/data/local/tmp/dl3_xnnpack_fp32.pte`) on the phone.
37-
Run the following adb command to push the model.
38-
```
38+
## Step 4: Download or Push the model
39+
40+
### Option A: Download from the app (Recommended)
41+
The app includes a **"Download Model"** button that automatically downloads and extracts the model. Simply tap the button and wait for the download to complete.
42+
43+
### Option B: Push manually via adb
44+
If you exported the model yourself or want to use a custom model:
45+
```bash
3946
adb push dl3_xnnpack_fp32.pte /data/local/tmp/dl3_xnnpack_fp32.pte
4047
```
4148

42-
Note: If you want to use a QNN lowered model, you mush modify the maven executorch dependency to [executorch-qnn](https://mvnrepository.com/artifact/org.pytorch/executorch-android-qnn) and rebuild the app.
49+
> **Note:** If you want to use a QNN lowered model, modify the maven executorch dependency to [executorch-qnn](https://mvnrepository.com/artifact/org.pytorch/executorch-android-qnn) and rebuild the app.
4350
44-
## Step 5: Load and Test Custom Images (No APK Rebuild Needed)
45-
You can now test image segmentation on your own images (supported formats: .jpg, .jpeg, .png) without rebuilding the APK. The app supports loading .jpg, .jpeg, and .png images from the /sdcard/Pictures/ directory, with user-granted permissions.
51+
## Step 5: Load and Test Custom Images
52+
You can test image segmentation on your own images (supported formats: .jpg, .jpeg, .png) without rebuilding the APK.
4653

4754
### How to Use
48-
#### a. Push your image to the device:
49-
```
50-
adb push <path to your image> /sdcard/Pictures/
51-
52-
```
53-
#### b. After the push, In the app:
54-
- Tap the "Load And Refresh" button.
55-
- If prompted, grant the app permission to access the /sdcard/Pictures/ folder.
56-
- The image should appear immediately in the app.
57-
- You can now run dynamic image segmentation and view the results.
55+
1. Push your image to the device:
56+
```bash
57+
adb push <path to your image> /sdcard/Pictures/
58+
```
5859

59-
Tip: You can use images containing Dog, Sheep, Person, or any combination of these classes.
60+
2. In the app:
61+
- Tap the **"Load And Refresh"** button
62+
- If prompted, grant permission to access the /sdcard/Pictures/ folder
63+
- The image should appear immediately
64+
- Tap **"Run"** to perform segmentation
6065

61-
This feature enhances the testing/validation process by allowing users to quickly test different images without the need to rebuild the application.
66+
### Supported Classes
67+
The app detects all 21 PASCAL VOC classes including: Person, Dog, Cat, Car, Bicycle, Bird, and more. Each class is highlighted with a distinct color overlay.
6268

6369
## Step 6: Run unit test
6470
### On your terminal
65-
```
71+
```bash
6672
./gradlew connectedAndroidTest
6773
```
6874

6975
### On Android Studio
70-
In Android Studio project, open file `app/src/androidTest/java/org/pytorch/executorchexamples/dl3/SanityCheck.java`,
71-
and click the "Play" button for `public class SanityCheck` (Control + Shift + r).
76+
Open `app/src/androidTest/java/org/pytorch/executorchexamples/dl3/SanityCheck.java` and click the "Play" button for `public class SanityCheck`.

dl3/android/DeepLabV3Demo/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
1111
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
12+
<uses-permission android:name="android.permission.INTERNET" />
1213

1314
<application
1415
android:allowBackup="false"

0 commit comments

Comments
 (0)