How can you add noise to your input?
def add_normal_noise(input_tensor, mean: int = 0, std: float = 0.5):
# Create the tensor containing the noise
noise_tensor = torch.empty_like(input_tensor)
noise_tensor.normal_(mean=mean, std=std)
# Add noise to input tensor and return results
return input_tensor + noise_tensor
# mean = 0, standard deviation is hyperparameter,
# which has to be figured out
How can you dropout values from your input?
simple_dropout = torch.nn.Dropout(p=p)
How can we chain different data augmentation techniques?
from torchvision import transforms
transform_chain = transforms.Compose([
transforms.Resize(size=100),
transforms.ColorJitter(),
transforms.RandomRotation(degrees=180),
transforms.RandomVerticalFlip(),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
noise_transform
# use transforms.Lambda, therefore noise has to be wrapped
# in an auxiliary function
)]
Some transforms work on PIL images, others on tensors -> keep order and position of transformation in mind.
You might need 2 transform chains, one for training and one for evaluation.
How can you combine the dataset module and the transforms methods?
Option 1: implement the transformations in the getitem() method of the dataset, ideal when we want to apply transformations for training and evaluation
Option 2: implement the transformation in the getitem() method of a different dataset, since we often want to apply different transformation to training and evaluation
Zuletzt geändertvor 2 Jahren