I create training, validation and testing data loaders for MNIST as follows:
train_set = datasets.MNIST(root=data_root, train=True, transform=transform_train, download=True) valid_set = datasets.MNIST(root=data_root, train=True, transform=transform_test, download=False) test_set = datasets.MNIST(root=data_root, train=False, transform=transform_test, download=False) # Split training into train and validation train_size = 600; val_size = 59400; indices = torch.randperm(len(train_set)) train_indices = indices[:len(indices)-valid_size][:train_size or None] valid_indices = indices[len(indices)-valid_size:] if valid_size else None train_loader = torch.utils.data.DataLoader(train_set, batch_size=batch_size, sampler=SubsetRandomSampler(train_indices), **kwargs) test_loader = torch.utils.data.DataLoader(test_set, batch_size=batch_size, **kwargs) if valid_size: valid_loader = torch.utils.data.DataLoader(valid_set, batch_size=batch_size, sampler=SubsetRandomSampler(valid_indices), **kwargs) else: valid_loader = None
Now what I would like to do is to transform the training data and then add the transformed data to the existing training data to form a new training set, somehow like this:
# Now transform the training data and add the new transformed data to existing training data for data, target in train_loader: t_ims = ut.transform_ims(data.numpy(), [parameters]) t_data = torch.from_numpy(t_ims) # Concatenate data = [data, t_data] target = [target, target] # Set new training data train_loader.data = data train_loader.target = target
Could you please tell me how to do that? I find the structure of dataloader in PyTorch is really difficult to understand
Thank you very much for your help!!