Updated Model Inference Information
Browse files- README.md +29 -0
- vit-gps-coordinates-predictor.pth +3 -0
README.md
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
### Train Dataset Means and stds
|
2 |
+
lat_mean = 39.951572994535354
|
3 |
+
lat_std = 0.0006556104083785816
|
4 |
+
lon_mean = -75.19137012508818
|
5 |
+
lon_std = 0.0006895844560639971
|
6 |
+
|
7 |
+
### Custom Model Class
|
8 |
+
from transformers import ViTModel
|
9 |
+
class ViTGPSModel(nn.Module):
|
10 |
+
def __init__(self, output_size=2):
|
11 |
+
super().__init__()
|
12 |
+
self.vit = ViTModel.from_pretrained("google/vit-base-patch16-224-in21k")
|
13 |
+
self.regression_head = nn.Linear(self.vit.config.hidden_size, output_size)
|
14 |
+
|
15 |
+
def forward(self, x):
|
16 |
+
cls_embedding = self.vit(x).last_hidden_state[:, 0, :]
|
17 |
+
return self.regression_head(cls_embedding)
|
18 |
+
|
19 |
+
### Running Inference
|
20 |
+
|
21 |
+
model_path = hf_hub_download(repo_id="Latitude-Attitude/vit-gps-coordinates-predictor", filename="vit-gps-coordinates-predictor.pth")
|
22 |
+
model = torch.load(model_path)
|
23 |
+
model.eval()
|
24 |
+
|
25 |
+
with torch.no_grad():
|
26 |
+
for images in dataloader:
|
27 |
+
images = images.to(device)
|
28 |
+
outputs = model(images)
|
29 |
+
preds = outputs.cpu() * torch.tensor([lat_std, lon_std]) + torch.tensor([lat_mean, lon_mean])
|
vit-gps-coordinates-predictor.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d832691c95c0cf6a291c7611d881524494eac520c3a2f8d39c321cf5b5de193d
|
3 |
+
size 345686610
|