MCPcopy Create free account
hub / github.com/pytorch/tutorials / LeNet

Class LeNet

intermediate_source/pruning_tutorial.py:44–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
43
44class LeNet(nn.Module):
45 def __init__(self):
46 super(LeNet, self).__init__()
47 # 1 input image channel, 6 output channels, 5x5 square conv kernel
48 self.conv1 = nn.Conv2d(1, 6, 5)
49 self.conv2 = nn.Conv2d(6, 16, 5)
50 self.fc1 = nn.Linear(16 * 5 * 5, 120) # 5x5 image dimension
51 self.fc2 = nn.Linear(120, 84)
52 self.fc3 = nn.Linear(84, 10)
53
54 def forward(self, x):
55 x = F.max_pool2d(F.relu(self.conv1(x)), (2, 2))
56 x = F.max_pool2d(F.relu(self.conv2(x)), 2)
57 x = x.view(-1, int(x.nelement() / x.shape[0]))
58 x = F.relu(self.fc1(x))
59 x = F.relu(self.fc2(x))
60 x = self.fc3(x)
61 return x
62
63model = LeNet().to(device=device)
64

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected