i used image augmentation in pytorch before training in unet like this
class ProcessTrainDataset(Dataset):
def __init__(self, x, y):
self.x = x
self.y = y
self.pre_process = transforms.Compose([
transforms.ToTensor()])
self.transform_data = transforms.Compose([
transforms.ColorJitter(brightness=0.2, contrast=0.2)])
self.transform_all = transforms.Compose([
transforms.RandomVerticalFlip(),
transforms.RandomHorizontalFlip(),
transforms.RandomRotation(10),
transforms.RandomPerspective(distortion_scale=0.2, p=0.5),
transforms.RandomAffine(degrees=0, translate=(0.2,0.2), scale=(0.9,1.1),),])
def __len__(self):
return len(self.x)
def __getitem__(self, idx):
img_x = Image.open(self.x[idx])
img_y = Image.open(self.y[idx]).convert("L")
#First get into the right range of 0 - 1, permute channels first, and put to tensor
img_x = self.pre_process(img_x)
img_y = self.pre_process(img_y)
#Apply resize and shifting transforms to all; this ensures each pair has the identical transform applied
img_all = torch.cat([img_x, img_y])
img_all = self.transform_all(img_all)
#Split again and apply any color/saturation/hue transforms to data only
img_x, img_y = img_all[:-1, ...], img_all[-1:,...]
img_x = self.transform_data(img_x)
#Add augmented data to dataset
self.x_augmented.append(img_x)
self.y_augmented.append(img_y)
return img_x, img_y
but how do we know if all augmentations have been applied to the dataset and how can we see the number of datasets after augmentation?