tensorflow/lite/g3doc/api_docs/java/org/tensorflow/lite/task/vision/classifier/ImageClassifier.html
public final class ImageClassifier
Performs classification on images.
The API expects a TFLite model with optional, but strongly recommended, TFLite Model Metadata..
The API supports models with one image input tensor and one classification output tensor. To be more specific, here are the requirements.
Input image tensor (kTfLiteUInt8/kTfLiteFloat32)
[batch x height x width x channels].batch is required to be 1).channels is required to be 3).kTfLiteFloat32, NormalizationOptions are required to be attached to the metadata for input normalization.Output score tensor (kTfLiteUInt8/kTfLiteFloat32)
with N classes of either 2 or 4 dimensions, such as [1 x N] or [1 x 1 x 1 x N]
the label file is required to be packed to the metadata. See the example of creating metadata for an image classifier. If no label files are packed, it will use index as label in the result.
An example of such model can be found on TensorFlow Hub..
| class | ImageClassifier.ImageClassifierOptions | Options for setting up an ImageClassifier. |
| List<Classifications> |
classify(TensorImage image)
Performs actual classification on the provided TensorImage.
|
| List<Classifications> |
classify(TensorImage image, ImageProcessingOptions options)
Performs actual classification on the provided TensorImage with ImageProcessingOptions.
|
| List<Classifications> |
classify(MlImage image)
Performs actual classification on the provided MlImage.
|
| List<Classifications> |
classify(MlImage image, ImageProcessingOptions options)
Performs actual classification on the provided MlImage with ImageProcessingOptions.
|
| static ImageClassifier |
createFromBuffer(ByteBuffer modelBuffer)
Creates an ImageClassifier instance with a model buffer and the default ImageClassifier.ImageClassifierOptions.
|
| static ImageClassifier |
createFromBufferAndOptions(ByteBuffer modelBuffer, ImageClassifier.ImageClassifierOptions options)
Creates an ImageClassifier instance with a model buffer and ImageClassifier.ImageClassifierOptions.
|
| static ImageClassifier |
createFromFile(Context context, String modelPath)
Creates an ImageClassifier instance from the default ImageClassifier.ImageClassifierOptions.
|
| static ImageClassifier |
createFromFile(File modelFile)
Creates an ImageClassifier instance from the default ImageClassifier.ImageClassifierOptions.
|
| static ImageClassifier |
createFromFileAndOptions(Context context, String modelPath, ImageClassifier.ImageClassifierOptions options)
Creates an ImageClassifier instance from ImageClassifier.ImageClassifierOptions.
|
| static ImageClassifier |
createFromFileAndOptions(File modelFile, ImageClassifier.ImageClassifierOptions options)
Creates an ImageClassifier instance.
|
From class org.tensorflow.lite.task.core.BaseTaskApi
| synchronized void | close() Release the memory allocated from C++ and deregister the library from the static holder.
| | long | getNativeHandle() | | boolean | isClosed() |
From class java.lang.Object
| boolean | equals(Object arg0) | | final Class<?> | getClass() | | int | hashCode() | | final void | notify() | | final void | notifyAll() | | String | toString() | | final void | wait(long arg0, int arg1) | | final void | wait(long arg0) | | final void | wait() |
From interface java.io.Closeable
| abstract void | close() |
From interface java.lang.AutoCloseable
| abstract void | close() |
Performs actual classification on the provided TensorImage.
ImageClassifier supports the following TensorImage color space types:
ColorSpaceType.RGBColorSpaceType.NV12ColorSpaceType.NV21ColorSpaceType.YV12ColorSpaceType.YV21| image | a UINT8 TensorImage object that represents an RGB or YUV image |
| IllegalArgumentException | if the color space type of image is unsupported |
Performs actual classification on the provided TensorImage with ImageProcessingOptions.
ImageClassifier supports the following options:
ImageProcessingOptions.Builder.setRoi(Rect)). It defaults to the entire image.ImageProcessingOptions.Builder.setOrientation(ImageProcessingOptions.Orientation)). It defaults to ImageProcessingOptions.Orientation.TOP_LEFT.ImageClassifier supports the following TensorImage color space types:
ColorSpaceType.RGBColorSpaceType.NV12ColorSpaceType.NV21ColorSpaceType.YV12ColorSpaceType.YV21| image | a UINT8 TensorImage object that represents an RGB or YUV image |
| options | |
| IllegalArgumentException | if the color space type of image is unsupported |
Performs actual classification on the provided MlImage.
| image | an MlImage object that represents an image |
| IllegalArgumentException | if the storage type or format of the image is unsupported |
Performs actual classification on the provided MlImage with ImageProcessingOptions.
ImageClassifier supports the following options:
ImageProcessingOptions.Builder.setRoi(Rect)). It defaults to the entire image.ImageProcessingOptions.Builder.setOrientation(ImageProcessingOptions.Orientation)). It defaults to ImageProcessingOptions.Orientation.TOP_LEFT. MlImage.getRotation() is not effective.| image | a MlImage object that represents an image |
| options | configures options including ROI and rotation |
| IllegalArgumentException | if the storage type or format of the image is unsupported |
Creates an ImageClassifier instance with a model buffer and the default ImageClassifier.ImageClassifierOptions.
| modelBuffer | a direct ByteBuffer or a MappedByteBuffer of the classification model |
| IllegalArgumentException | if the model buffer is not a direct ByteBuffer or a MappedByteBuffer |
| IllegalStateException | if there is an internal error |
| RuntimeException | if there is an otherwise unspecified error |
Creates an ImageClassifier instance with a model buffer and ImageClassifier.ImageClassifierOptions.
| modelBuffer | a direct ByteBuffer or a MappedByteBuffer of the classification model |
| options | |
| IllegalArgumentException | if the model buffer is not a direct ByteBuffer or a MappedByteBuffer |
| IllegalStateException | if there is an internal error |
| RuntimeException | if there is an otherwise unspecified error |
Creates an ImageClassifier instance from the default ImageClassifier.ImageClassifierOptions.
| context | | | modelPath | path of the classification model with metadata in the assets |
| IOException | if an I/O error occurs when loading the tflite model | | IllegalArgumentException | if an argument is invalid | | IllegalStateException | if there is an internal error | | RuntimeException | if there is an otherwise unspecified error |
Creates an ImageClassifier instance from the default ImageClassifier.ImageClassifierOptions.
| modelFile | the classification model File instance |
| IOException | if an I/O error occurs when loading the tflite model | | IllegalArgumentException | if an argument is invalid | | IllegalStateException | if there is an internal error | | RuntimeException | if there is an otherwise unspecified error |
Creates an ImageClassifier instance from ImageClassifier.ImageClassifierOptions.
| context | | | modelPath | path of the classification model with metadata in the assets | | options | |
| IOException | if an I/O error occurs when loading the tflite model | | IllegalArgumentException | if an argument is invalid | | IllegalStateException | if there is an internal error | | RuntimeException | if there is an otherwise unspecified error |
Creates an ImageClassifier instance.
| modelFile | the classification model File instance |
| options | |
| IOException | if an I/O error occurs when loading the tflite model | | IllegalArgumentException | if an argument is invalid | | IllegalStateException | if there is an internal error | | RuntimeException | if there is an otherwise unspecified error |