补全以下代码class LeNet(paddle.nn.Layer): def __init__(self): super(LeNet, self).__init__() return x
时间: 2024-06-02 19:08:18 浏览: 144
class LeNet(paddle.nn.Layer):
def __init__(self):
super(LeNet, self).__init__()
self.conv1 = paddle.nn.Conv2D(in_channels=1, out_channels=6, kernel_size=5, stride=1, padding=2)
self.max_pool1 = paddle.nn.MaxPool2D(kernel_size=2, stride=2)
self.conv2 = paddle.nn.Conv2D(in_channels=6, out_channels=16, kernel_size=5, stride=1)
self.max_pool2 = paddle.nn.MaxPool2D(kernel_size=2, stride=2)
self.fc1 = paddle.nn.Linear(in_features=16*5*5, out_features=120)
self.fc2 = paddle.nn.Linear(in_features=120, out_features=84)
self.fc3 = paddle.nn.Linear(in_features=84, out_features=10)
def forward(self, x):
x = self.conv1(x)
x = paddle.nn.functional.relu(x)
x = self.max_pool1(x)
x = self.conv2(x)
x = paddle.nn.functional.relu(x)
x = self.max_pool2(x)
x = paddle.reshape(x, [x.shape[0], -1])
x = self.fc1(x)
x = paddle.nn.functional.relu(x)
x = self.fc2(x)
x = paddle.nn.functional.relu(x)
x = self.fc3(x)
return x
阅读全文