Spaces:
Configuration error
Configuration error
Update README.md
Browse files
README.md
CHANGED
|
@@ -10,8 +10,8 @@ from huggingface_hub import hf_hub_download
|
|
| 10 |
import torch
|
| 11 |
|
| 12 |
# Specify the repository and the filename of the model you want to load
|
| 13 |
-
repo_id = "FinalProj5190/
|
| 14 |
-
filename = "
|
| 15 |
|
| 16 |
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
| 17 |
|
|
@@ -23,23 +23,31 @@ model_test.eval() # Set the model to evaluation mode
|
|
| 23 |
The model implementation is here:
|
| 24 |
```
|
| 25 |
from transformers import ViTModel
|
| 26 |
-
class
|
| 27 |
def __init__(self, num_classes=2):
|
| 28 |
-
super(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
self.vit = ViTModel.from_pretrained('google/vit-base-patch16-224-in21k')
|
| 30 |
-
|
| 31 |
-
#
|
| 32 |
self.regression_head = nn.Sequential(
|
| 33 |
-
nn.Linear(self.vit.config.hidden_size,
|
| 34 |
nn.ReLU(),
|
| 35 |
-
nn.Linear(
|
| 36 |
)
|
| 37 |
-
|
| 38 |
def forward(self, x):
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
return gps_coordinates
|
| 45 |
```
|
|
|
|
| 10 |
import torch
|
| 11 |
|
| 12 |
# Specify the repository and the filename of the model you want to load
|
| 13 |
+
repo_id = "FinalProj5190/ImageToGPSproject-resnet_vit-base" # Replace with your repo name
|
| 14 |
+
filename = "resnet_vit_gps_regressor_complete.pth"
|
| 15 |
|
| 16 |
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
| 17 |
|
|
|
|
| 23 |
The model implementation is here:
|
| 24 |
```
|
| 25 |
from transformers import ViTModel
|
| 26 |
+
class HybridGPSModel(nn.Module):
|
| 27 |
def __init__(self, num_classes=2):
|
| 28 |
+
super(HybridGPSModel, self).__init__()
|
| 29 |
+
# Pre-trained ResNet for feature extraction
|
| 30 |
+
self.resnet = resnet18(pretrained=True)
|
| 31 |
+
self.resnet.fc = nn.Identity()
|
| 32 |
+
|
| 33 |
+
# Pre-trained Vision Transformer
|
| 34 |
self.vit = ViTModel.from_pretrained('google/vit-base-patch16-224-in21k')
|
| 35 |
+
|
| 36 |
+
# Combined regression head
|
| 37 |
self.regression_head = nn.Sequential(
|
| 38 |
+
nn.Linear(512 + self.vit.config.hidden_size, 128),
|
| 39 |
nn.ReLU(),
|
| 40 |
+
nn.Linear(128, num_classes)
|
| 41 |
)
|
| 42 |
+
|
| 43 |
def forward(self, x):
|
| 44 |
+
resnet_features = self.resnet(x)
|
| 45 |
+
vit_outputs = self.vit(pixel_values=x)
|
| 46 |
+
vit_features = vit_outputs.last_hidden_state[:, 0, :] # CLS token
|
| 47 |
+
|
| 48 |
+
combined_features = torch.cat((resnet_features, vit_features), dim=1)
|
| 49 |
+
|
| 50 |
+
# Predict GPS coordinates
|
| 51 |
+
gps_coordinates = self.regression_head(combined_features)
|
| 52 |
return gps_coordinates
|
| 53 |
```
|