* 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 = {})
| 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. |
no test coverage detected