Skip to content

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

@ZhiyuanChen

Description

@ZhiyuanChen

🐛 Bug

"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

To Reproduce

Steps to reproduce the behavior:

model = models.resnet50()

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)

Expected behavior

forward

Environment

Please copy and paste the output from our
environment collection script
(or fill out the checklist below manually).

You can get the script and run it with:

wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
  • PyTorch Version (e.g., 1.0): 1.6
  • OS (e.g., Linux): Ubuntu
  • How you installed PyTorch (conda, pip, source): conda -c pytorch
  • Build command you used (if compiling from source):
  • Python version: 3.7
  • CUDA/cuDNN version: 10.2
  • GPU models and configuration: V100
  • Any other relevant information:

Additional context

pytorch/pytorch#42654

cc @pmeier

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions