public class ObjectDetectionService extends Object
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.Modifier and Type | Field and Description |
---|---|
static List<String> |
FETCH_NAMES
Default list of fetch names for Box models.
|
static List<String> |
FETCH_NAMES_WITH_MASKS
Default list of fetch names for mask supporting models.
|
Constructor and Description |
---|
ObjectDetectionService() |
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.
|
ObjectDetectionService(String modelUri,
String labelsUri,
float confidence,
boolean withMasks,
boolean cacheModel)
Convenience constructor that would initialize all necessary internal components.
|
Modifier and Type | Method and Description |
---|---|
List<ObjectDetection> |
detect(BufferedImage image,
String format)
Detects objects in a single
BufferedImage . |
List<ObjectDetection> |
detect(byte[] image)
Detects objects from a single input image encoded as byte array.
|
List<List<ObjectDetection>> |
detect(byte[][] batchedImages)
Uses detects objects from a batch of input images encoded as byte array.
|
List<ObjectDetection> |
detect(String imageUri)
Detects objects in a single input image identified by its URI.
|
public ObjectDetectionService()
public ObjectDetectionService(String modelUri, String labelsUri, float confidence, boolean withMasks, boolean cacheModel)
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.public ObjectDetectionService(ObjectDetectionInputConverter inputConverter, ObjectDetectionOutputConverter outputConverter, org.springframework.cloud.fn.common.tensorflow.deprecated.TensorFlowService tensorFlowService)
inputConverter
- Converter from byte array to object detection input image tensoroutputConverter
- Covets the object detection output tensors into ObjectDetection
listtensorFlowService
- Java tensorflow runner instancepublic List<ObjectDetection> detect(String imageUri)
imageUri
- input image's URIObjectDetection
domain objects representing detected objectspublic List<ObjectDetection> detect(BufferedImage image, String format)
BufferedImage
.image
- Input image to detect objects from.format
- Image format (e.g. jpg, png ...) to use when converting the buffer into byte array.ObjectDetection
domain objects representing detected objects in the input imagepublic List<ObjectDetection> detect(byte[] image)
image
- Input image encoded as byte arrayObjectDetection
domain objects representing detected objects in the input imagepublic List<List<ObjectDetection>> detect(byte[][] batchedImages)
batchedImages
- Batch of input images encoded as byte arrays. First dimension is the batch size and second the image bytes.ObjectDetection
domain objects representing detected objects in the input image.Copyright © 2020. All rights reserved.