|
| 1 | +# ONNX Runtime Mobile image classification Android sample application |
| 2 | + |
| 3 | +## Overview |
| 4 | +This is an example application for [ONNX Runtime](https://github.com/microsoft/onnxruntime) on Android. The demo app uses image classfication which is able to continuously classify the objects it sees from the device's camera in real-time and displays the most probable inference result on the screen. |
| 5 | + |
| 6 | +This example is loosely based on [Google CodeLabs - Getting Started with CameraX](https://codelabs.developers.google.com/codelabs/camerax-getting-started) |
| 7 | + |
| 8 | +### Model |
| 9 | +We use classic MobileNetV2(float) model and MobileNetV2 (uint8) in this sample app. |
| 10 | + |
| 11 | +## Requirements |
| 12 | +- Android Studio 4.1+ (installed on Mac/Windows/Linux) |
| 13 | +- Android SDK 29+ |
| 14 | +- Android NDK r21+ |
| 15 | +- Android device in developer mode and enable USB debugging |
| 16 | + |
| 17 | +## Build And Run |
| 18 | +### Prerequisites |
| 19 | +- MobileNetV2 ort format model |
| 20 | +- labels text file (used for image classification) |
| 21 | +- Prebuilt ONNX Runtime arm64 Android Archive(AAR) files, which can be directly imported in Android Studio |
| 22 | + |
| 23 | +The above three files are provided and can be downloaded [here](https://1drv.ms/u/s!Auaxv_56eyubgQX-S_kTP0AP66Km?e=e8YMX1). |
| 24 | + |
| 25 | +[Optional] You can also build your own ONNX Runtime arm64 AAR files for Android. (See [build instructions here](https://www.onnxruntime.ai/docs/how-to/build.html#android) and [Build Android Archive(AAR)](https://www.onnxruntime.ai/docs/how-to/build.html#build-android-archive-aar)). |
| 26 | + |
| 27 | + |
| 28 | +### Step 1. Clone the ONNX Runtime Mobile examples source code and download required model files |
| 29 | +Clone this ORT Mobile examples GitHub repository to your computer to get the sample application. |
| 30 | + |
| 31 | +Download the packages provided in `Prerequisites`. |
| 32 | + |
| 33 | +- Copy MobileNetV1 onnx model and the labels file to `example/image_classification/android/app/src/main/res/raw/` |
| 34 | + |
| 35 | +- Create `/libs` directory under `app/` and copy the AAR file `onnxruntime-release.aar` to `app/libs` |
| 36 | + |
| 37 | +Then open the sample application in Android Studio. To do this, open Android Studio and select `Open an existing project`, browse folders and open the folder `examples/image_classification/android/`. |
| 38 | + |
| 39 | +<img width=60% src="images/screenshot_1.png"/> |
| 40 | + |
| 41 | +### Step 2. Build the sample application in Android Studio |
| 42 | + |
| 43 | +Select `Build-Make Project` in the top toolbar in Android Studio and check the projects has built successfully. |
| 44 | + |
| 45 | +<img width=60% src="images/screenshot_3.png" alt="App Screenshot"/> |
| 46 | + |
| 47 | +<img width=60% src="images/screenshot_4.png" alt="App Screenshot"/> |
| 48 | + |
| 49 | +### Step 3. Connect your Android Device and run the app |
| 50 | + |
| 51 | +Connect your Android Device to the computer and select your device in the top-down device bar. |
| 52 | + |
| 53 | +<img width=60% src="images/screenshot_5.png" alt="App Screenshot"/> |
| 54 | + |
| 55 | +<img width=60% src="images/screenshot_6.png" alt="App Screenshot"/> |
| 56 | + |
| 57 | +Then Select `Run-Run app` and this will prompt the app to be installed on your device. |
| 58 | + |
| 59 | +Now you can test and try by opening the app `ort_image_classifier` on your device. The app may request your permission for using the camera. |
| 60 | + |
| 61 | + |
| 62 | +# |
| 63 | +Here's an example screenshot of the app. |
| 64 | + |
| 65 | +<img width=20% src="images/screenshot_2.jpg" alt="App Screenshot" /> |
| 66 | + |
| 67 | + |
| 68 | + |
0 commit comments