Augmentations to only one class

Hi,

I’m not sure if I have correctly implemented applying augmentations to only one class during training (binary classes). The code runs however, I’m just unsure if the augmentations is actually happening during the get item function. Would anyone be able to tell me if this would cause any potential issues (for example memory or speed)? :

 if self.phase == 'train':
            self.transforms = T.Compose([T.RandomResizedCrop(224),
                                    T.ToTensor(),
                                    T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])]) 
            self.transforms_augs = T.Compose([T.RandomResizedCrop(224),
                                    T.RandomHorizontalFlip(),
                                    T.RandomVerticalFlip(),
                                    T.ToTensor(),
                                    T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])]) 

        else:
            self.transforms = T.Compose([T.RandomResizedCrop(224),T.ToTensor(),
                                T.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])])


    def __getitem__(self, index):
        if self.phase == 'train':
            path = self.imgs[index]
            label = int(path.split('/')[11])
            data = Image.open(path).convert('RGB')
            if label == 1:
                data = self.transforms_augs(data)
            else:
                data = self.transforms(data)

Cheers,

T

Hi,

for me your augmentation looks good. You could visualize your input data by denormalizing it first, converting it from [B, C, H, W] to [B, H, W, C] using torch.permute(), maybe min-max it to be between 0-255, then convert it to a numpy array and e.g. show it with matplotlib imshow().

Greetings.

1 Like

Thanks, I’ll give that a try!

T