object has no attribute
代码
import torchfrom torch import nn
input = torch.tensor([[1, 2, 0, 3, 1],
[0, 1, 2, 3, 1],
[1, 2, 1, 0, 0],
[5, 2, 3, 1, 1],
[2, 1, 0, 1, 1]], dtype=torch.float32)
input = torch.reshape(input, (-1, 1, 5, 5))
print(input.shape)
class jiang(nn.Module):
def __int__(self):
super(jiang, self).__int__()
self.maxpool1 = torch.nn.MaxPool2d(kernel_size=3,
ceil_mode=True)
def forward(self, input):
output = self.maxpool1(input)
return output
wen = jiang()
wen(input)
错误类型
D:\AnacondaPython\python.exe D:/pythonProject/CNN/nn.MaxPool_demo.pyTraceback (most recent call last):
File "D:/pythonProject/CNN/nn.MaxPool_demo.py", line 23, in <module>
wen(input)
File "D:\AnacondaPython\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
File "D:/pythonProject/CNN/nn.MaxPool_demo.py", line 19, in forward
output = self.maxpool1(input)
File "D:\AnacondaPython\lib\site-packages\torch\nn\modules\module.py", line 1185, in __getattr__
raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'jiang' object has no attribute 'maxpool1'
torch.Size([1, 1, 5, 5])
Process finished with exit code 1
拜谢大佬指点
回答:
__init__
,不是 __int__
。
以上是 object has no attribute 的全部内容, 来源链接: utcz.com/p/938405.html