| 21 | import {Color, DeepLabInput, Label, Legend, ModelArchitecture, QuantizationBytes, SegmentationData} from './types'; |
| 22 | |
| 23 | export function createPascalColormap(): Color[] { |
| 24 | /** |
| 25 | * Generates the colormap matching the Pascal VOC dev guidelines. |
| 26 | * The original implementation in Python: https://git.io/fjgw5 |
| 27 | */ |
| 28 | |
| 29 | const pascalColormapMaxEntriesNum = config['DATASET_MAX_ENTRIES']['PASCAL']; |
| 30 | const colormap = new Array(pascalColormapMaxEntriesNum); |
| 31 | for (let idx = 0; idx < pascalColormapMaxEntriesNum; ++idx) { |
| 32 | colormap[idx] = new Array(3); |
| 33 | } |
| 34 | for (let shift = 7; shift > 4; --shift) { |
| 35 | const indexShift = 3 * (7 - shift); |
| 36 | for (let channel = 0; channel < 3; ++channel) { |
| 37 | for (let idx = 0; idx < pascalColormapMaxEntriesNum; ++idx) { |
| 38 | colormap[idx][channel] |= ((idx >> (channel + indexShift)) & 1) |
| 39 | << shift; |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | return colormap; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Returns |