Tensorflow is an open source software library developed by Google Brain team and provides strong support for machine learning and deep learning. It can be deployed to various platforms such as CPUs, GPUs, TPUs, and from desktops to clusters of servers to mobile and edge devices. IT supports programming languages such as Java,Go and C. In this post, I will describe how to do object detection with Tensorflow. We will use Tensorflow for Java. It can be added as a Maven dependency as follows:

 <dependency>
   <groupId>org.tensorflow</groupId>
   <artifactId>tensorflow</artifactId>
   <version>1.8.0</version>
 </dependency>

Or you can download the jar file as described here.

For object detection firstly you need a model. Models are created by training. For instance, you train the model with various photos of an apple tree. Then the model will recognize the image if you show another apple tree. There are ready to use models. Here you can find them.

Models are in protocol buffer format. Protocol buffer is a fast, small and simple format. Firstly you define your data format, and then you use a generated code to read and write structured data.

For Tensorflow predefined models, you can use this proto file as structure. After installing protocol buffer compiler you need to run the following command:

protoc –java_out=./ string_int_label_map.proto

This creates a java file and you will use this file in your object detection implementation where you install the protocol buffer pre-trained models which are in .pbtxt files.

You can use ready to use labels which are found here. You need to choose a compatible label file depending on your model.

Finally, here is the java sample for object detection.

Categories: Tutorial