问题遇到的现象和发生背景
在使用dataloader加载数据时出现加载的数据维度不匹配
问题相关代码,请勿粘贴截图
运行结果及报错内容
Traceback (most recent call last):
File "/mnt/pycharm_project_520/main_msaf.py", line 207, in
train_losses, train_scores = train(get_X, args.log_interval, multimodal_model, device, training_loader,
File "/mnt/pycharm_project_520/main_utils.py", line 54, in train
for batch_idx, sample in enumerate(train_loader):
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 530, in next
data = self._next_data()
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1224, in _next_data
return self._process_data(data)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1250, in _process_data
data.reraise()
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/torch/_utils.py", line 457, in reraise
raise exception
RuntimeError: Caught RuntimeError in DataLoader worker process 7.
Original Traceback (most recent call last):
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
data = fetcher.fetch(index)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 52, in fetch
return self.collate_fn(data)
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/torch/utils/data/_utils/collate.py", line 157, in default_collate
return elem_type({key: default_collate([d[key] for d in batch]) for key in elem})
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/torch/utils/data/_utils/collate.py", line 157, in
return elem_type({key: default_collate([d[key] for d in batch]) for key in elem})
File "/root/miniconda3/envs/myconda/lib/python3.8/site-packages/torch/utils/data/_utils/collate.py", line 138, in default_collate
return torch.stack(batch, 0, out=out)
RuntimeError: stack expects each tensor to be equal size, but got [30, 3, 224, 224] at entry 0 and [31, 3, 224, 224] at entry 7
我的解答思路和尝试过的方法
在网上搜了一些办法。但是很多没具体步骤,不知道咋解决