| 220 | |
| 221 | |
| 222 | def labelcolormap(N): |
| 223 | if N == 35: # cityscape |
| 224 | cmap = np.array([(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (111, 74, 0), (81, 0, 81), |
| 225 | (128, 64, 128), (244, 35, 232), (250, 170, 160), (230, 150, 140), (70, 70, 70), (102, 102, 156), (190, 153, 153), |
| 226 | (180, 165, 180), (150, 100, 100), (150, 120, 90), (153, 153, 153), (153, 153, 153), (250, 170, 30), (220, 220, 0), |
| 227 | (107, 142, 35), (152, 251, 152), (70, 130, 180), (220, 20, 60), (255, 0, 0), (0, 0, 142), (0, 0, 70), |
| 228 | (0, 60, 100), (0, 0, 90), (0, 0, 110), (0, 80, 100), (0, 0, 230), (119, 11, 32), (0, 0, 142)], |
| 229 | dtype=np.uint8) |
| 230 | else: |
| 231 | cmap = np.zeros((N, 3), dtype=np.uint8) |
| 232 | for i in range(N): |
| 233 | r, g, b = 0, 0, 0 |
| 234 | id = i + 1 # let's give 0 a color |
| 235 | for j in range(7): |
| 236 | str_id = uint82bin(id) |
| 237 | r = r ^ (np.uint8(str_id[-1]) << (7 - j)) |
| 238 | g = g ^ (np.uint8(str_id[-2]) << (7 - j)) |
| 239 | b = b ^ (np.uint8(str_id[-3]) << (7 - j)) |
| 240 | id = id >> 3 |
| 241 | cmap[i, 0] = r |
| 242 | cmap[i, 1] = g |
| 243 | cmap[i, 2] = b |
| 244 | |
| 245 | if N == 182: # COCO |
| 246 | important_colors = { |
| 247 | 'sea': (54, 62, 167), |
| 248 | 'sky-other': (95, 219, 255), |
| 249 | 'tree': (140, 104, 47), |
| 250 | 'clouds': (170, 170, 170), |
| 251 | 'grass': (29, 195, 49) |
| 252 | } |
| 253 | for i in range(N): |
| 254 | name = util.coco.id2label(i) |
| 255 | if name in important_colors: |
| 256 | color = important_colors[name] |
| 257 | cmap[i] = np.array(list(color)) |
| 258 | |
| 259 | return cmap |
| 260 | |
| 261 | |
| 262 | class Colorize(object): |