Skip to content

Repository files navigation

ExecuTorch Android Demo

A minimal Kotlin Android app that runs an ExecuTorch .pte model on-device using the XNNPACK CPU backend. It is wired to load an Edge Impulse-exported model.

image

Prebuilt sample APKs

Grab an APK from the Releases page and sideload it — no build required. Each ships a different Edge Impulse model and installs under its own app id, so you can keep all three side by side:

APK Model Input shape Classes
app-classification-debug.apk Image classifier [1, 3, 96, 96] lamp, plant, unknown
app-fomo-debug.apk FOMO object detection [1, 3, 320, 320] coffee, lamp
app-timeseries-debug.apk Motion (spectral) [1, 39] idle, snake, updown, wave

Compatible Learn Blocks Classification, Timeseries, Object Detection FOMO & KWS

Name link
Timeseries https://github.com/edgeimpulse/executorch-pytorch-timeseries-block
Classification https://github.com/edgeimpulse/executorch-pytorch-classification-block
FOMO https://github.com/edgeimpulse/executorch-pytorch-object-detection-fomo-block
KWS https://github.com/edgeimpulse/executorch-pytorch-kws-block
image image image
adb install -r app-classification-debug.apk

Open the app and tap Run inference. It runs one forward pass on a placeholder input and shows the output scores — proof the model loads and runs on-device.

Project layout

app/
  src/
    main/                         <- shared code, UI, launcher icon (no model)
      java/com/example/executorchdemo/
        MainActivity.kt           <- UI + runs one inference on a button tap
        EdgeImpulseClassifier.kt  <- loads the .pte, runs forward(), reads scores
    classification/assets/        <- model.pte + labels.txt + input_shape.txt
    fomo/assets/                  <- model.pte + labels.txt + input_shape.txt
    timeseries/assets/            <- model.pte + labels.txt + input_shape.txt

Each model is a Gradle product flavor (classification, fomo, timeseries). The bundled assets per flavor are:

  • model.pte — the ExecuTorch program exported from Edge Impulse
  • labels.txt — one class label per line, in output order
  • input_shape.txt — the input tensor shape, e.g. 1,3,96,96 (NCHW)

The input shape is read at runtime from input_shape.txt, so adding a new model is just a new flavor + assets — no code change.

Dependency

ExecuTorch comes from Maven Central (see app/build.gradle.kts):

implementation("org.pytorch:executorch-android:1.0.0")

Build & run

# build every flavor's debug APK
./gradlew assembleDebug
# -> app/build/outputs/apk/<flavor>/debug/app-<flavor>-debug.apk

# build/install a single flavor
./gradlew installClassificationDebug   # or installFomoDebug / installTimeseriesDebug

If a flavor has no bundled model you'll see this instead:

image

Requires the Android SDK (platform 35, build-tools 35) and JDK 17. The SDK location is read from local.properties (sdk.dir).

Using your own Edge Impulse model

  1. Add a flavor asset folder, e.g. app/src/<name>/assets/, with model.pte, labels.txt, and input_shape.txt.
  2. Register the flavor in app/build.gradle.kts under productFlavors.
  3. Replace the all-zeros placeholder input in MainActivity.runInference() with real, preprocessed data (a normalized camera frame, a sensor window, etc.).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages