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
feat: Add GitHub Actions workflow for model export and enhance DeepLabV3 Android demo with improved segmentation visualization and inference time display.
Copy file name to clipboardExpand all lines: dl3/android/DeepLabV3Demo/README.md
+34-29Lines changed: 34 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,14 @@ This guide explains how to setup ExecuTorch for Android using a demo app. The ap
6
6
* Download and install [Android Studio and SDK 34](https://developer.android.com/studio).
7
7
* (For exporting the DL3 model) Python 3.10+ with `executorch` package installed.
8
8
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
+
```
11
14
12
15
## 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.
14
17
15
18
### Using a Physical Device
16
19
* 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
20
23
* Open Android Studio and create a new virtual device.
21
24
* Start the emulator by clicking the "Play" button next to the device name.
22
25
23
-
## Step 3: Build, install, and run the app on your phone
26
+
## Step 3: Build, install, and run the app
24
27
### On your terminal
25
-
(`cd dl3/android/DeepLabV3Demo` first)
26
-
```
28
+
```bash
29
+
cd dl3/android/DeepLabV3Demo
27
30
./gradlew installDebug
28
31
adb shell am start -W -S -n org.pytorch.executorchexamples.dl3/.MainActivity
29
32
```
30
33
31
34
### On Android Studio
32
35
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.
34
37
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:
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.
43
50
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.
46
53
47
54
### 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
+
```
58
59
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
60
65
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.
62
68
63
69
## Step 6: Run unit test
64
70
### On your terminal
65
-
```
71
+
```bash
66
72
./gradlew connectedAndroidTest
67
73
```
68
74
69
75
### 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`.
0 commit comments