解决RuntimeError: The expanded size of the tensor (313) must match the existing size (256) at non-sing

最近在复现2020年ECCV的rethinking-inpainting的代码,发现源码是错误的,训练一直出现这个错误,试了很多方法都没有解决,在GitHub上给作者留言,最终一位网友提的修改方法成功解决,特来记录一下
错误:
RuntimeError: The expanded size of the tensor (313) must match the existing size (256) at non-singleton dimension 2. Target sizes: [1, 1, 313, 256]. Tensor sizes: [1, 1, 256, 256]
在这里插入图片描述
修改地方为dataprocess.py里的:
源代码为:

self.img_transform = transforms.Compose([
            transforms.Resize(opt.fineSize),
            transforms.ToTensor(),
            transforms.Normalize((0.5, 0.5, 0.5),(0.5, 0.5, 0.5))
        ])
        # mask should not normalize, is just have 0 or 1
        self.mask_transform = transforms.Compose([
            transforms.Resize(opt.fineSize),
            transforms.ToTensor()
        ])

修改为:

self.img_transform = transforms.Compose([
            transforms.Resize((opt.fineSize, opt.fineSize)),
            transforms.ToTensor(),
            transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
        ])
        # mask should not normalize, is just have 0 or 1
        self.mask_transform = transforms.Compose([
            transforms.Resize((opt.fineSize, opt.fineSize)),
            transforms.ToTensor()
        ])

你可能感兴趣的:(程序问题,深度学习,计算机视觉,pytorch,神经网络)