Is there a script for converting the labels into grayscale as required by Caffe?
asheeshr opened this issue · comments
In the Readme, it is mentioned that:
Data
Our example models are trained on the ISPRS Vaihingen dataset. We use the IRRG tiles (8bit format). The ground truth files are color-encoded and should be converted to the numerical labels, e.g. {0,1,2,3,4,5} instead of {[255,255,255],[0,0,255],[0,255,255],[0,255,0],[255,0,255],[255,0,0]}.
This doesn't appear to be happening in any of the notebooks.
Yes, I've been meaning to add those scripts.
In the meantime, you can use those two functions to perform the conversion from RGB-color encoding to grayscale labels :
def convert_to_color(arr_2d):
""" grayscale labels to RGB-color encoding """
arr_3d = np.zeros((arr_2d.shape[0], arr_2d.shape[1], 3), dtype=np.uint8)
palette = {0 : (255, 255, 255), # Impervious surfaces (white)
1 : (0, 0, 255), # Buildings (dark blue)
2 : (0, 255, 255), # Low vegetation (light blue)
3 : (0, 255, 0), # Tree (green)
4 : (255, 255, 0), # Car (yellow)
5 : (255, 0, 0), # Clutter (red)
6 : (0, 0, 0)} # Unclassified (black)
for c, i in palette.items():
m = arr_2d == c
arr_3d[m] = i
return arr_3d
def convert_from_color(arr_3d):
""" RGB-color encoding to grayscale labels """
arr_2d = np.zeros((arr_3d.shape[0], arr_3d.shape[1]), dtype=np.uint8)
palette = {(0, 0, 0): 0, # Impervious surfaces (white)
(0, 0, 255): 1, # Buildings (dark blue)
(0, 255, 255): 2, # Low vegetation (light blue)
(0, 255, 0): 3, # Tree (green)
(255, 255, 0): 4, # Car (yellow)
(255, 0, 0): 5, # Clutter (red)
(0, 0, 0): 6} # Unclassified (black)
for c, i in palette.items():
m = np.all(arr_3d == np.array(c).reshape(1, 1, 3), axis=2)
arr_2d[m] = i
return arr_2d
You can now use the convert_gt.py
script :
usage: convert_gt.py [-h] [--to-color] [--from-color] [--out OUT]
images [images ...]