| 131 | * The input tensor to run through the model. |
| 132 | */ |
| 133 | export function toInputTensor(input: DeepLabInput) { |
| 134 | return tf.tidy(() => { |
| 135 | const image = |
| 136 | input instanceof tf.Tensor ? input : tf.browser.fromPixels(input); |
| 137 | const [height, width] = image.shape; |
| 138 | const resizeRatio = config['CROP_SIZE'] / Math.max(width, height); |
| 139 | const targetHeight = Math.round(height * resizeRatio); |
| 140 | const targetWidth = Math.round(width * resizeRatio); |
| 141 | return tf.expandDims( |
| 142 | tf.image.resizeBilinear(image, [targetHeight, targetWidth])); |
| 143 | }); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * @param colormap :: `Color[]` |