Caffe2 - Python API
A deep learning, cross platform ML framework
mnist.py
1 import torch.nn as nn
2 import torch.nn.functional as F
3 
4 
5 class MNIST(nn.Module):
6 
7  def __init__(self):
8  super(MNIST, self).__init__()
9  self.conv1 = nn.Conv2d(1, 10, kernel_size=5)
10  self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
11  self.conv2_drop = nn.Dropout2d()
12  self.fc1 = nn.Linear(320, 50)
13  self.fc2 = nn.Linear(50, 10)
14 
15  def forward(self, x):
16  x = F.relu(F.max_pool2d(self.conv1(x), 2))
17  x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2))
18  x = x.view(-1, 320)
19  x = F.relu(self.fc1(x))
20  x = F.dropout(x, training=self.training)
21  x = self.fc2(x)
22  return F.log_softmax(x, dim=1)