Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Dataset stats: \
|
2 |
+
lat_mean = 39.951564548022596 \
|
3 |
+
lat_std = 0.0006361722351128644 \
|
4 |
+
lon_mean = -75.19150880602636 \
|
5 |
+
lon_std = 0.000611411894337979
|
6 |
+
|
7 |
+
The model can be loaded using:
|
8 |
+
```
|
9 |
+
from huggingface_hub import hf_hub_download
|
10 |
+
import torch
|
11 |
+
# Specify the repository and the filename of the model you want to load
|
12 |
+
repo_id = "FinalProj5190/ImageToGPSproject-resnet_vit-base" # Replace with your repo name
|
13 |
+
filename = "resnet_vit_gps_regressor_complete.pth"
|
14 |
+
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
15 |
+
# Load the model using torch
|
16 |
+
model_test = torch.load(model_path)
|
17 |
+
model_test.eval() # Set the model to evaluation mode
|
18 |
+
```
|
19 |
+
|
20 |
+
The model implementation is here:
|
21 |
+
```
|
22 |
+
from transformers import ViTModel
|
23 |
+
class HybridGPSModel(nn.Module):
|
24 |
+
def __init__(self, num_classes=2):
|
25 |
+
super(HybridGPSModel, self).__init__()
|
26 |
+
# Pre-trained ResNet for feature extraction
|
27 |
+
self.resnet = resnet18(pretrained=True)
|
28 |
+
self.resnet.fc = nn.Identity()
|
29 |
+
# Pre-trained Vision Transformer
|
30 |
+
self.vit = ViTModel.from_pretrained('google/vit-base-patch16-224-in21k')
|
31 |
+
# Combined regression head
|
32 |
+
self.regression_head = nn.Sequential(
|
33 |
+
nn.Linear(512 + self.vit.config.hidden_size, 128),
|
34 |
+
nn.ReLU(),
|
35 |
+
nn.Linear(128, num_classes)
|
36 |
+
)
|
37 |
+
def forward(self, x):
|
38 |
+
resnet_features = self.resnet(x)
|
39 |
+
vit_outputs = self.vit(pixel_values=x)
|
40 |
+
vit_features = vit_outputs.last_hidden_state[:, 0, :] # CLS token
|
41 |
+
combined_features = torch.cat((resnet_features, vit_features), dim=1)
|
42 |
+
# Predict GPS coordinates
|
43 |
+
gps_coordinates = self.regression_head(combined_features)
|
44 |
+
return gps_coordinates
|
45 |
+
```
|