Skip to content

HongminHan/tensorflow-java

 
 

Repository files navigation

tensorflow-java

Tensorflow Java examples

How To Install

You need to run the jni.sh to install the right Java bindings for your platform and the download.sh script that will download the inception5 model in order to be ready to run a simple examples:

git clone https://github.com/loretoparisi/tensorflow-java.git \
cd tensorflow-java \
sh jni.sh \
sh download.sh \

A simple Hello World example

Create a simple Java class with a main to be executable and import org.tensorflow.TensorFlow

import org.tensorflow.TensorFlow;

public class TensorFlowExample {
  public static void main(String[] args) {
    System.out.println("TensorFlowExample using TensorFlow version: " +  TensorFlow.version());
  }
}

Save it and then from command line compile and run

cd tensorflow-java
javac -cp lib/libtensorflow-1.4.0.jar TensorFlowExample.java
java -cp lib/libtensorflow-1.4.0.jar:. -Djava.library.path=./jni TensorFlowExample

If you get the TensorFlow version as output it worked!

TensorFlowExample using TensorFlow version: 1.0.0-rc2

Real world (Inception) example

We use the LabelImage official Tensorflow example to label an example image with the inception graph model.

$ javac -cp lib/libtensorflow-1.4.0.jar LabelImage.java 
$ java -cp lib/libtensorflow-1.4.0.jar:. -Djava.library.path=./jni LabelImage models/ images/example-400x288.jpg 
BEST MATCH: lakeside (19,00% likely)

Disclaimer

This example is provided as it is and it is based on the official Tensorflow Java JNI wrapper and example available here.

About

Tensorflow Java examples

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 92.0%
  • Shell 8.0%