46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
import torch.nn as nn
|
|
|
|
class DogCatClassifier(nn.Module):
|
|
def __init__ (self):
|
|
super().__init__()
|
|
|
|
self.conv1 = nn.Sequential(
|
|
nn.Conv2d(3, 32, 3, padding = 1),
|
|
nn.ReLU(inplace = True),
|
|
nn.MaxPool2d(2),
|
|
nn.BatchNorm2d(32)
|
|
)
|
|
|
|
self.conv2 = nn.Sequential(
|
|
nn.Conv2d(32, 64, 3, padding = 1),
|
|
nn.ReLU(inplace = True),
|
|
nn.MaxPool2d(2),
|
|
nn.BatchNorm2d(64)
|
|
)
|
|
|
|
self.conv3 = nn.Sequential(
|
|
nn.Conv2d(64, 128, 3, padding = 1),
|
|
nn.ReLU(inplace = True),
|
|
nn.MaxPool2d(2),
|
|
nn.BatchNorm2d(128)
|
|
)
|
|
|
|
self.fc1 = nn.Linear(128 * 4 * 4 , 512)# 2048, lowkey had to calculator it lol
|
|
self.dropout = 0.5 # tunable
|
|
self.fc2 = nn.Linear(512, 1)
|
|
|
|
def forward(self, x):
|
|
x = self.conv1(x)
|
|
x = self.conv2(x)
|
|
x = self.conv3(x)
|
|
x = x.view(x.size(0), -1)
|
|
x = self.fc1(x)
|
|
x = nn.functional.relu(x)
|
|
x = self.fc2(x)
|
|
x = nn.functional.sigmoid(x)
|
|
return x
|
|
|
|
|
|
|
|
|
|
|