Skip to main content
Version: Next

Function: useInstanceSegmentation()

useInstanceSegmentation<C>(props): InstanceSegmentationType<InstanceSegmentationLabels<C["modelName"]>>

Defined in: hooks/computer_vision/useInstanceSegmentation.ts:38

React hook for managing an Instance Segmentation model instance.

Type Parameters

C

C extends InstanceSegmentationModelSources

A InstanceSegmentationModelSources config specifying which model to load.

Parameters

props

InstanceSegmentationProps<C>

Configuration object containing model config and optional preventLoad flag.

Returns

InstanceSegmentationType<InstanceSegmentationLabels<C["modelName"]>>

An object with model state (error, isReady, isGenerating, downloadProgress) and a typed forward function.

Example

const { isReady, isGenerating, forward, error, downloadProgress } =
useInstanceSegmentation({
model: {
modelName: 'yolo26n-seg',
modelSource: 'https://huggingface.co/.../yolo26n-seg.pte',
},
});

if (!isReady) {
return <Text>Loading: {(downloadProgress * 100).toFixed(0)}%</Text>;
}

const results = await forward('path/to/image.jpg', {
confidenceThreshold: 0.5,
inputSize: 640,
});