Hello there , I’m new to PyTorch, I’ve created a dataset that is having x-ray images and it is transformed but after creating the dataset I’m not getting good test accuracy so i have decided to do augmentation but I don’t know how to do augmentation on already created dataset .
aug = transforms.Compose([transforms.RandomHorizontalFlip(1),
transforms.RandomAffine(20)])
temp_list = []
for x,y in train_loader:
temp_list.append(aug(x))
final_tensor = torch.cat(temp_list)
This way we can do that , is there ant efficient way? without using list .
Thank you for your suggestion.
Hey @Bhavya_Soni
Why would you concatenate the augmented tensors?
It would be efficient to augment and send the augmented tensors through a model and learn the weights.
The only problem that I see here is that the Random_ augmentation will augment each image in a batch the same way, which is not an ideal setup.
First, you can set batch_size for the DataLoader to load multiple data into a batch and do transform or augmentation for each batch.
Secondly, I am not sure why you have this tmp_list. You can directly use the augmented data to train your model.
for x, y in train_loader:
aug_x = aug(x)
...
output = model(aug_x)
loss = ...
loss.backward()
...
``