To start with Java, you need to first set up a Maven project and add the following dependency to your pom.xml.
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow</artifactId>
<version>1.7.0</version>
</dependency>
This is an enumeration of two libraries:
libtensorflow
libtensorflow_jni
This process wraps up all the TensorFlow C++ libraries and JNI connector to access it through Java programs.
By default, it works on CPU powers. You can also add the following dependency to support GPU acceleration.
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>libtensorflow_jni_gpu</artifactId>
<version>1.7.0</version>
</dependency>
Now, you're ready to use TensorFlow features on Java.
For the whole program of training the model, refer the following link: https://github.com/tensorflow/models/blob/master/samples/languages/java/training/src/main/java/Train.java