C4W3 - UNet Assignment - color palette

Enjoy!
palette

2 Likes

Thanks for giving us this guide to the colors they use for the labels here.

@Francis60 that is interesting and I think the code you used to pull this would be fair to share-- But I am left wondering a little what is the distinction between ‘None’ and ‘Any’ ? That seems a little weird…

*Or even ‘Other’ for that matter…

Hello,

CARLA would say something subtle, I suppose:
Any: I see something but I can’t tell which class it belongs to.
None: I don’t see anything

  1. Get a list of color classes from first channel thru all the masks:

All classes from 1 to 22 an are used.
Note the Python nonsense ordered set.

  1. Find the previous version list on stackoverflow or CARLA site.

Here they used ‘Any’ class for personalized object category in C code.
23_classes_objectlabel_tag
The latest version includes many more classes, such as different types of vehicle.

  1. The code :

colors = [‘None’, ‘Buildings’, ‘Fences’, ‘Other’,‘Pedestrians’, ‘Poles’, ‘RoadLines’,
‘Roads’, ‘Sidewalks’, ‘Vegetation’, ‘Vehicles’, ‘Walls’, ‘TrafficSigns’, ‘Sky’,
‘Ground’, ‘Bridge’, ‘RailTrack’, ‘GuardRail’, ‘TrafficLight’,
‘Static’, ‘Dynamic’, ‘Water’, ‘Terrain’, ‘Any’]

fig, arr = plt.subplots(5, 5, figsize=(6, 4))
for c, ax in enumerate(arr.flat):
if c != 0 and c < len(colors)-1:
name = colors[c]
area = np.full((1, 2), c, dtype=np.uint8)
ax.imshow(area, vmin=1, vmax=22) # specify range !
ax.set_title(name, fontsize=12)
ax.axis(‘off’)
elif c != len(colors):
name = colors[c]
area = np.full((1, 2, 1), 1, dtype=np.uint8) * [122, 122, 122] # grey
ax.imshow(area)
ax.set_title(name, fontsize=12)
ax.axis(‘off’)
else:
ax.axis(‘off’) # empty cell

plt.tight_layout()

# Save the plot to a file (e.g., PNG)
plt.savefig(‘palette.png’)

plt.show()

1 Like

Unfortunately I was not able to adapt the display() function given in the Lab to actually use the exact range of colors, resulting in a wrong mapping of colors. :slightly_frowning_face:

defauft “viridis” cmap parameter used in plt.imshow().
viridis_color_map

Still the mapping is correct as soon as you have “Buildings” and “Terrain” pixels into the mask

Here you go!

def display(display_list):
plt.figure(figsize=(15, 15))

title = ['Input Image', 'True Mask', 'Predicted Mask']

for i in range(len(display_list)):
    plt.subplot(1, len(display_list), i+1)
    plt.title(title[i])
    if i == 0:
        plt.imshow(tf.keras.preprocessing.image.array_to_img(display_list[i]))
    else:
        mask = display_list[i]
        mask = tf.math.reduce_max(mask, axis=-1, keepdims=True)
        plt.imshow(mask[:, :, 0], cmap=cmap, vmin=1, vmax=22)

    plt.axis('off')
    
plt.show()
1 Like

With ‘rainbow’ palette:

1 Like