MCPcopy Create free account
hub / github.com/tensorflow/tfjs / classify

Method classify

tfjs-automl/src/img_classification.ts:42–55  ·  view source on GitHub ↗
(input: ImageInput, options?: ImageClassificationOptions)

Source from the content-addressed store, hash-verified

40 constructor(public graphModel: GraphModel, public dictionary: string[]) {}
41
42 async classify(input: ImageInput, options?: ImageClassificationOptions):
43 Promise<ImagePrediction[]> {
44 options = sanitizeOptions(options);
45
46 const scores = tidy(() => {
47 const preprocessedImg = this.preprocess(input, options);
48 return this.graphModel.predict(preprocessedImg) as Tensor;
49 });
50 const probabilities = await scores.data() as Float32Array;
51 scores.dispose();
52 const result = Array.from(probabilities)
53 .map((prob, i) => ({label: this.dictionary[i], prob}));
54 return result;
55 }
56
57 private preprocess(input: ImageInput, options: ImageClassificationOptions) {
58 // Preprocessing involves center crop and normalizing between [-1, 1].

Callers

nothing calls this directly

Calls 6

preprocessMethod · 0.95
tidyFunction · 0.90
sanitizeOptionsFunction · 0.70
predictMethod · 0.65
dataMethod · 0.65
disposeMethod · 0.45

Tested by

no test coverage detected