Two types of transformations

lets say i have these transformations

 transform_all = transforms.Compose([transforms.ToTensor(),
 minor_class_transform = transforms.Compose([transforms.RandomPerspective()])


I’m aware that the transformations will be applied on the fly for every sample. I want that transform_all is applied to every single datapoint since its doing normalization etc. Then i want that minor_class_transform is applied for every datapoint which is in an minority class. When i apply minority class transformation will non-transformed datapoints also added to the sample?

This is how i apply transformations in my custom dataset class.

    def __getitem__(self, idx):
        x, y_1, y_2  = self.samples[idx]
        x = cv2.imread(x)
        x = self.transform_all(x)
        if y_2 == 0:
            x = self.minor_class_transform(x)
        return x, y_1, y_2

I want that transform_all is applied to every single datapoint and that not a single image is without transform_all. Then im using minor_class_transform to do data augmenting for minority class images, but i also want that when minor_class_transform is not applied then such images are in the sample.

Answer according to my understanding

self.transform_all will be used for transformation of all images even if y2==0 but for y2==0 an additional transform will also take place ie the self.minor_class_transform

1 Like

Thus we have common understanding how the code snippet works. However lets say i have a picture X which belongs to a minority class. Then obviously self.minor_class_transform will be applied to the X. Will the non-transformed X be in the same sample as transformed X, since i want to increase amount of datapoints in the minority class.