当然可以,下面是一个使用 PyTorch 实现 MINST 手写数字识别的简单程序:
```python import torch import torch.nn as nn import torch.optim as optim from torchvision import datasets, transforms
定义模型
class Net(nn.Module): def init(self): super(Net, self).init() self.conv1 = nn.Conv2d(1, 10, kernel_size=5) self.conv2 = nn.Conv2d(10, 20, kernel_size=5) self.conv2_drop = nn.Dropout2d() self.fc1 = nn.Linear(320, 50) self.fc2 = nn.Linear(50, 10)
def forward(self, x):
x = torch.relu(nn.MaxPool2d(2)(self.conv1(x)))
x = torch.relu(nn.MaxPool2d(