Thanks for tuning in to Google I/O. View all sessions on demand
Watch on demand
ObjectDetector
Stay organized with collections
Save and categorize content based on your preferences.
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
)
- image input of size
[batch x height x width x channels]
.
- batch inference is not supported (
batch
is required to be 1).
- only RGB inputs are supported (
channels
is required to be 3).
- if type is
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
):
- tensor of size
[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..
Inherited Methods
From class
java.lang.Object
boolean
|
|
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
From interface
java.lang.AutoCloseable
Public Methods
public
static
ObjectDetector
createFromFile
(Context context, String modelPath)
Parameters
context |
|
modelPath |
path to the detection model with metadata in the assets |
public
static
ObjectDetector
createFromFile
(File modelFile)
Parameters
modelFile |
the detection model File instance |
Parameters
context |
|
modelPath |
path to the detection model with metadata in the assets |
options |
|
Parameters
modelFile |
the detection model File instance |
options |
|
Performs actual detection on the provided MlImage
.
Parameters
image |
an MlImage object that represents an image |
Parameters
image |
a UINT8 TensorImage object that represents an RGB or YUV image |
options |
the options to configure how to preprocess the image |
Parameters
image |
an MlImage object that represents an image |
options |
the options to configure how to preprocess the image |
Parameters
image |
a UINT8 TensorImage object that represents an RGB or YUV image |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2021-10-08 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]