Coder Social home page Coder Social logo

iq-scm / tensorflow-example-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from szaza/tensorflow-example-java

0.0 0.0 0.0 507 KB

This is a Tensorflow Java example application what uses YOLOv2 model and Gradle for build and dependency management.

License: Do What The F*ck You Want To Public License

Java 100.00%

tensorflow-example-java's Introduction

TensorFlow Java example with YOLOv2 built by Gradle

TensorFlow Java API is a new opportunity to use TensorFlow from Java applications. On the official TensorFlow site you can find a description about the Java API usage with Maven using an Inception model. This sample shows you how to use TensorFlow from Java programs using Gradle as build and dependency management tool. In my sample code I used the YOLO vesion 2 to detect and classify objects.

How it works?

tensorflow java example cow and bird tensorflow java example
Input image Bird and cow detected by YOLO using TensorFlow Java API
tensorflow yolo java eagle java tensorflow yolo sample
Input image Bird detected by YOLO using TensorFlow Java API

Compile and run

Preconditions:

  • Java JDK 1.8 or greater;
  • TensorFlow 1.6 or grater;
  • Git version control system;

Strongly recommended to install:

  • nVidia CUDA Toolkit 8.0 or higher version;
  • nVidia cuDNN GPU accelerated deep learning framework;

Download the frozen graphs

Before compiling the application you have to create/download some graph definition files. To try out the application you can use my frozen graphs, which are trained to the Pascal VOC dataset with 20 classes. You can download them from my google drive here. Place these files under the src/main/resources/YOLO directory.

Please make sure that you've set properly the GRAPH_FILE and LABEL_FILE variables in the Configuration file.

Compile the source by using Gradle

By default it runs on CPU. If you want to run this program with GPU support please add this line to the build.gradle file:
compile group: 'org.tensorflow', name: 'libtensorflow_jni_gpu', version: '1.6.0'

Specify the path for the image in the Main class (for sure it can be modified to read from the command line arguments).
Compile the code with the following command: ./gradlew clean build

Run the application

Type the ./gradlew run command in the command line window and hit enter. You are done! The output is printed out with the LogBack logging framework so, it looks like:

INFO edu.ml.tensorflow.ObjectDetector - Object: cow - confidence: 0.8864294
INFO edu.ml.tensorflow.ObjectDetector - Object: bird - confidence: 0.64604723

Note

If you would like to create a client-server architecture with Spring Framework check this project: TensorFlow Java tutorial with Spring.

FAQ

Is it much slower than the TensorFlow Python or TensorFlow C++ API?
No, because it communicates through Java Native Interface (JNI)

News about YoloV3 support

The current solution doesn't support the YoloV3 model and unfortunately, I do not have time to implement it, however I would be very happy if I could help to implement and I could review a PR with this feture. For this reason I've started a new branch here: https://github.com/szaza/tensorflow-java-examples-spring/tree/feature/add-yolov3-support; If you are interested in this feature and you would like to be a collabortor, please add a comment for this thread: szaza/tensorflow-java-examples-spring#2;

Many-many thank for any support!

tensorflow-example-java's People

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.