import torch.nn.functional as F import torch.nn as nn class ImageRegressor(nn.Module): def __init__(self, num_outputs=4): super(ImageRegressor, self).__init__() self.conv1 = nn.Conv2d(1, 32, 3, padding=1) self.bn1 = nn.BatchNorm2d(32) self.conv2 = nn.Conv2d(32, 64, 3, padding=1) self.bn2 = nn.BatchNorm2d(64) self.conv3 = nn.Conv2d(64, 128, 3, padding=1) self.bn3 = nn.BatchNorm2d(128) self.pool = nn.MaxPool2d(2, 2) self.dropout_conv = nn.Dropout2d(0.25) self.dropout_fc = nn.Dropout(0.5) self.fc1 = nn.Linear(128 * 8 * 8, 512) self.fc2 = nn.Linear(512, 128) self.fc3 = nn.Linear(128, num_outputs) def forward(self, x): x = self.pool(F.relu(self.bn1(self.conv1(x)))) x = self.dropout_conv(x) x = self.pool(F.relu(self.bn2(self.conv2(x)))) x = self.dropout_conv(x) x = self.pool(F.relu(self.bn3(self.conv3(x)))) x = self.dropout_conv(x) x = x.view(-1, 128 * 8 * 8) x = F.relu(self.fc1(x)) x = self.dropout_fc(x) x = F.relu(self.fc2(x)) x = self.dropout_fc(x) x = self.fc3(x) return x