I want to apply data augmentation to my dataset " faceLandmarks dataset " in a way that I run multiple training loops. One based on dataset without transform, another one based on dataset with transform and after that for every sample I get extra images. this is what I tried
class FaceLandmarksDataset(Dataset):
def __init__(self, csv_file, root_dir, transform=None):
self.landmarks_frame = pd.read_csv(csv_file)
self.root_dir = root_dir
self.transform = transform
def __len__(self):
return len(self.landmarks_framee
def __getitem__(self, idx):
if torch.is_tensor(idx):
idx = idx.tolist()
self.transform = transforms.Compose([Rescale,
RandomCrop,
ToTensor()])
img_name = os.path.join(self.root_dir,
self.landmarks_frame.iloc[idx, 0])
image = io.imread(img_name)
landmarks = self.landmarks_frame.iloc[idx, 1:]
landmarks = np.array([landmarks], dtype=float).reshape(-1, 2)
#start adding th loop to have tha transformed version
# Assign a label indicating 'none' augmentation by default
aug= 'none'
# Apply transformation if it exists and is a list with augmentation labels
if self.transform:
if isinstance(self.transform, list):
aug = self.transform[idx % len(self.transform)]
sample = {'image': image, 'landmarks': landmarks, 'aug': aug}
if self.transform and aug != 'none':
sample = self.transform(sample)
sample = {'image': image, 'landmarks': landmarks}
return sample
# dataloader for the dataset ---------------------------------
transformed_dataset =
FaceLandmarksDataset(csv_file='/faces_dataset/faces/faces/face_la
ndmarks.csv',root_dir='C/faces_dataset/faces/faces/')
dataloader = DataLoader(transformed_dataset, batch_size=4,
shuffle=True, num_workers=0)
then I got confused how can I call both the transformed and original sample in the dataloader