Old CNN for handwritten base-10 digit classification, by a team led by Yann LeCun at AT&T Bell Labs. See this page.

Architecture

Seven total layers: 2 convolutional layers, 2 pooling layers, and 3 fully-connected layers.

In sequential order:

  • Input image is in grayscale, so a single input channel into the first convolutional layer.
  • Convolutional layer has 6 output channels, into ReLU and 2D average pooling.
  • Next convolutional layer has 16 output channels.
  • After ReLU and 2D average pooling, there’s 2 fully connected layers.

Implementation

In PyTorch, we can succinctly implement the architecture as follows.

class LeNet5(nn.Module):
	def __init__(self):
		super(LeNet5, self).__init__()
		self.conv1 = nn.Conv2d(1, 6, 5)
		self.pool = nn.MaxPool2d(2, 2)
		self.conv2 = nn.Conv2d(6, 16, 5)
		self.fc1 = nn.Linear(5 * 5 * 16, 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)))
		x = self.pool(F.relu(self.conv2(x)))
		x = x.view(-1, 5 * 5 * 16) # flattens conv output
		x = F.tanh(self.fc1(x))
		x = F.tanh(self.fc2(x))
		x = self.fc3(x)
		return x

See also