问题描述
今天调试论文的一段代码,运行时报 TypeError: new(): argument ‘size’ must be tuple of ints, but found element of type float at pos 3 的错误,如下图所示:
原因
论文发表比较早,使用 Python2 写的,我用的 Python3 的解释器,语法上可能有区别。
解决方法
对其进行类型转换,将
real_center = torch.FloatTensor(opt.batchSize, 3, opt.imageSize/2, opt.imageSize/2)
修改为:
real_center = torch.FloatTensor(opt.batchSize, 3, int(opt.imageSize/2), int(opt.imageSize/2))
代码就不再报上述错误了。