GithubHelp home page GithubHelp logo

tspannhw / onnxinferencejava Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vandanavk/onnxinferencejava

0.0 2.0 0.0 21 KB

Convert a Chainer model to ONNX format, import to MXNet and perform inference using MXNet's Java API

Python 37.45% Java 62.55%

onnxinferencejava's Introduction

ONNX model inference using MXNet's Java API

Recommendations:

  • Use Python 3.5+ as onnx_chainer requires Python 3.5+
  • Chainer is not guaranteed to work on MacOS and Windows (Reference)
  • Use conda to create a virtual environment for Python

Installation:

  1. Clone this repo with
git clone https://github.com/vandanavk/ONNXinferenceJava.git
cd ONNXinferenceJava/
  1. Create and activate a conda environment
pip install conda
conda create -n mxnet_blog python=3.6

conda activate mxnet_blog

Tip: If you are unable to activate the conda environment, try this

  1. Install Python dependencies
pip install mxnet==1.4.0
pip install chainer==5.3.0
pip install chainercv==0.12.0
pip install onnx==1.3.0
pip install onnx_chainer==1.3.3
  1. For Java, install the pre-requisites Reference

For macOS

brew update
brew tap caskroom/versions
brew cask install java8
brew install maven

For Ubuntu

sudo apt-get install openjdk-8-jdk maven

Code execution:

  1. Execute the Python file to convert the Chainer model to an MXNet model

python chainer_onnx_mxnet.py

Check model/ folder for

chainer_vgg16.onnx, vgg16-symbol.json, vgg16-0000.params, synset.txt

Check data/ folder for Penguin.jpg

  1. Execute the Java file to perform inference
mvn clean dependency:copy-dependencies install
java -Xmx8G -cp target/ONNXJava-1.0-SNAPSHOT.jar:target/dependency/* mxnet.ONNXMXNetJava --model-path-prefix model/vgg16 --input-image data/Penguin.jpg

Alternatively, open ONNXInferenceJava in an IDE, build the project and run ONNXMXNetJava.java

Deactivate conda environment

conda deactivate mxnet_blog

onnxinferencejava's People

Contributors

vandanavk avatar

Watchers

James Cloos avatar  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.