PyTorch Dataloader - List is not callable error when enumerating
When iterating over a PyTorch dataloader, e.g.

# define dataset, dataloader
train_data = datasets.ImageFolder(data_dir + '/train', transform=train_transforms)
test_data = datasets.ImageFolder(data_dir + '/test', transform=test_transforms)
trainloader = torch.utils.data.DataLoader(train_data, batch_size=64, shuffle=True)
testloader = torch.utils.data.DataLoader(test_data, batch_size=64)

# define model, optimizer, loss
# not included - irrelevant to the question

for ii, (inputs, labels) in enumerate(trainloader):

    # Move input and label tensors to the GPU
    inputs, labels = inputs.to(device), labels.to(device)

    start = time.time()

    outputs = model.forward(inputs)
    loss = criterion(outputs, labels)
    loss.backward()


I get a TypeError: 'list' object is not callable on this line

for ii, (inputs, labels) in enumerate(trainloader):


What dumb thing am I forgetting?

Did you remember to call transforms.Compose on your list of transforms?

In this line

train_data = datasets.ImageFolder(data_dir + '/train', transform=train_transforms)


the transform parameter is expecting a callable object, not a list.

So, for example, this is wrong:

train_transforms = [
    transforms.RandomResizedCrop(224),
    transforms.RandomHorizontalFlip(),
    transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])]


It should look like this

train_transforms = transforms.Compose([
    transforms.RandomResizedCrop(224),
    transforms.RandomHorizontalFlip(),
    transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])])

