Establish the model and output specification
The preparation script loads the pretrained LR-ASPP MobileNetV3 weights,
downloading them as needed. It then writes the weights, ordered Pascal VOC
labels, a sample image, and the shared preprocessing and output specification
to the artifact directory. It does not create a .pte file; export and
lowering happen in the next section.
Run the script from the repository root:
module-3-executorch-on-android-semantic-segmentation/scripts/aot/prepare_lraspp_mobilenetv3.py \
--out module-3-executorch-on-android-semantic-segmentation/artifacts/lraspp_mobilenetv3
Model loading and weight storage follow the pattern used in Module 2. An additional requirement for semantic segmentation is to preserve the mapping between output channels and Pascal VOC classes. The script writes the labels in class-ID order so Python and Android interpret each output plane consistently:
labels_path.write_text(
json.dumps(VOC_SEGMENTATION_LABELS, indent=2) + "\n"
)
The script also records the image preprocessing and output layout used by the
export, validation, and Android code. Open
module-3-executorch-on-android-semantic-segmentation/artifacts/lraspp_mobilenetv3/model_spec.json.
Its input and output entries should look like this:
"input": {
"shape": [1, 3, 520, 520],
"dtype": "float32",
"layout": "nchw",
"preprocessing": {
"resize": [520, 520],
"resize_mode": "letterbox",
"pad_rgb": [0, 0, 0],
"mean": [0.485, 0.456, 0.406],
"std": [0.229, 0.224, 0.225]
}
},
"output": {
"shape": [1, 21, 520, 520],
"dtype": "float32",
"layout": "nchw",
"postprocessing": {
"background_class": 0,
"default_class": "largest_non_background"
}
}
Letterboxing preserves the source aspect ratio and adds black padding to make a 520×520 tensor. Python validation, PTQ calibration, and the Android app all use this same operation.
The sample is a CC0 Labrador photograph saved in the artifact directory as
sample.jpg. The dog is clearly separated from the background, so the mask
boundary and transparent cutout are easy to inspect.
Check the input and output specification
After running the preparation script, check that you know and understand:
the input shape and layout
the resize mode
the output shape and layout
the number of classes, background class ID, and default foreground-selection rule
Why the specification matters
Every later step depends on this input and output specification. Python validation and Android inference must agree on image resize, letterboxing, normalization, tensor layout, class order, output shape, and foreground-selection logic.
Course complete
Nice work
You completed Optimize and deploy AI inference with ExecuTorch on Arm.