infil00p / pytorch_android_cpp_example

A sample application of how to use the NDK and OpenCV to make a basic classifier using PyTorch Mobile models.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Basic Example of PyTorch Mobile C++ API

This is an example of how to use PyTorch Mobile on Android using the NDK, and tying it together with pre-processing data written in OpenCV for portability.

This method is required if you're looking to port models across various frameworks for inference, such as CoreML and WinML so that the pre-processing that was originally written in Python only has to be re-implemented once, .instead of numerous times.

The use of OpenCV is optional, but was chosen due to it being common and having a good correspondence between the Python and C++ APIs.

HOW-TO RUN

  1. Download OpenCV 4.1 for Android and copy the related shared libraries into the pytorch_mobilenet/app/src/main/libs directory in their respective platform folders (x86, x86_64, armeabi-v7a, arm64-v8a) (Create a PR if you know of a known working AAR of OpenCV with the C++ libraries)
  2. Use the Jupyter Notebook in mobilenet_v2_work to export a .pt file from the MobilenetV2 model origianlly from torchvision
  3. Copy that file to the pytorch_mobile/app/src/main/assets directory
  4. Build and Run the Application.

This example code is licenced under the Apache 2.0 Licence.

All other code and headers are subject to their licences and copyright holders.

About

A sample application of how to use the NDK and OpenCV to make a basic classifier using PyTorch Mobile models.

License:Apache License 2.0


Languages

Language:C++ 90.3%Language:C 6.5%Language:Jupyter Notebook 2.6%Language:Kotlin 0.3%Language:Objective-C 0.2%Language:CMake 0.1%