Pytorch, TypeError: object() takes no parameters
Pytorch, TypeError: object() takes no parameters
这可能是一个初学者问题,但尽管如此:当 运行 图像 classifier 使用 pytorch 构建时,我收到此错误:
Traceback (most recent call last):
File "/pytorch/kanji_torch.py", line 47, in <module>
network = Network()
File "/pytorch/kanji_torch.py", line 113, in __init__
self.conv1 = nn.Conv2d(1, 32, 5)
File "/python3.5/site-packages/torch/nn/modules/conv.py", line 233, in __init__
False, _pair(0), groups, bias)
File "/python3.5/site-packages/torch/nn/modules/conv.py", line 32, in __init__
out_channels, in_channels // groups, *kernel_size))
TypeError: object() takes no parameters
我这样定义网络class:
class Network(torch.nn.Module):
def __init__(self):
super(Network, self).__init__()
self.conv1 = nn.Conv2d(1, 32, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(32, 64, 5)
self.pool2 = nn.MaxPool2d(2, 2)
self.conv3 = nn.Conv2d(64, 64, 5)
self.pool2 = nn.MaxPool2d(2, 2)
self.fc1 = nn.Linear(64 * 5 * 5, 512)
self.fc2 = nn.Linear(512, 640)
self.fc3 = nn.Linear(640, 3756)
非常确定我正确导入了所有相关的 pytorch 库模块。
(将 torch.nn 导入为 nn 和
进口手电筒)
对我做错了什么有什么想法吗?
谢谢!
你的pytorch版本可能有问题,当我运行代码:
class Network(torch.nn.Module):
def __init__(self):
super(Network, self).__init__()
self.conv1 = nn.Conv2d(1, 32, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(32, 64, 5)
self.pool2 = nn.MaxPool2d(2, 2)
self.conv3 = nn.Conv2d(64, 64, 5)
self.pool2 = nn.MaxPool2d(2, 2)
self.fc1 = nn.Linear(64 * 5 * 5, 512)
self.fc2 = nn.Linear(512, 640)
self.fc3 = nn.Linear(640, 3756)
print(network)
输出为:
Network (
(conv1): Conv2d(1, 32, kernel_size=(5, 5), stride=(1, 1))
(pool): MaxPool2d (size=(2, 2), stride=(2, 2), dilation=(1, 1))
(conv2): Conv2d(32, 64, kernel_size=(5, 5), stride=(1, 1))
(pool2): MaxPool2d (size=(2, 2), stride=(2, 2), dilation=(1, 1))
(conv3): Conv2d(64, 64, kernel_size=(5, 5), stride=(1, 1))
(fc1): Linear (1600 -> 512)
(fc2): Linear (512 -> 640)
(fc3): Linear (640 -> 3756)
)
我建议 update/reinstall pytorch。
这可能是一个初学者问题,但尽管如此:当 运行 图像 classifier 使用 pytorch 构建时,我收到此错误:
Traceback (most recent call last):
File "/pytorch/kanji_torch.py", line 47, in <module>
network = Network()
File "/pytorch/kanji_torch.py", line 113, in __init__
self.conv1 = nn.Conv2d(1, 32, 5)
File "/python3.5/site-packages/torch/nn/modules/conv.py", line 233, in __init__
False, _pair(0), groups, bias)
File "/python3.5/site-packages/torch/nn/modules/conv.py", line 32, in __init__
out_channels, in_channels // groups, *kernel_size))
TypeError: object() takes no parameters
我这样定义网络class:
class Network(torch.nn.Module):
def __init__(self):
super(Network, self).__init__()
self.conv1 = nn.Conv2d(1, 32, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(32, 64, 5)
self.pool2 = nn.MaxPool2d(2, 2)
self.conv3 = nn.Conv2d(64, 64, 5)
self.pool2 = nn.MaxPool2d(2, 2)
self.fc1 = nn.Linear(64 * 5 * 5, 512)
self.fc2 = nn.Linear(512, 640)
self.fc3 = nn.Linear(640, 3756)
非常确定我正确导入了所有相关的 pytorch 库模块。
(将 torch.nn 导入为 nn 和
进口手电筒)
对我做错了什么有什么想法吗?
谢谢!
你的pytorch版本可能有问题,当我运行代码:
class Network(torch.nn.Module):
def __init__(self):
super(Network, self).__init__()
self.conv1 = nn.Conv2d(1, 32, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(32, 64, 5)
self.pool2 = nn.MaxPool2d(2, 2)
self.conv3 = nn.Conv2d(64, 64, 5)
self.pool2 = nn.MaxPool2d(2, 2)
self.fc1 = nn.Linear(64 * 5 * 5, 512)
self.fc2 = nn.Linear(512, 640)
self.fc3 = nn.Linear(640, 3756)
print(network)
输出为:
Network (
(conv1): Conv2d(1, 32, kernel_size=(5, 5), stride=(1, 1))
(pool): MaxPool2d (size=(2, 2), stride=(2, 2), dilation=(1, 1))
(conv2): Conv2d(32, 64, kernel_size=(5, 5), stride=(1, 1))
(pool2): MaxPool2d (size=(2, 2), stride=(2, 2), dilation=(1, 1))
(conv3): Conv2d(64, 64, kernel_size=(5, 5), stride=(1, 1))
(fc1): Linear (1600 -> 512)
(fc2): Linear (512 -> 640)
(fc3): Linear (640 -> 3756)
)
我建议 update/reinstall pytorch。