tensorflow/lite/g3doc/api_docs/java/org/tensorflow/lite/task/vision/detector/ObjectDetector.html
public final class ObjectDetector
Performs object detection on images.
The API expects a TFLite model with TFLite Model Metadata..
The API supports models with one image input tensor and four output tensors. 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 tensors must be the 4 outputs of a DetectionPostProcess op, i.e:
Location tensor (kTfLiteFloat32):
[1 x num_results x 4], the inner array representing bounding boxes in the form [top, left, right, bottom].BoundingBoxProperties are required to be attached to the metadata and must specify type=BOUNDARIES and coordinate_type=RATIO.Classes tensor (kTfLiteFloat32):
tensor of size [1 x num_results], each value representing the integer index of a class.
if label maps are attached to the metadata as TENSOR_VALUE_LABELS associated files, they are used to convert the tensor values into labels.
scores tensor (kTfLiteFloat32):
tensor of size [1 x num_results], each value representing the score of the detected object.
Number of detection tensor (kTfLiteFloat32):
integer num_results as a tensor of size [1].
An example of such model can be found on TensorFlow Hub..
| class | ObjectDetector.ObjectDetectorOptions | Options for setting up an ObjectDetector. |
| static ObjectDetector |
createFromBuffer(ByteBuffer modelBuffer)
Creates an ObjectDetector instance with a model buffer and the default ObjectDetector.ObjectDetectorOptions.
|
| static ObjectDetector |
createFromBufferAndOptions(ByteBuffer modelBuffer, ObjectDetector.ObjectDetectorOptions options)
Creates an ObjectDetector instance with a model buffer and ObjectDetector.ObjectDetectorOptions.
|
| static ObjectDetector |
createFromFile(Context context, String modelPath)
Creates an ObjectDetector instance from the default ObjectDetector.ObjectDetectorOptions.
|
| static ObjectDetector |
createFromFile(File modelFile)
Creates an ObjectDetector instance from the default ObjectDetector.ObjectDetectorOptions.
|
| static ObjectDetector |
createFromFileAndOptions(Context context, String modelPath, ObjectDetector.ObjectDetectorOptions options)
Creates an ObjectDetector instance from ObjectDetector.ObjectDetectorOptions.
|
| static ObjectDetector |
createFromFileAndOptions(File modelFile, ObjectDetector.ObjectDetectorOptions options)
Creates an ObjectDetector instance from ObjectDetector.ObjectDetectorOptions.
|
| List<Detection> |
detect(MlImage image)
Performs actual detection on the provided MlImage.
| | List<Detection> | detect(TensorImage image, ImageProcessingOptions options) Performs actual detection on the provided image.
|
| List<Detection> |
detect(MlImage image, ImageProcessingOptions options)
Performs actual detection on the provided MlImage with ImageProcessingOptions.
| | List<Detection> | detect(TensorImage image) Performs actual detection on the provided image.
|
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() |
Creates an ObjectDetector instance with a model buffer and the default ObjectDetector.ObjectDetectorOptions.
| modelBuffer | a direct ByteBuffer or a MappedByteBuffer of the detection model |
| IllegalArgumentException | if the model buffer is not a direct ByteBuffer or a MappedByteBuffer * @throws IllegalStateException if there is an internal error |
| RuntimeException | if there is an otherwise unspecified error |
Creates an ObjectDetector instance with a model buffer and ObjectDetector.ObjectDetectorOptions.
| modelBuffer | a direct ByteBuffer or a MappedByteBuffer of the detection 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 ObjectDetector instance from the default ObjectDetector.ObjectDetectorOptions.
| context | | | modelPath | path to the detection 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 ObjectDetector instance from the default ObjectDetector.ObjectDetectorOptions.
| modelFile | the detection 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 ObjectDetector instance from ObjectDetector.ObjectDetectorOptions.
| context | | | modelPath | path to the detection 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 ObjectDetector instance from ObjectDetector.ObjectDetectorOptions.
| modelFile | the detection 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 |
Performs actual detection on the provided MlImage.
| image | an MlImage object that represents an image |
| IllegalStateException | if there is an internal error | | RuntimeException | if there is an otherwise unspecified error | | IllegalArgumentException | if the storage type or format of the image is unsupported |
Performs actual detection on the provided image.
ObjectDetector supports the following TensorImage color space types:
ColorSpaceType.RGBColorSpaceType.NV12ColorSpaceType.NV21ColorSpaceType.YV12ColorSpaceType.YV21ObjectDetector supports the following options:
ImageProcessingOptions.Builder.setOrientation(ImageProcessingOptions.Orientation)). It defaults to ImageProcessingOptions.Orientation.TOP_LEFT.| image | a UINT8 TensorImage object that represents an RGB or YUV image |
| options | the options to configure how to preprocess the image |
| IllegalStateException | if there is an internal error | | RuntimeException | if there is an otherwise unspecified error | | IllegalArgumentException | if the color space type of image is unsupported |
Performs actual detection on the provided MlImage with ImageProcessingOptions.
ObjectDetector supports the following options:
ImageProcessingOptions.Builder.setOrientation(ImageProcessingOptions.Orientation)). It defaults to ImageProcessingOptions.Orientation.TOP_LEFT. MlImage.getRotation() is not effective.| image | an MlImage object that represents an image |
| options | the options to configure how to preprocess the image |
| IllegalStateException | if there is an internal error | | RuntimeException | if there is an otherwise unspecified error | | IllegalArgumentException | if the storage type or format of the image is unsupported |
Performs actual detection on the provided image.
ObjectDetector 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 |
| IllegalStateException | if there is an internal error | | RuntimeException | if there is an otherwise unspecified error | | IllegalArgumentException | if the color space type of image is unsupported |