sqiud commited on
Commit
ee72481
·
verified ·
1 Parent(s): 6bf7ebb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +22 -14
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/ImageToGPSproject_new_vit" # Replace with your repo name
14
- filename = "resnet_gps_regressor_complete.pth"
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 MultiModalModel(nn.Module):
27
  def __init__(self, num_classes=2):
28
- super(MultiModalModel, self).__init__()
 
 
 
 
 
29
  self.vit = ViTModel.from_pretrained('google/vit-base-patch16-224-in21k')
30
-
31
- # Replace for regression instead of classification
32
  self.regression_head = nn.Sequential(
33
- nn.Linear(self.vit.config.hidden_size, 512),
34
  nn.ReLU(),
35
- nn.Linear(512, num_classes)
36
  )
37
-
38
  def forward(self, x):
39
- outputs = self.vit(pixel_values=x)
40
- # Take the last hidden state (CLS token embedding)
41
- cls_output = outputs.last_hidden_state[:, 0, :]
42
- # Pass through the regression head
43
- gps_coordinates = self.regression_head(cls_output)
 
 
 
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
  ```