Coder Social home page Coder Social logo

onnxruntimeandorid's Introduction

OnnxRuntimeAndorid

This app uses ONNXRuntime (with NNAPI enabled) for Android C/C++ library to run MobileNet-v2 ONNX model. Android camera pixels are passed to ONNXRuntime using JNI

#On Google pixel 3 ONNXRuntime (with NNAPI execution provider) took around 25 miliseconds to run MobileNetV2 model

Implemtation Details

ONNXRuntime shared object (libonnxruntime.so) was created by following instructions in ONNXRuntime Docs. https://github.com/microsoft/onnxruntime/blob/master/BUILD.md#android-build-instructions

./build.sh --android --android_sdk_path /Users/username/Library/Android/sdk --android_ndk_path /Users/username/Documents/Android/android-ndk-r21d --android_abi arm64-v8a --android_api 28 --use_nnapi --parallel --build_shared_lib --config MinSizeRel

libonnxruntime.so is copied to distribution/lib/arm64-v8a/libonnxruntime.so and ONNXRuntime headers are copied to distribution/include/onnxruntime

  • app/src/main/cpp path contains ONNXRuntime C++ inference, preprocessing input, postprocessing output, JNI wrappers code
  • app/src/main/java/com/play/onnxruntime contains java code to open camera, display image stream, access bitmap, UI, JNI calls to run inference..
  • app/CMakeLists.txt is the cmake file to compile the c++ code

Run the prebuilt apk

copy model/mobilenetv2-7.onnx and model/labels.txt to /data/local/tmp directory on device

adb push model/mobilenetv2-7.onnx /data/local/tmp
adb push model/labels.txt /data/local/tmp

Install the prebuilt apk file

adb install apk/app-debug.apk

Build Instructions

#Requirements

  • Android SDK 29
  • Android NDK r21d

Open the local.properties file and set ndk.dir to the path of Android NDK folder.

sdk.dir = /Users/Name/Library/Android/sdk
ndk.dir = /Users/Name/Documents/Android/android-ndk-r21d

Run the app after making the above changes.

#Note This app was test on Google pixel3 and build for arm64-v8a.

onnxruntimeandorid's People

Contributors

rohithkvsp avatar

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.