Slow to go fast 2022-07-20 19:00 采纳率: 100%
浏览 1966
已结题

加载自定义数据集时出错RuntimeError: stack expects each tensor to be equal size

问题遇到的现象和发生背景

在使用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

我的解答思路和尝试过的方法

在网上搜了一些办法。但是很多没具体步骤,不知道咋解决

我想要达到的结果
  • 写回答

2条回答 默认 最新

  • 快乐小土狗 2022-07-20 21:13
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 7月30日
  • 已采纳回答 7月22日
  • 创建了问题 7月20日

悬赏问题

  • ¥15 office打开卡退(新电脑重装office系统后)
  • ¥300 FLUENT 火箭发动机燃烧EDC仿真
  • ¥15 【Hadoop 问题】Hadoop编译所遇问题hadoop-common: make failed with error code 2
  • ¥15 vb6.0+webbrowser无法加载某个网页求解
  • ¥15 RPA财务机器人采购付款流程
  • ¥15 计算机图形多边形及三次样条曲线绘制
  • ¥15 根据protues画的图用keil写程序
  • ¥200 如何使用postGis实现最短领规划?
  • ¥15 pyinstaller打包错误
  • ¥20 cesm的气溶胶排放文件