1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
class Mnist_Net(paddle.nn.Layer):
def __init__(self):
super().__init__()
self.conv1=paddle.nn.Conv2D(in_channels=1,out_channels=6,kernel_size=[5,5])
self.maxpool1=paddle.nn.MaxPool2D(kernel_size=[2,2],stride=2)
self.conv2=paddle.nn.Conv2D(in_channels=6,out_channels=16,kernel_size=[5,5])
self.maxpool2=paddle.nn.MaxPool2D(kernel_size=[2,2],stride=2)
self.conv3=paddle.nn.Conv2D(in_channels=16,out_channels=120,kernel_size=[5,5])
self.flatten=paddle.nn.Flatten()
self.fc2=paddle.nn.Linear(120,84)
self.fc3=paddle.nn.Linear(84,10)
self.softmax=paddle.nn.Softmax()
self.relu=paddle.nn.ReLU()
self.sigmoid=paddle.nn.Sigmoid()
def forward(self,x):
x=self.conv1(x)
x=self.relu(x)
x=self.maxpool1(x)
x=self.conv2(x)
x=self.relu(x)
x=self.maxpool2(x)
x=self.conv3(x)
x=self.relu(x)
x=self.flatten(x)
x=self.fc2(x)
x=self.relu(x)
x=self.fc3(x)
y=self.softmax(x)
return y
mnist_net=Mnist_Net()
paddle.summary(mnist_net,(1,1,32,32))
|