MCPcopy
hub / github.com/tensorflow/tfjs-models / segment

Method segment

deeplab/src/index.ts:182–206  ·  view source on GitHub ↗

* Segments an arbitrary image and generates a two-dimensional tensor with * class labels assigned to each cell of the grid overlayed on the image ( the * maximum number of cells on the side is fixed to 513). * * @param image :: `ImageData | HTMLImageElement | HTMLCanvasElement | * HTM

(input: DeepLabInput, config: PredictionConfig = {})

Source from the content-addressed store, hash-verified

180 */
181
182 public async segment(input: DeepLabInput, config: PredictionConfig = {}):
183 Promise<DeepLabOutput> {
184 if (!((config.colormap && config.labels) || this.base)) {
185 throw new Error(
186 `Calling the 'segment' method requires either the 'base'` +
187 ` attribute to be defined ` +
188 `(e.g. 'pascal', 'cityscapes' or'ade20k'),` +
189 ` or 'colormap' and 'labels' options to be set. ` +
190 `Aborting, since neither has been provided.`);
191 } else if (!(config.colormap && config.labels)) {
192 config.colormap = getColormap(this.base);
193 config.labels = getLabels(this.base);
194 }
195
196 const {colormap, labels, canvas} = config;
197 const rawSegmentationMap = tf.tidy(() => this.predict(input));
198
199 const [height, width] = rawSegmentationMap.shape;
200 const {legend, segmentationMap} =
201 await toSegmentationImage(colormap, labels, rawSegmentationMap, canvas);
202
203 tf.dispose(rawSegmentationMap);
204
205 return {legend, height, width, segmentationMap};
206 }
207
208 /**
209 * Dispose of the tensors allocated by the model.

Callers 4

predictMethod · 0.80
predictMethod · 0.80
deeplab_test.tsFile · 0.80
runPredictionFunction · 0.80

Calls 5

predictMethod · 0.95
getColormapFunction · 0.90
getLabelsFunction · 0.90
toSegmentationImageFunction · 0.90
disposeMethod · 0.65

Tested by

no test coverage detected