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