Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Object Detection in Java

Example of using pre-trained models of the TensorFlow Object Detection API in Java.


  1. Download some metadata files:

  2. Download a model from the object detection API model zoo. For example:

    mkdir -p models
    curl -L \ \
    | tar -xz -C models/
  3. Have some test images handy. For example:

    mkdir -p images
    curl -L -o images/test.jpg \
  4. Compile and run!

    mvn -q compile exec:java \
      -Dexec.args="models/ssd_inception_v2_coco_2017_11_17/saved_model labels/mscoco_label_map.pbtxt images/test.jpg"


  • This example demonstrates the use of the TensorFlow SavedModel format. If you have TensorFlow for Python installed, you could explore the model to get the names of the tensors using saved_model_cli command. For example:

    saved_model_cli show --dir models/ssd_inception_v2_coco_2017_11_17/saved_model/ --all
  • The file in src/main/object_detection/protos/ was generated using:

    protoc -Isrc/main/protobuf --java_out=src/main/java src/main/protobuf/string_int_label_map.proto

    Where protoc was downloaded from

You can’t perform that action at this time.