About this module

Modules 1 and 2 prepared ExecuTorch programs on a development machine and ran them on a Raspberry Pi. Module 3 keeps the same ahead-of-time preparation workflow and changes the target to an Android application. Semantic segmentation is the example, but the workflow can also support image classification, chatbots, audio processing, object detection or other use-cases.

You will build an Android object-cutout application using TorchVision LR-ASPP MobileNetV3 and XNNPACK. The application lets the user choose a photo, runs semantic segmentation, selects the largest predicted foreground class, and makes all other pixels transparent.

Object cutout is a common building block in mobile photo editing. It can remove or replace a background, create stickers and collages, apply portrait effects, or clean up product photography. Running the model on the phone reduces the need to send the original image to the cloud.

You will prepare two ExecuTorch programs, compare their local segmentation results, and deploy the INT8 program to Android:

ModelPurpose
FP32 LR-ASPP MobileNetV3 with XNNPACKEstablish correctness and a local cutout-quality baseline.
INT8 LR-ASPP MobileNetV3 with XNNPACKConfirm acceptable quantized output, then deploy it to Android.

The application packages the INT8 .pte artifact, model_spec.json, and class labels as Android assets. Java code copies the model into app-private storage, loads it with ExecuTorch, prepares a selected image, runs inference, and converts the output tensor into a transparent cutout. The app reports preprocessing, model-forward, postprocessing, and total time.

You do not need an Android phone to complete the module. A physical device is preferable for performance testing, but you can run the application with an Android Studio emulator.

Previous page Complete and continue