ImageClassifier.ImageClassifierOptions.Builder

public abstract class ImageClassifier.ImageClassifierOptions.Builder

Builder for ImageClassifierOptions.

Summary

Public constructors

Public methods

final ImageClassifier.ImageClassifierOptions

Validates and builds the ImageClassifierOptions instance. *

abstract ImageClassifier.ImageClassifierOptions.Builder

Sets the BaseOptions for the image classifier task.

abstract ImageClassifier.ImageClassifierOptions.Builder
setCategoryAllowlist(List<String> categoryAllowlist)

Sets the optional allowlist of category names.

abstract ImageClassifier.ImageClassifierOptions.Builder
setCategoryDenylist(List<String> categoryDenylist)

Sets the optional denylist of category names.

abstract ImageClassifier.ImageClassifierOptions.Builder

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

abstract ImageClassifier.ImageClassifierOptions.Builder

Sets an optional ErrorListener.

abstract ImageClassifier.ImageClassifierOptions.Builder
setMaxResults(Integer maxResults)

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

abstract ImageClassifier.ImageClassifierOptions.Builder

Sets the ResultListener to receive the classification results asynchronously when the image classifier is in the live stream mode.

abstract ImageClassifier.ImageClassifierOptions.Builder

Sets the RunningMode for the image classifier task.

abstract ImageClassifier.ImageClassifierOptions.Builder
setScoreThreshold(Float scoreThreshold)

Sets the optional score threshold.

Public constructors

Builder

public Builder()

Public methods

build

public final ImageClassifier.ImageClassifierOptions build()

Validates and builds the ImageClassifierOptions instance. *

Throws
java.lang.IllegalArgumentException

if any of the set options are invalid.

setBaseOptions

public abstract ImageClassifier.ImageClassifierOptions.Builder setBaseOptions(BaseOptions baseOptions)

Sets the BaseOptions for the image classifier task.

setCategoryAllowlist

public abstract ImageClassifier.ImageClassifierOptions.Builder setCategoryAllowlist(List<String> categoryAllowlist)

Sets the optional allowlist of category names.

If non-empty, detection results whose category name is not in this set will be filtered out. Duplicate or unknown category names are ignored. Mutually exclusive with categoryDenylist.

setCategoryDenylist

public abstract ImageClassifier.ImageClassifierOptions.Builder setCategoryDenylist(List<String> categoryDenylist)

Sets the optional denylist of category names.

If non-empty, detection results whose category name is in this set will be filtered out. Duplicate or unknown category names are ignored. Mutually exclusive with categoryAllowlist.

setDisplayNamesLocale

public abstract ImageClassifier.ImageClassifierOptions.Builder setDisplayNamesLocale(String locale)

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

setErrorListener

public abstract ImageClassifier.ImageClassifierOptions.Builder setErrorListener(ErrorListener errorListener)

Sets an optional ErrorListener.

setMaxResults

public abstract ImageClassifier.ImageClassifierOptions.Builder setMaxResults(Integer maxResults)

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

If not set, all available results are returned. If set, must be >0.

setResultListener

public abstract ImageClassifier.ImageClassifierOptions.Builder setResultListener(
    OutputHandler.ResultListener<ImageClassifierResult, MPImage> resultListener
)

Sets the ResultListener to receive the classification results asynchronously when the image classifier is in the live stream mode.

setRunningMode

public abstract ImageClassifier.ImageClassifierOptions.Builder setRunningMode(RunningMode runningMode)

Sets the RunningMode for the image classifier task. Default to the image mode. Image classifier has three modes:

  • IMAGE: The mode for performing classification on single image inputs.
  • VIDEO: The mode for performing classification on the decoded frames of a video.
  • LIVE_STREAM: The mode for for performing classification on a live stream of input data, such as from camera. In this mode, setResultListener must be called to set up a listener to receive the classification results asynchronously.

setScoreThreshold

public abstract ImageClassifier.ImageClassifierOptions.Builder setScoreThreshold(Float scoreThreshold)

Sets the optional score threshold. Results with score below this value are rejected.

Overrides the score threshold specified in the TFLite Model Metadata, if any.