Run an Arm AI Portal depth estimation model on Android
Generate a depth map
Start Image Analysis:
adb shell am start -n com.arm.learningpath.imagetoimage/.ui.MainActivity
Run the first image:
- Select Depth Anything V2 Small INT8.
- Select Load model.
- Select Choose image and choose a JPEG or PNG scene with objects at different distances.
- Select Run depth estimation.
Image Analysis temporarily disables the model and image controls while it decodes an image, loads a model, or runs inference. The controls become available again when the operation finishes or reports an error.
The app displays a grayscale map. Brighter pixels have higher relative disparity and represent nearer regions. Darker pixels represent farther regions.
The result panel reports the original source resolution, model input and output resolution, and finite disparity range. The displayed map uses the decoded preview dimensions, which can be smaller for a large source image. The status panel reports model load and inference times.
After you stage the model in application-private storage, depth inference runs locally on the phone and doesn’t need a network connection.
Understand the adapter contract
The Android adapter follows the model card’s fixed contract:
| Stage | Behavior |
|---|---|
| Decode | Reads the selected RGB image with its orientation applied; the application might subsample a large image during decoding to limit memory use |
| Resize | Resizes the decoded RGB image to 686 x 518 with bicubic interpolation; this can change the source aspect ratio |
| Normalize | Scales channels to [0, 1], then applies ImageNet mean and standard deviation |
| Input | Creates one float32 [1, 3, 518, 686] tensor in NCHW order |
| Inference | Executes forward with the XNNPACK-backed ExecuTorch module |
| Output | Requires one finite float32 [1, 518, 686] relative-disparity tensor |
| Render | Min-max normalizes each result to [0, 255] and resizes it to the decoded preview dimensions with bilinear filtering |
If the output is constant, the adapter renders a black map instead of dividing by zero. It rejects an incorrect shape, dtype, missing XNNPACK declaration, or non-finite value.
Validate input-dependent results
Choose a second image with a different scene and run depth estimation again. Confirm the following:
- Both runs finish without a load or tensor-contract error.
- The disparity range contains finite numbers.
- The second depth map differs from the first.
- Nearer and farther regions have the expected brightness ordering.
- The displayed result fills and aligns with the decoded image preview.
What you’ve accomplished
You’ve run Depth Anything V2 Small on an Arm-based Android phone and generated and validated input-dependent relative-disparity maps.
You can extend this workflow to deploy monocular depth estimation models from the Arm AI Portal locally for your own use cases.