public class ImageRecognition extends Object implements AutoCloseable
Constructor and Description |
---|
ImageRecognition(String modelUri,
String labelsUri,
int imageHeight,
int imageWidth,
float mean,
float scale,
String imageRecognitionGraphInputName,
String imageRecognitionGraphOutputName,
int responseSize,
boolean cacheModel)
Instead of creating the
ImageRecognition service explicitly via the constructor,
you should consider the convenience factory methods below. |
Modifier and Type | Method and Description |
---|---|
void |
close() |
static ImageRecognition |
inception(String inceptionModelUri,
int normalizedImageSize,
int responseSize,
boolean cacheModel)
The Inception graph uses "input" as input and "output" as output.
|
static ImageRecognition |
mobileNetV1(String mobileNetV1ModelUri,
int normalizedImageSize,
int responseSize,
boolean cacheModel)
Convenience for MobileNetV1 pre-trained models:
https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.md#pre-trained-models
The MobileNetV1 graph uses "input" as input and "MobilenetV1/Predictions/Reshape_1" as output.
|
static ImageRecognition |
mobileNetV2(String mobileNetV2ModelUri,
int normalizedImageSize,
int responseSize,
boolean cacheModel)
Convenience for MobileNetV2 pre-trained models:
https://github.com/tensorflow/models/tree/master/research/slim/nets/mobilenet#pretrained-models
The normalized image size is always square (e.g.
|
Map<String,Double> |
recognizeMax(byte[] inputImage)
Takes an byte encoded image and returns the most probable category recognized in the image along fromMemory its probability.
|
Map<String,Double> |
recognizeTopK(byte[] inputImage)
Takes an byte encoded input image and returns the top K most probable categories recognized in the image
along fromMemory their probabilities.
|
static List<RecognitionResponse> |
toRecognitionResponse(Map<String,Double> recognitionMap)
Convert image recognition results into
RecognitionResponse domain list. |
public ImageRecognition(String modelUri, String labelsUri, int imageHeight, int imageWidth, float mean, float scale, String imageRecognitionGraphInputName, String imageRecognitionGraphOutputName, int responseSize, boolean cacheModel)
ImageRecognition
service explicitly via the constructor,
you should consider the convenience factory methods below. E.g.
inception(String, int, int, boolean)
mobileNetV1(String, int, int, boolean)
mobileNetV2(String, int, int, boolean)
modelUri
- location of the pre-trained model to use.labelsUri
- location of the list fromMemory pre-trained categories used by the model.imageRecognitionGraphInputName
- name of the Model's input node to send the input image to.imageRecognitionGraphOutputName
- name of the Model's output node to retrieve the predictions from.imageHeight
- normalized image height.imageWidth
- normalized image width.mean
- mean value to normalize the input image.scale
- scale to normalize the input image.responseSize
- Max number of predictions per recognize.cacheModel
- if true the pre-trained model is cached on the local file system.public Map<String,Double> recognizeMax(byte[] inputImage)
inputImage
- Byte array encoded image to recognize.public Map<String,Double> recognizeTopK(byte[] inputImage)
inputImage
- Byte array encoded image to recognize.public static ImageRecognition inception(String inceptionModelUri, int normalizedImageSize, int responseSize, boolean cacheModel)
public static ImageRecognition mobileNetV2(String mobileNetV2ModelUri, int normalizedImageSize, int responseSize, boolean cacheModel)
mobileNetV2ModelUri
- model urinormalizedImageSize
- Depends on the pre-trained model used. Usually 224px is used.responseSize
- Number of responses fot topK requests.cacheModel
- cache modelpublic static ImageRecognition mobileNetV1(String mobileNetV1ModelUri, int normalizedImageSize, int responseSize, boolean cacheModel)
public static List<RecognitionResponse> toRecognitionResponse(Map<String,Double> recognitionMap)
RecognitionResponse
domain list.recognitionMap
- map containing the category mames and its probability. Returned by the
recognizeMax(byte[])
and the ImageRecognitionrecognizeTopK(byte[])
methodsRecognitionResponse
objects representing the name-to-probability pairs in the input map.public void close()
close
in interface AutoCloseable
Copyright © 2022. All rights reserved.