Giter Club home page Giter Club logo

semseg_mobile's Introduction

ONNX Runtime Mobile image classification Android sample application

Overview

This is an example application for ONNX Runtime on Android. The demo app uses image classification which is able to continuously classify the objects it sees from the device's camera in real-time and displays the most probable inference results on the screen.

This example is loosely based on Google CodeLabs - Getting Started with CameraX

Model

We use pre-trained TorchVision MOBILENET V2 in this sample app.

Requirements

  • Android Studio 4.1+ (installed on Mac/Windows/Linux)
  • Android SDK 29+
  • Android NDK r21+
  • Android device with a camera in developer mode with USB debugging enabled

Build And Run

Step 0. [Optional] Prepare the ORT models

Open Mobilenet v2 Quantization with ONNX Runtime Notebook, this notebook will demonstrate how to,

  1. Export the pre-trained MobileNet V2 FP32 model from PyTorch to a FP32 ONNX model
  2. Quantize the FP32 ONNX model to an uint8 ONNX model
  3. Convert both FP32 and uint8 ONNX models to ORT models

Note: this step is optional, you can download the FP32 and uint8 ORT models here.

Step 1. Clone the ONNX Runtime Mobile examples source code and download required model files

Clone this GitHub repository to your computer to get the sample application.

Put the labels file and models into the sample application resource directory:

  • Download the labels file here
  • Copy MobileNetV2 ORT models and the labels file to mobile/examples/image_classification/android/app/src/main/res/raw/
  • Alternatively, you can run mobile/examples/image_classification/android/download_model_files.sh to download the labels file and models to the sample application resource directory.

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 mobile/examples/image_classification/android/.

Step 2. Build the sample application in Android Studio

Select Build -> Make Project in the top toolbar in Android Studio and check the projects has built successfully.

App Screenshot

App Screenshot

Step 3. Connect your Android Device and run the app

Connect your Android Device to the computer and select your device in the top-down device bar.

App Screenshot

App Screenshot

Then Select Run -> Run app and this will prompt the app to be installed on your device.

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.

Here's an example screenshot of the app.

App Screenshot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.