#深度学习网络
#图片大小为1*28*28,batch_size=64
import torch
from torch import nn
from torch.nn import Conv2d, MaxPool2d, Sequential, Flatten, Linear
class Shen(nn.Module):
def __init__(self):
super(Shen,self).__init__()
self.model=Sequential(
Conv2d(1,8,kernel_size=3,padding=1,),#8*28*28
MaxPool2d(2),#8*14*14
Conv2d(8,16,kernel_size=5,padding=2),#16*14*14
MaxPool2d(2),#16*7*7
Flatten(),
Linear(784,16),
Linear(16,10)
)
def forward(self,x):
x=self.model(x)
return x
pass
if __name__=='__main__':
shen=Shen()
input=torch.ones((64,1,28,28))
output=shen(input)
print(output.shape)
该文章展示了如何使用PyTorch构建一个简单的卷积神经网络(CNN),网络包括两个卷积层,每个后面跟着最大池化层,最后是全连接层,用于1*28*28尺寸图片的分类,batch_size设为64。
2085

被折叠的 条评论
为什么被折叠?



