我是神经网络的新手,目前正在尝试构建具有2个转换层的CNN。
class CNN(nn.Module):
def __init__(self):
super(CNN, self).__init__()
self.conv1 = nn.Conv2d(in_channels = 1, out_channels = 16, kernel_size = 3, stride = 1, padding = 1),
self.maxp1 = nn.MaxPool2d(2),
self.conv2 = nn.Conv2d(in_channels = 16, out_channels = 16, kernel_size = 3, stride = 1, padding = 1),
self.fc1 = nn.Linear(16, 64),
self.fc2 = nn.Linear(64, 10)
def forward(self, x):
x = nn.ReLU(self.maxp1(self.conv1(x)))
x = nn.ReLU(self.maxp2(self.conv1(x)))
x = x.view(x.size(0), -1)
x = nn.ReLu(self.fc1(x))
return self.fc2
我想做的是ConvLayer-ReLu激活-最大池2x2-ConvLayer-ReLu激活-展平层-完全连接-ReLu-完全连接
但是,这给了我TypeError: 'tuple' object is not callable
上的x = nn.ReLU(self.maxp1(self.conv1(x)))
我该如何解决?
答案 0 :(得分:0)
您可以将
override init(frame: CGRect) { super.init(frame: frame) setUpGradient() }
更改为nn.ReLU
。
如果您想使用F.relu
,则最好将其声明为nn.ReLU()
方法的一部分,并稍后在__init__
中进行调用:
forward()