前言
本文介绍使用神经网络进行实战。
使用的代码是《零基础学习人工智能—Python—Pytorch学习(九)》里的代码。
代码实现
mudule定义
首先我们自定义一个module,创建一个torch_test17_Model.py文件(这个module要单独用个py文件定义),如下:
import torch.nn as nn
import torch.nn.functional as F
class ConvNet(nn.Module):
def __init__(self):
super(ConvNet, self).__init__()
self.conv1 = nn.Conv2d(3, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16*5*5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)
def forward(self, x):
x = self.pool(F.relu(self.conv1(x