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.
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.kTfLiteUInt8
/kTfLiteFloat32
)
N
classes of either 2 or 4 dimensions, such as [1 x
N]
or [1 x 1 x 1 x N]
An example of such model can be found on TensorFlow Hub..
class | ImageClassifier.ImageClassifierOptions | Options for setting up an ImageClassifier. |
void |
deinit(long nativeHandle)
|
Performs actual classification on the provided TensorImage
.
ImageClassifier
supports the following TensorImage
color space types:
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:
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
.
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 the default
ImageClassifier.ImageClassifierOptions
.
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 |
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 |