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

加载自定义数据集时出错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 模拟电路求复阻抗和传递函数,请各位拍照写一下解答过程
  • ¥60 不懂得怎么运行下载来的代码
  • ¥15 CST导出3D模型图为什么和软件显示不一样?
  • ¥15 加热反应炉PLC控制系统设计(相关搜索:梯形图)
  • ¥15 python 用Dorc包报错,我的写法和网上教的是一样的但是它显示无效参数,是什么问题
  • ¥15 经过滑动平均后的一维信号还原用什么结构好呢?
  • ¥15 指定IP电脑的访问设置
  • ¥30 matlab ode45 未发现警告,但是运行出错
  • ¥15 为什么devc++编译项目会失败啊
  • ¥15 vscode platformio