<aside>
Home | Model Architechture | Model Training | Datasets | Data Preprocessing | Libraries | Training Analysis | Full Code Breakdown
</aside>
<aside>
class NeuralNet(nn.Module):
def __init__(self):
super().__init__()
# Convolutional layers with batch normalization
self.conv1 = nn.Conv2d(3, 32, 5) # 128x128 -> 124x124
self.bn1 = nn.BatchNorm2d(32) # Batch normalization for first conv layer
self.pool = nn.MaxPool2d(2, 2) # Pooling layer
self.conv2 = nn.Conv2d(32, 64, 5) # 124x124 -> 120x120
self.bn2 = nn.BatchNorm2d(64) # Batch normalization for second conv layer
self.conv3 = nn.Conv2d(64, 128, 3) # 60x60 -> 56x56
self.bn3 = nn.BatchNorm2d(128) # Batch normalization for third conv layer
# Fully connected layers with batch normalization
self.fc1 = nn.Linear(128 * 13 * 13, 512) # Adjust based on the final output shape
self.bn_fc1 = nn.BatchNorm1d(512) # Batch normalization for first fully connected layer
self.fc2 = nn.Linear(512, 256)
self.bn_fc2 = nn.BatchNorm1d(256) # Batch normalization for second fully connected layer
self.fc3 = nn.Linear(256, 5)
self.dropout = nn.Dropout(0.5)
def forward(self, x):
x = self.pool(F.relu(self.bn1(self.conv1(x)))) # Conv1 + BatchNorm + ReLU + Pool
x = self.pool(F.relu(self.bn2(self.conv2(x)))) # Conv2 + BatchNorm + ReLU + Pool
x = self.pool(F.relu(self.bn3(self.conv3(x)))) # Conv3 + BatchNorm + ReLU + Pool
x = torch.flatten(x, 1) # Flatten from (batch_size, 128, 14, 14) to (batch_size, 25088)
x = F.relu(self.bn_fc1(self.fc1(x))) # FC1 + BatchNorm + ReLU
x = self.dropout(x) # Dropout
x = F.relu(self.bn_fc2(self.fc2(x))) # FC2 + BatchNorm + ReLU
x = self.fc3(x) # Output layer
return x
</aside>
<aside>

</aside>
<aside>
conv1:
conv2:
conv3:
bn1, bn2, bn3) to normalize activations and stabilize training by reducing internal covariate shift.pool:
MaxPool2d layer is applied after each convolution to reduce spatial dimensions by half (e.g., from 124x124 to 62x62).fc1:
(batch_size, 128 * 13 * 13).fc2:
fc3:
fc1 to randomly deactivate 50% of neurons during training, preventing overfitting.fc3 is a raw score (logits) for each of the 5 classes. Softmax can be applied externally during inference to convert logits to probabilities.
</aside><aside>
conv1, conv2, conv3) with batch normalization, ReLU activation, and pooling.fc1, fc2) with batch normalization, ReLU, and dropout.fc3) outputs logits corresponding to the 5 classes.
</aside><aside>
This model uses Adam optimizer with 0.001 initiallearning rate.
optimizer = optim.Adam(net.parameters(), lr=0.001)
Adam optimizer combines momentum and adaptive learning rates. It dynamically adjusts the learning rate for each parameter, improving convergence efficiency.
</aside>