/** * @license * Copyright 2019 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ import * as tfconv from '@tensorflow/tfjs-converter'; import * as tf from '@tensorflow/tfjs-core'; import {DeepLabInput, DeepLabOutput, ModelArchitecture, ModelConfig, PredictionConfig} from './types'; import {getColormap, getLabels, getURL, toInputTensor, toSegmentationImage} from './utils'; export {version} from './version'; export { getColormap, getLabels, getURL, ModelConfig, PredictionConfig, toSegmentationImage }; /** * Initializes the DeepLab model and returns a `SemanticSegmentation` object. * * @param input :: * `ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement` * * The input image to feed through the network. * * @param config :: `ModelConfig` * * The configuration for the model with any of the following attributes: * * * quantizationBytes (optional) :: `QuantizationBytes` * * The degree to which weights are quantized (either 1, 2 or 4). * Setting this attribute to 1 or 2 will load the model with int32 and * float32 compressed to 1 or 2 bytes respectively. * Set it to 4 to disable quantization. * * * base (optional) :: `ModelArchitecture` * * The type of model to load (either `pascal`, `cityscapes` or `ade20k`). * * * modelUrl (optional) :: `string` * * The URL from which to load the TF.js GraphModel JSON. * Inferred from `base` and `quantizationBytes` if undefined. * * @return The initialized `SemanticSegmentation` object */ export async function load( modelConfig: ModelConfig = { base: 'pascal', quantizationBytes: 2 }, ) { if (tf == null) { throw new Error( `Cannot find TensorFlow.js.` + ` If you are using a