demo流程
- model.py定义卷积神经网络
- train.py加载数据集并训练,训练集计算loss,测试集计算accuracy,保存训练模型
- predict.py用自己图像进行分类测试,并显示出图像改变成32*32大小后的图像和预测出的类别
定义卷积神经网络
def __init__(self):
super(LeNet, self).__init__()
self.conv1 = nn.Conv2d(3,16,5)
self.pool1 = nn.MaxPool2d(2,2)
self.conv2 = nn.Conv2d(16,32,5)
self.pool2 = nn.MaxPool2d(2,2)
self.fc1 = nn.Linear(32*5*5,120)
self.fc2 = nn.Linear(120,84)
self.fc3 = nn.Linear(84,10)
def forward(self,x):
x = F.relu(self.conv1(x))
x = self.pool1(x)
x = F.relu(self.conv2(x))
x = self.pool2(x)
x = x.view(-1,32*5*5)
x = F.<