Class ObjectDetectionService

java.lang.Object
org.springframework.cloud.fn.object.detection.ObjectDetectionService

public class ObjectDetectionService extends Object
Convenience class that leverages the the ObjectDetectionInputConverter, ObjectDetectionOutputConverter and TensorFlowService in combination fromMemory the Tensorflow Object Detection API (https://github.com/tensorflow/models/tree/master/research/object_detection) models for detection objects in input images. All pre-trained models (https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md) and labels are supported. You can download pre-trained models directly from the zoo: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md Just use the URI notation: (zoo model tar.gz url)#(name of the frozen model file name). To speedup the bootstrap performance you should consider downloading the models locally and use the file:/"path to my model" URI instead! The object category labels for the pre-trained models are available at: https://github.com/tensorflow/models/tree/master/research/object_detection/data Use the labels applicable for the model. Also, for performance reasons you may consider to download the labels and load them from file: instead.
Author:
Christian Tzolov
  • Field Details

    • FETCH_NAMES

      public static List<String> FETCH_NAMES
      Default list of fetch names for Box models.
    • FETCH_NAMES_WITH_MASKS

      public static List<String> FETCH_NAMES_WITH_MASKS
      Default list of fetch names for mask supporting models.
  • Constructor Details

    • ObjectDetectionService

      public ObjectDetectionService()
    • ObjectDetectionService

      public ObjectDetectionService(String modelUri, String labelsUri, float confidence, boolean withMasks, boolean cacheModel)
      Convenience constructor that would initialize all necessary internal components.
      Parameters:
      modelUri - URI of the pre-trained, frozen Tensorflow model.
      labelsUri - URI of the pre-trained category labels.
      confidence - Confidence threshold. Only objects detected wth confidence above this threshold will be returned.
      withMasks - If a Mask model is selected then you can use this flag to extract the instance segmentation masks as well.
    • ObjectDetectionService

      public ObjectDetectionService(ObjectDetectionInputConverter inputConverter, ObjectDetectionOutputConverter outputConverter, org.springframework.cloud.fn.common.tensorflow.deprecated.TensorFlowService tensorFlowService)
      Generic constructor thea allow the converter to be pre-configured before passed to the service.
      Parameters:
      inputConverter - Converter from byte array to object detection input image tensor
      outputConverter - Covets the object detection output tensors into ObjectDetection list
      tensorFlowService - Java tensorflow runner instance
  • Method Details

    • detect

      public List<ObjectDetection> detect(String imageUri)
      Detects objects in a single input image identified by its URI.
      Parameters:
      imageUri - input image's URI
      Returns:
      Returns a list of ObjectDetection domain objects representing detected objects
    • detect

      public List<ObjectDetection> detect(BufferedImage image, String format)
      Detects objects in a single BufferedImage.
      Parameters:
      image - Input image to detect objects from.
      format - Image format (e.g. jpg, png ...) to use when converting the buffer into byte array.
      Returns:
      Returns a list of ObjectDetection domain objects representing detected objects in the input image
    • detect

      public List<ObjectDetection> detect(byte[] image)
      Detects objects from a single input image encoded as byte array.
      Parameters:
      image - Input image encoded as byte array
      Returns:
      Returns a list of ObjectDetection domain objects representing detected objects in the input image
    • detect

      public List<List<ObjectDetection>> detect(byte[][] batchedImages)
      Uses detects objects from a batch of input images encoded as byte array.
      Parameters:
      batchedImages - Batch of input images encoded as byte arrays. First dimension is the batch size and second the image bytes.
      Returns:
      Returns list of lists. For every input image in the batch a list of ObjectDetection domain objects representing detected objects in the input image.