Pages


<aside>

Home | Model Architechture | Model Training | Datasets | Data Preprocessing | Libraries | Training Analysis | Full Code Breakdown

</aside>


Model Code


<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>


Model Visualization

<aside>

model.onnx.png

</aside>

Model Definitions


<aside>

1. Convolutional Layers

2. Batch Normalization

3. Pooling Layer

4. Fully Connected Layers

5. Dropout

6. Activation Functions

7. Output Layer

Forward Pass


<aside>


Optimizer


<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>