I'm messing with Semantic Image Segmentation from google's DeepLab . I want to be able change colors for each semantic ( i.e. person , cat etc) . The method that creates the colormap , with PASCAL benchmark is
def create_pascal_label_colormap():
"""Creates a label colormap used in PASCAL VOC segmentation benchmark.
Returns:
A Colormap for visualizing segmentation results.
"""
colormap = np.zeros((256, 3), dtype=int)
ind = np.arange(256, dtype=int)
for shift in reversed(range(8)):
for channel in range(3):
colormap[:, channel] |= ((ind >> channel) & 1) << shift
ind >>= 3
return colormap
I guess if I change the value of ind
with another (instead of 2
to have 3
) I get different colors. Also , is there another way to get different colors for the semantics ? I just can't seem to guess how that works , how the colormap is created , using shifting as we see in the code . I'm linking also the full code I'm working on from DeepLab,on google colab :
https://colab.research.google.com/drive/1a3TnfeEjVMg7N1Dz5d_UA8GN_iKHkG_l#scrollTo=na9DyxVl4_Ul
If you have a fixed number of classes you could also just hard-code the colors you'd like to have, something like
def create_pascal_label_colormap():
return np.asarray([
[0, 0, 0],
[0, 192, 0],
])