Download code/regression_model.py from DeepLense/flowlensing: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/DeepLense/flowlensing/resolve/main/code/regression_model.py
- Command line
-
hf download hf://DeepLense/flowlensing/code/regression_model.py
-
curl -L -o regression_model.py https://huggingface.co/DeepLense/flowlensing/resolve/main/code/regression_model.py
1.26 kB
| 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 |