MCPcopy Index your code
hub / github.com/pytorch/tutorials / SimpleCNN

Class SimpleCNN

intermediate_source/per_sample_grads.py:26–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24# Here's a simple CNN and loss function:
25
26class SimpleCNN(nn.Module):
27 def __init__(self):
28 super(SimpleCNN, self).__init__()
29 self.conv1 = nn.Conv2d(1, 32, 3, 1)
30 self.conv2 = nn.Conv2d(32, 64, 3, 1)
31 self.fc1 = nn.Linear(9216, 128)
32 self.fc2 = nn.Linear(128, 10)
33
34 def forward(self, x):
35 x = self.conv1(x)
36 x = F.relu(x)
37 x = self.conv2(x)
38 x = F.relu(x)
39 x = F.max_pool2d(x, 2)
40 x = torch.flatten(x, 1)
41 x = self.fc1(x)
42 x = F.relu(x)
43 x = self.fc2(x)
44 output = F.log_softmax(x, dim=1)
45 return output
46
47def loss_fn(predictions, targets):
48 return F.nll_loss(predictions, targets)

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected