Skip to content

Search

Tagger

ClassTagging Source

Tags images with a TaggingBackend, asking about each category in a Vocabulary. The model can only answer with values you define. Create one and reuse it.

class Tagger

Example

const tagger = new Tagger({
backend: new AmosBackend(),
vocabulary: {
setting: { type: "multi", values: { beach: null, mountains: null, city: null } },
night: { type: "flag", question: "Was the photo taken at night?" },
},
});
const result = await tagger.tag({
image: { data: await readFile("getxo.jpg"), mimeType: "image/jpeg" },
context: "Lead photo for a travel guide to Getxo, Spain.",
});
result.labels; // ["setting:beach", "setting:city"]

Constructor

new Tagger(options: TaggerOptions)

Checks the vocabulary. Throws a TaggingError with code invalid-configuration if it's invalid.

Parameters

optionsrequiredTaggerOptions

Methods

tag()

tag(request: TaggingRequest): Promise<TaggingResult>

Tags one image. Throws a TaggingError when the image or request is invalid, the backend fails, or its answers don't match the questions.

Parameters

requestrequiredTaggingRequest

ReturnsPromise<TaggingResult>

evaluate()

evaluate(records: Iterable<DecisionRecord>): Evaluation

Scores saved records against their expected answers, applying this tagger's thresholds to the recorded probabilities. Nothing is sent to the backend.

Parameters

recordsrequiredIterable<DecisionRecord>

ReturnsEvaluation

image-tagger is a Ben Hodgson projectGitHub