Created
October 31, 2023 20:31
-
-
Save leavism/5ada114858130c89f4e066f376e69924 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImprovedCatDogClassifier(nn.Module): | |
def __init__(self): | |
super(ImprovedCatDogClassifier, self).__init__() | |
# Convolutional layers with BatchNorm | |
self.conv1 = nn.Conv2d(1, 32, kernel_size=3, stride=1, padding=1) | |
self.bn1 = nn.BatchNorm2d(32) | |
self.conv2 = nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1) | |
self.bn2 = nn.BatchNorm2d(64) | |
self.conv3 = nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1) | |
self.bn3 = nn.BatchNorm2d(128) | |
self.conv4 = nn.Conv2d(128, 256, kernel_size=3, stride=1, padding=1) | |
self.bn4 = nn.BatchNorm2d(256) | |
self.pool = nn.MaxPool2d(2, 2) | |
# Fully connected layers with Dropout | |
self.fc1 = nn.Linear(256 * 14 * 14, 128) | |
self.dropout = nn.Dropout(0.5) | |
self.fc2 = nn.Linear(128, 2) | |
def forward(self, x): | |
x = self.pool(F.relu(self.bn1(self.conv1(x)))) | |
x = self.pool(F.relu(self.bn2(self.conv2(x)))) | |
x = self.pool(F.relu(self.bn3(self.conv3(x)))) | |
x = self.pool(F.relu(self.bn4(self.conv4(x)))) | |
x = x.view(x.size(0), -1) | |
x = F.relu(self.fc1(x)) | |
x = self.dropout(x) | |
x = self.fc2(x) | |
return x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment