Updated the Efficient Net model
Browse files
README.md
CHANGED
@@ -1,9 +1,55 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
-
|
9 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Image to GPS Model: DINO-ResNet Fusion
|
2 |
+
|
3 |
+
## Training Data Statistics
|
4 |
+
The following mean and standard deviation values were used to normalize the GPS coordinates:
|
5 |
+
|
6 |
+
- **Latitude Mean**: {lat_mean:.6f}
|
7 |
+
- **Latitude Std**: {lat_std:.6f}
|
8 |
+
- **Longitude Mean**: {lon_mean:.6f}
|
9 |
+
- **Longitude Std**: {lon_std:.6f}
|
10 |
+
|
11 |
+
## How to use the model
|
12 |
+
|
13 |
+
Please include the definition of the model first before loading the checkpoint:
|
14 |
+
|
15 |
+
```python
|
16 |
+
# Import all the dependencies
|
17 |
+
import torch
|
18 |
+
import torch.nn as nn
|
19 |
+
import torchvision.models as models
|
20 |
+
import torchvision.transforms as transforms
|
21 |
+
from torch.utils.data import DataLoader, Dataset
|
22 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification, AutoModel
|
23 |
+
from huggingface_hub import PyTorchModelHubMixin
|
24 |
+
from PIL import Image
|
25 |
+
import os
|
26 |
+
import numpy as np
|
27 |
+
|
28 |
+
class EfficientNetGPSModel(nn.Module):
|
29 |
+
def __init__(self, eff_name="efficientnet_b0", num_outputs=2):
|
30 |
+
super(EfficientNetGPSModel, self).__init__()
|
31 |
+
|
32 |
+
# Load the EfficientNet backbone
|
33 |
+
self.efficientnet = getattr(models, eff_name)(pretrained=True)
|
34 |
+
|
35 |
+
# Replace the classifier head while keeping the overall structure simple
|
36 |
+
in_features = self.efficientnet.classifier[1].in_features
|
37 |
+
self.efficientnet.classifier = nn.Sequential(
|
38 |
+
nn.Linear(in_features, num_outputs) # Directly map to GPS coordinates
|
39 |
+
)
|
40 |
+
|
41 |
+
def forward(self, x):
|
42 |
+
return self.efficientnet(x)
|
43 |
+
|
44 |
+
def save_model(self, save_path):
|
45 |
+
self.save_pretrained(save_path)
|
46 |
+
|
47 |
+
def push_model(self, repo_name):
|
48 |
+
self.push_to_hub(repo_name)
|
49 |
+
```
|
50 |
+
|
51 |
+
Then you can download the model from HF by running, and this will also load the checkpoint automatically:
|
52 |
+
|
53 |
+
```python
|
54 |
+
model = EfficientNetGPSModel.from_pretrained("cis519/efficient-net-gps")
|
55 |
+
```
|