ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more

ObjectDetector.ObjectDetectorOptions.Builder

public static class ObjectDetector.ObjectDetectorOptions.Builder

A builder that helps to configure an instance of ObjectDetectorOptions.

Public Methods

ObjectDetector.ObjectDetectorOptions
build()
ObjectDetector.ObjectDetectorOptions.Builder
setBaseOptions(BaseOptions baseOptions)
Sets the general options to configure Task APIs, such as accelerators.
ObjectDetector.ObjectDetectorOptions.Builder
setDisplayNamesLocale(String displayNamesLocale)
Sets the locale to use for display names specified through the TFLite Model Metadata, if any.
ObjectDetector.ObjectDetectorOptions.Builder
setLabelAllowList(List<String> labelAllowList)
Sets the optional allow list of labels.
ObjectDetector.ObjectDetectorOptions.Builder
setLabelDenyList(List<String> labelDenyList)
Sets the optional deny list of labels.
ObjectDetector.ObjectDetectorOptions.Builder
setMaxResults(int maxResults)
Sets the maximum number of top-scored detection results to return.
ObjectDetector.ObjectDetectorOptions.Builder
setNumThreads(int numThreads)
This method was deprecated in API level . use BaseOptions to configure number of threads instead. This method will override the number of threads configured from BaseOptions.
ObjectDetector.ObjectDetectorOptions.Builder
setScoreThreshold(float scoreThreshold)
Sets the score threshold that overrides the one provided in the model metadata (if any).

Inherited Methods

Public Methods

public ObjectDetector.ObjectDetectorOptions.Builder setBaseOptions (BaseOptions baseOptions)

Sets the general options to configure Task APIs, such as accelerators.

Parameters
baseOptions

public ObjectDetector.ObjectDetectorOptions.Builder setDisplayNamesLocale (String displayNamesLocale)

Sets the locale to use for display names specified through the TFLite Model Metadata, if any.

Defaults to English("en"). See the TFLite Metadata schema file. for the accepted pattern of locale.

Parameters
displayNamesLocale

public ObjectDetector.ObjectDetectorOptions.Builder setLabelAllowList (List<String> labelAllowList)

Sets the optional allow list of labels.

If non-empty, detection results whose label is not in this set will be filtered out. Duplicate or unknown labels are ignored. Mutually exclusive with labelDenyList. It will cause IllegalStateException when calling ObjectDetector.createFromFileAndOptions(Context, String, ObjectDetector.ObjectDetectorOptions), if both labelDenyList and labelAllowList are set.

Parameters
labelAllowList

public ObjectDetector.ObjectDetectorOptions.Builder setLabelDenyList (List<String> labelDenyList)

Sets the optional deny list of labels.

If non-empty, detection results whose label is in this set will be filtered out. Duplicate or unknown labels are ignored. Mutually exclusive with labelAllowList. It will cause IllegalStateException when calling ObjectDetector.createFromFileAndOptions(Context, String, ObjectDetector.ObjectDetectorOptions), if both labelDenyList and labelAllowList are set.

Parameters
labelDenyList

public ObjectDetector.ObjectDetectorOptions.Builder setMaxResults (int maxResults)

Sets the maximum number of top-scored detection results to return.

If < 0, all available results will be returned. If 0, an invalid argument error is returned. Note that models may intrinsically be limited to returning a maximum number of results N: if the provided value here is above N, only N results will be returned. Defaults to -1.

Parameters
maxResults
Throws
IllegalArgumentException if maxResults is 0.

public ObjectDetector.ObjectDetectorOptions.Builder setNumThreads (int numThreads)

This method was deprecated in API level .
use BaseOptions to configure number of threads instead. This method will override the number of threads configured from BaseOptions.

Sets the number of threads to be used for TFLite ops that support multi-threading when running inference with CPU. Defaults to -1.

numThreads should be greater than 0 or equal to -1. Setting numThreads to -1 has the effect to let TFLite runtime set the value.

Parameters
numThreads

public ObjectDetector.ObjectDetectorOptions.Builder setScoreThreshold (float scoreThreshold)

Sets the score threshold that overrides the one provided in the model metadata (if any). Results below this value are rejected.

Parameters
scoreThreshold