RuntimeError: The size of tensor a (128) must match the size of tensor b (122) at non-singleton dimension 3
时间: 2023-09-22 11:10:17 浏览: 807
pytorch模型提示超出内存RuntimeError: CUDA out of memory.
5星 · 资源好评率100%
这个报错的原因是由于在计算过程中,两个张量的尺寸不匹配导致的。根据引用的描述,这个问题可能是在读取图片时出现的。要解决这个问题,可以尝试将图片转换为RGB格式。另外,根据引用的建议,在DataLoader函数中添加参数"drop_last=False"也可能解决这个问题。具体地,你可以像下面这样修改代码:
dataloader = DataLoader(ImageDataset(opt.dataroot, transforms_=transforms_, unaligned=True), batch_size=opt.batchSize, shuffle=True, num_workers=opt.n_cpu, drop_last=False)
通过保持batch的尺寸不变来避免尺寸不匹配的问题。希望这个解决方案能帮到你!<span class="em">1</span><span class="em">2</span>
#### 引用[.reference_title]
- *1* [RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio](https://blog.csdn.net/weixin_46135327/article/details/130805823)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [RuntimeError: The size of tensor a (8) must match the size of tensor b (7) at non-singleton dimensio](https://blog.csdn.net/m0_46368408/article/details/131231563)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文