File size: 1,794 Bytes
56daab4 27672e7 715ab45 |
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 46 47 48 49 50 51 52 53 54 55 56 57 |
lat_mean=39.951853021309034
lat_std=0.0005336591548786815
lon_mean=-75.19122782343982
lon_std=0.0004335530163099028
---
license: mit
---
#ResNet GPS Prediction Model
This model predicts GPS coordinates (latitude and longitude) from input images using a custom ResNet-based architecture.
##How to Use
1. Download `resnet_gps_model.pth` and `config.json` from this repository.
2. Define the model architecture (as shown in the usage example below).
3. Load the model weights and configuration.
## Example Usage
```python
import torch
import json
# Load config
config = json.load(open("config.json", "r"))
# Define and load model
resnet = CustomResNetModel(model_name="microsoft/resnet-18", num_classes=config["num_classes"])
state_dict = torch.load("resnet_gps_model.pth")
resnet.load_state_dict(state_dict)
resnet.eval()
This is our customresnetmodel
class CustomResNetModel(nn.Module):
def __init__(self, model_name="microsoft/resnet-18", num_classes=2):
super(CustomResNetModel, self).__init__()
# Load pre-trained ResNet from Hugging Face
self.resnet = AutoModelForImageClassification.from_pretrained(model_name)
# Adjust the classifier layer to output the desired number of classes
in_features = self.resnet.classifier[0].in_features # Assuming the last layer is a Linear layer
self.resnet.classifier = nn.Sequential(
nn.Flatten(),
nn.Linear(in_features, num_classes)
)
def forward(self, x):
return self.resnet(x)
def save_model(self, save_path):
"""Save model locally using the Hugging Face format."""
self.save_pretrained(save_path)
def push_model(self, repo_name):
"""Push the model to the Hugging Face Hub."""
self.push_to_hub(repo_name)
|