Trouble using transforms.FiveCrop()/TenCrop() in PyTorch
I am trying to increase my CNN’s performance and thus i decided to “play” with some transformations in order to see how they affect my model. I read that FiveCrop() and TenCrop() might help because they generate extra data to train on. However, when i try to train the model, using one of the transformations mentioned above, i get the following error:

TypeError: pic should be PIL Image or ndarray. Got &lt; class ‘tuple’>

The documentation of those transformations, only states a note for the test procedure, any idea how to fix this?

Thanks in advance!

train_transform = transforms.Compose(
    [transforms.ColorJitter(),
     transforms.TenCrop(32),
     transforms.ToTensor(),
     transforms.Normalize((0.4914, 0.4822, 0.4465), (0.247, 0.243, 0.261))
     ])

train = datasets.CIFAR10(root = './data',
                  train = True,
                  transform = train_transform,
                  download = True)

train_loader = torch.utils.data.DataLoader(dataset = train,
                                      batch_size = 1250,
                                      shuffle = True)

for epoch in range(num_of_iterations):
  correct = 0
  acc = 0.0
  running_loss = 0.0
  for i, (images, labels) in enumerate(train_loader):
      images = images.requires_grad_().to(device)
      labels = labels.to(device)


The error occurs on the line of the second for-loop

Right, your error is coming from transforms.ToTensor(), which is directly downstream of your TenCrop in the composed transformation. It expects an image but gets a tuple of crops instead. You should follow a procedure similar to the one shown in the documentation not only for testing but also for training in order to reorganize your images into the expected format of [batch, feature_maps, width, height].

As a side note, CIFAR10 is already 32x32 pixels so taking 32x32 crops is an identity operation. Your FiveCrop effectively just repeats the same image 5 times and TenCrop repeats it 5 times plus adds 5 flipped versions. You should either reduce the size of crops or find out a different data augumentation scheme to see improvement with your networks generalization.
