File size: 1,193 Bytes
f664fd4
d61c0d5
f664fd4
4899ca0
f664fd4
4899ca0
f664fd4
4899ca0
d8b523b
4899ca0
 
ec3de94
4899ca0
ec3de94
4899ca0
ec3de94
 
4899ca0
ec3de94
d8b523b
ec3de94
 
 
 
 
 
 
 
 
 
 
 
 
4899ca0
 
ec3de94
 
 
d8b523b
 
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
lat_mean = 39.95177162396873

lat_std = 0.0006333008487451197

lon_mean = -75.19143495078883

lon_std = 0.0006184167829766685

```
# TO RUN: 
from huggingface_hub import hf_hub_download
import torchvision.models as models
import torch
import torch.nn as nn

# Specify the repository and the filename of the model you want to load
repo_id = "cis-5190-final-fall24/ImageToGPSproject_model"  # Replace with your repo name
filename = "final_model.pth"
class ResNetGPSModel(nn.Module):

    def __init__(self):
        super(ResNetGPSModel, self).__init__()
        self.resnet = models.resnet101()  # Updated for PyTorch >=0.13
        self.resnet.fc = nn.Sequential(
            nn.Dropout(0.4),  # Dropout for regularization
            nn.Linear(self.resnet.fc.in_features, 2)  # Latitude and Longitude
        )

    def forward(self, x):
        return self.resnet(x)

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = ResNetGPSModel().to(device)
model_path = hf_hub_download(repo_id=repo_id, filename=filename)

# Load the model using torch
state_dict = torch.load(model_path)
model.load_state_dict(state_dict)
model.eval()  # Set the model to evaluation mode
```