Skip to main content
Version: 0.10.0

Function: useClassifier()

useClassifier<L>(config, options?): object

Defined in: hooks/useClassifier.ts:23

React hook to load and run an image classification model.

This hook manages downloading (if remote URLs are provided) and loading the model assets, compiling them, tracking download progress and load errors, and releasing native memory when the component unmounts or the configuration changes.

For imperative usage, see createClassifier.

Type Parameters​

L​

L

The type representing the classification labels.

Parameters​

config​

ClassifierModel<L>

The image classification model configuration. See ClassifierModel.

options?​

ResourceOptions

Load and caching options. See ResourceOptions.

Returns​

object

The same object as Classifier (without dispose), combined with loading state, download progress, and labels.

classify​

classify: (input, options?) => Promise<Classification<L>[]> | undefined = model.classify

classifyWorklet​

classifyWorklet: (input, options?) => Classification<L>[] | undefined = model.classifyWorklet

downloadProgress​

downloadProgress: number

error​

error: Error | undefined

isReady​

isReady: boolean = !!model

labels​

labels: readonly L[] = config.modelOpts.labels

resource​

resource: ClassifierModel<L> | undefined

See​

Classifier