File size: 1,087 Bytes
08796e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# SwinGPSModel
## Model Class
```python
class SwinGPSModel(nn.Module):
def __init__(self, pretrained=True):
super(SwinGPSModel, self).__init__()
# Load the pretrained Swin Transformer
self.backbone = create_model('swin_base_patch4_window7_224', pretrained=pretrained)
# Get the number of features from the backbone
num_features = self.backbone.num_features
self.backbone.head = nn.Identity()
# Define the regression head
self.regression_head = nn.Sequential(
nn.AdaptiveAvgPool2d((1, 1)),
nn.Flatten(),
nn.Linear(num_features, 256),
nn.ReLU(),
nn.Linear(256, 2)
)
def forward(self, x):
# Forward pass through the backbone
features = self.backbone(x)
features = features.permute(0, 3, 1, 2)
return self.regression_head(features)
```
## How to Run
In the notebook Run_swin_base.ipynb, replace the line:
```python
dataset_test = load_dataset("gydou/released_img")
```
with the proper location of the testing dataset.
## Training Dataset Statistics
```python
lat_std = 0.0006914493505038013
lon_std = 0.0006539239061573955
lat_mean = 39.9517411499467
lon_mean = -75.19143213125122
``` |