The following data loader script reads 11 different class names from ‘mask’ images. It seems that the index of the classes is used to define the order. But, when you have an image that has 11 different mask-classes with no names assigned, how could the first index be a ‘sky’ and second could be ‘building’ and so on? I am having a hard time understanding this logic.
class Dataset(BaseDataset):
"""CamVid Dataset. Read images, apply augmentation and preprocessing transformations.
Args:
images_dir (str): path to images folder
masks_dir (str): path to segmentation masks folder
class_values (list): values of classes to extract from segmentation mask
augmentation (albumentations.Compose): data transfromation pipeline
(e.g. flip, scale, etc.)
preprocessing (albumentations.Compose): data preprocessing
(e.g. normalization, shape manipulation, etc.)
"""
CLASSES = ['sky', 'building', 'pole', 'road', 'pavement',
'tree', 'signsymbol', 'fence', 'car',
'pedestrian', 'bicyclist', 'unlabelled']
def __init__(
self,
images_dir,
masks_dir,
classes=None,
augmentation=None,
preprocessing=None,
):
self.ids = os.listdir(images_dir)
self.images_fps = [os.path.join(images_dir, image_id) for image_id in self.ids]
self.masks_fps = [os.path.join(masks_dir, image_id) for image_id in self.ids]
# convert str names to class values on masks
self.class_values = [self.CLASSES.index(cls.lower()) for cls in classes]
self.augmentation = augmentation
self.preprocessing = preprocessing
It seems the order of the classes is defined in the script using CLASSES?
I don’t know what exactly is passed to the Dataset, but based on how self.class_values is created, it seems to be the case.
The index are in the mask images itself. So for example if the label for “sky” is 1, in the mask images with sky should be full of 1 in the correspondents pixels.
You are right. Camvid masks have labels from 1 to 11. In my case, I do not have classes in order and they range from 0 to 23 and these are greyscale images. How to deal with this?