Class ImageRecognition
java.lang.Object
org.springframework.cloud.fn.image.recognition.ImageRecognition
- All Implemented Interfaces:
AutoCloseable
- Author:
- Christian Tzolov
-
Constructor Summary
ConstructorDescriptionImageRecognition
(String modelUri, String labelsUri, int imageHeight, int imageWidth, float mean, float scale, String imageRecognitionGraphInputName, String imageRecognitionGraphOutputName, int responseSize, boolean cacheModel) Instead of creating theImageRecognition
service explicitly via the constructor, you should consider the convenience factory methods below. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static ImageRecognition
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.recognizeMax
(byte[] inputImage) Takes an byte encoded image and returns the most probable category recognized in the image along fromMemory its probability.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 intoRecognitionResponse
domain list.
-
Constructor Details
-
ImageRecognition
public ImageRecognition(String modelUri, String labelsUri, int imageHeight, int imageWidth, float mean, float scale, String imageRecognitionGraphInputName, String imageRecognitionGraphOutputName, int responseSize, boolean cacheModel) Instead of creating theImageRecognition
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)
- Parameters:
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.
-
-
Method Details
-
recognizeMax
Takes an byte encoded image and returns the most probable category recognized in the image along fromMemory its probability.- Parameters:
inputImage
- Byte array encoded image to recognize.- Returns:
- Returns a single map entry containing the names of the recognized categories as key and the confidence as value.
-
recognizeTopK
Takes an byte encoded input image and returns the top K most probable categories recognized in the image along fromMemory their probabilities.- Parameters:
inputImage
- Byte array encoded image to recognize.- Returns:
- Returns a list of key-value pairs. Every key-value pair represents a single category recognized. The key stands for the name(s) of the category while the value states the confidence that there is an object of this category. The entries in the Map are ordered from the higher to the lower confidences.
-
inception
public static ImageRecognition inception(String inceptionModelUri, int normalizedImageSize, int responseSize, boolean cacheModel) The Inception graph uses "input" as input and "output" as output. -
mobileNetV2
public 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. H=W) The MobileNetV2 graph uses "input" as input and "MobilenetV2/Predictions/Reshape_1" as output.- Parameters:
mobileNetV2ModelUri
- model urinormalizedImageSize
- Depends on the pre-trained model used. Usually 224px is used.responseSize
- Number of responses fot topK requests.cacheModel
- cache model- Returns:
- ImageRecognition instance configured fromMemory a MobileNetV2 pre-trained model.
-
mobileNetV1
public 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. -
toRecognitionResponse
Convert image recognition results intoRecognitionResponse
domain list.- Parameters:
recognitionMap
- map containing the category mames and its probability. Returned by therecognizeMax(byte[])
and the ImageRecognitionrecognizeTopK(byte[])
methods- Returns:
- List of
RecognitionResponse
objects representing the name-to-probability pairs in the input map.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
-