问题描述

今天调试论文的一段代码,运行时报 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))

代码就不再报上述错误了。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐