RuntimeError: each element in list of batch should be of equal size

transform = transforms.Compose([
    transforms.Resize((480, 640)),
    transforms.ToTensor(),
])

train_dataset = datasets.CocoDetection(
    root=args.train_dataset, annFile=args.train_annotation, transform=transform)

train_loader = DataLoader(train_dataset, batch_size=64)

for (img, anno) in train_loader:
    out = model(img)
python3.7/site-packages/torch/utils/data/_utils/collate.py", line 82, in default_collate
    raise RuntimeError('each element in list of batch should be of equal size')
RuntimeError: each element in list of batch should be of equal size

Issue resolved by downgrad back to PyTorch 1.5.0
So it looks like a PyTorch 1.6 issue

I too got this error while using pytorch 1.6, so I did the same as you and downgraded it and it worked fine

Could you please provide more information at https://github.com/pytorch/pytorch/issues/42654 ?

how to downgrad back to PyTorch 1.5.0 ??

Comment the checking operation in site-packages/torch/utils/data/_utils/collate.py (line 80 81)

#if not all(len(elem) == elem_size for elem in it):
        #    raise RuntimeError('each element in list of batch should be of equal size')

That works for me with torch1.8 on Windows10.