Image Classification
English
nicholasKluge commited on
Commit
534cd39
1 Parent(s): 248a020

Create lennon.py

Browse files
Files changed (1) hide show
  1. lennon.py +35 -0
lennon.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch.nn as nn
2
+
3
+ class LeNNon(nn.Module):
4
+ def __init__(self):
5
+ """ Define a CNN architecture used for image classification.
6
+ This class defines the LeNNon architecture as a PyTorch module
7
+ """
8
+ super(LeNNon, self).__init__()
9
+ self.conv1 = nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1)
10
+ self.pool = nn.MaxPool2d(kernel_size=2, stride=2)
11
+ self.conv2 = nn.Conv2d(16, 32, kernel_size=3, stride=1, padding=1)
12
+ self.fc1 = nn.Linear(32 * 25 * 25, 128)
13
+ self.fc2 = nn.Linear(128, 10)
14
+
15
+ def forward(self, x):
16
+ """
17
+ Perform a forward pass through the LeNNon architecture.
18
+
19
+ This method applies the convolutional layers, max pooling layers,
20
+ and fully connected layers to the input tensor x.
21
+
22
+ Parameters:
23
+ -----------
24
+ x (torch.Tensor): The input tensor.
25
+
26
+ Returns:
27
+ --------
28
+ torch.Tensor: The output tensor.
29
+ """
30
+ x = self.pool(torch.relu(self.conv1(x)))
31
+ x = self.pool(torch.relu(self.conv2(x)))
32
+ x = x.view(-1, 32 * 25 * 25)
33
+ x = torch.relu(self.fc1(x))
34
+ x = self.fc2(x)
35
+ return x