train_transforms = transforms.Compose(
    [
        transforms.Resize((224, 224)),
        transforms.ToTensor(),        
    ]
)

train_data = datasets.VOCSegmentation(root='./data', image_set ='train', download=False, transform=train_transforms)

train_loader = DataLoader(dataset = train_data, batch_size=batch_size, shuffle=True)

for data, label in train_loader:
        # data = data.PILToTensor()
    print(data.shape)


Blockquote File “C:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data_utils\collate.py”, line 86, in default_collate
raise TypeError(default_collate_err_msg_format.format(elem_type))

TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class ‘PIL.PngImagePlugin.PngImageFile’>