Skip to main content
Version: 0.9.x

Function: selectByText()

Call Signature​

selectByText<L>(instances, instanceEmbeddings, textEmbedding, topk?): SegmentedInstance<L> | null

Defined in: utils/segmentAnythingPrompts.ts:105

Selects the best matching instance(s) for a text prompt.

Returns the instance(s) whose image embedding has the highest cosine similarity with the text embedding. The caller is responsible for producing the embeddings (e.g. with CLIP) and passing them in the same order as instances.

Type Parameters​

L​

L extends Readonly<Record<string, string | number>>

Parameters​

instances​

SegmentedInstance<L>[]

Array of segmented instances returned by forward().

instanceEmbeddings​

Float32Array<ArrayBufferLike>[]

Image embedding for each instance, in the same order as instances.

textEmbedding​

Float32Array

Embedding of the text prompt.

topk?​

1

Number of top matches to return (defaults to 1).

Returns​

SegmentedInstance<L> | null

The best matching instance (or null) if topk is 1, otherwise an array of the topk matching instances.

Call Signature​

selectByText<L>(instances, instanceEmbeddings, textEmbedding, topk): SegmentedInstance<L>[]

Defined in: utils/segmentAnythingPrompts.ts:111

Selects the best matching instance(s) for a text prompt.

Returns the instance(s) whose image embedding has the highest cosine similarity with the text embedding. The caller is responsible for producing the embeddings (e.g. with CLIP) and passing them in the same order as instances.

Type Parameters​

L​

L extends Readonly<Record<string, string | number>>

Parameters​

instances​

SegmentedInstance<L>[]

Array of segmented instances returned by forward().

instanceEmbeddings​

Float32Array<ArrayBufferLike>[]

Image embedding for each instance, in the same order as instances.

textEmbedding​

Float32Array

Embedding of the text prompt.

topk​

number

Number of top matches to return (defaults to 1).

Returns​

SegmentedInstance<L>[]

The best matching instance (or null) if topk is 1, otherwise an array of the topk matching instances.