Skip to main content
Version: 0.10.0

Function: useObjectDetector()

useObjectDetector<F, L>(config, options?): object

Defined in: hooks/useObjectDetector.ts:28

React hook to load and run an object detection 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 createObjectDetector.

Type Parameters​

F​

F extends "xyxy" | "xywh" | "cxcywh"

The bounding box format.

L​

L

The type representing the object class labels.

Parameters​

config​

ObjectDetectorModel<F, L>

The object detection model configuration. See ObjectDetectorModel.

options?​

ResourceOptions

Load and caching options. See ResourceOptions.

Returns​

object

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

detectObjects​

detectObjects: (input, options?) => Promise<ObjectDetection<F, L>[]> | undefined = model.detectObjects

detectObjectsWorklet​

detectObjectsWorklet: (input, options?) => ObjectDetection<F, L>[] | undefined = model.detectObjectsWorklet

downloadProgress​

downloadProgress: number

error​

error: Error | undefined

isReady​

isReady: boolean = !!model

labels​

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

resource​

resource: ObjectDetectorModel<F, L> | undefined

See​

ObjectDetector