亲测解决Pytorch TypeError: object of type ‘numpy.int64‘ has no len()
这个问题是小虎在初始化自适应平均池化的时候遇到的,解决方法是限制初始化时池化大小的类型。
问题原文
Exception has occurred: TypeError
object of type 'numpy.int64' has no len()File "D:\Complier\LEF\lib\model\segmentation\heads\modules\fgModules.py", line 162, in forwardPoolFeature = callMethod(self, Name)(self.PoolLayer(f))
TypeError: object of type 'numpy.int64' has no len()
解决实例
报错语句如下:
AdaptiveAvgPool2d(self.PoolSize)
查看类型发现是numpy:
type(self.PoolSize)
<class 'numpy.int64'>
所以可以改成:
AdaptiveAvgPool2d(int(self.PoolSize))