当前位置:   article > 正文

RuntimeError: The size of tensor a (8) must match the size of tensor b (7) at non-singleton dimensio_runtimeerror: the size of tensor a (2048) must mat

runtimeerror: the size of tensor a (2048) must match the size of tensor b (7

在出现类似问题报错,并且该错误出现的情景为前面训练正常,在当前训练的epoch快要结束时出现报错,则该错误原因为在训练过程中所用的数据集数量与所设置的batchsize可能不是整除的关系,导致出错。

解决方法,在DataLoader函数中加上一个参数drop_last=False,具体示例如下:

  1. dataloader = DataLoader(ImageDataset(opt.dataroot, transforms_=transforms_, unaligned=True),
  2. batch_size=opt.batchSize, shuffle=True, num_workers=opt.n_cpu, drop_last=False)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/272310
推荐阅读
相关标签
  

闽ICP备14008679号