Update README.md
Browse files
README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
-
|
2 |
latitude_std: 0.0006308700565432299
|
3 |
longitude_mean: -75.19147985909444
|
4 |
longitude_std: 0.0006379960634765379
|
5 |
|
6 |
To run input tensors to `predict_from_model(input_tensor)`:
|
7 |
|
|
|
8 |
```
|
9 |
import torch
|
10 |
import torch.nn as nn
|
@@ -24,10 +25,13 @@ def predict_from_model(input_tensor):
|
|
24 |
from datasets import load_dataset
|
25 |
from huggingface_hub import hf_hub_download
|
26 |
import numpy as np
|
|
|
|
|
|
|
27 |
#############
|
28 |
path_map = {"best region models/region_model_lr_0.0002_step_10_gamma_0.1_epochs_15.pth" : hf_hub_download(repo_id="IanAndJohn/region_ensemble_model", filename="best region models/region_model_lr_0.0002_step_10_gamma_0.1_epochs_15.pth"),
|
29 |
"best region models/region_model_lr_0.00035_step_10_gamma_0.1_epochs_50.pth" : hf_hub_download(repo_id="IanAndJohn/region_ensemble_model", filename="best region models/region_model_lr_0.00035_step_10_gamma_0.1_epochs_50.pth"),
|
30 |
-
"best region models/region_model_lr_0.0005_step_10_gamma_0.1_epochs_50.pth" : hf_hub_download(repo_id="IanAndJohn/region_ensemble_model", filename="best region models/region_model_lr_0.0005_step_10_gamma_0.1_epochs_50.pth"),
|
31 |
"best region models/region_model_lr_0.0005_step_10_gamma_0.1_epochs_60.pth" : hf_hub_download(repo_id="IanAndJohn/region_ensemble_model", filename="best region models/region_model_lr_0.0005_step_10_gamma_0.1_epochs_60.pth"),
|
32 |
"best region models/region_model_lr_0.002_step_10_gamma_0.1_epochs_100.pth" : hf_hub_download(repo_id="IanAndJohn/region_ensemble_model", filename="best region models/region_model_lr_0.002_step_10_gamma_0.1_epochs_100.pth"),
|
33 |
"best region models/model_histories.json" : hf_hub_download(repo_id="IanAndJohn/region_ensemble_model", filename="best region models/model_histories.json"),
|
@@ -138,7 +142,7 @@ def predict_from_model(input_tensor):
|
|
138 |
def __init__(self, tensors, transform=None, lat_mean=None, lat_std=None, lon_mean=None, lon_std=None, useRegions=False, give_originals=False):
|
139 |
# self.hf_dataset = hf_dataset.map(
|
140 |
self.tensors = tensors
|
141 |
-
|
142 |
def __len__(self):
|
143 |
return len(self.tensors)
|
144 |
|
@@ -204,7 +208,7 @@ def predict_from_model(input_tensor):
|
|
204 |
class_weights = [0.2839, 0.4268, 0.5583, 0.3873, 1.0000, 0.6036, 0.6009]
|
205 |
#####################
|
206 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
207 |
-
print(f'Using device: {device}')
|
208 |
|
209 |
per_model_weights = []
|
210 |
with open(path_map['region_ensemble_weights.json'], 'r') as file:
|
@@ -279,6 +283,7 @@ def predict_from_model(input_tensor):
|
|
279 |
po_predicted_region_lst[po.predicted_region].append(po)
|
280 |
|
281 |
po_datasets = [PredictionObjectDataset(x, give_originals=True) for x in po_predicted_region_lst]
|
|
|
282 |
po_loaders = [DataLoader(x, batch_size=32, shuffle=False) for x in po_datasets]
|
283 |
|
284 |
# lat_mean_lst = [x.latitude_mean for x in po_datasets]
|
@@ -305,6 +310,8 @@ def predict_from_model(input_tensor):
|
|
305 |
# model_all_regions = []
|
306 |
|
307 |
val_dataloader = po_loaders[i]
|
|
|
|
|
308 |
|
309 |
state_dict = torch.load(path_map[f'models/location_model_{i}.pth'])
|
310 |
|
@@ -360,6 +367,7 @@ def predict_from_model(input_tensor):
|
|
360 |
# all_preds.append([model_all_preds])
|
361 |
# all_actuals.append([model_all_actuals])
|
362 |
all_preds_norm.append([model_all_preds_norm])
|
|
|
363 |
# all_actuals_norm.append([model_all_actuals_norm])
|
364 |
# all_regions.append(model_all_regions)
|
365 |
|
@@ -550,7 +558,4 @@ def predict_from_model(input_tensor):
|
|
550 |
# plt.legend()
|
551 |
# plt.grid(True)
|
552 |
# plt.show()
|
553 |
-
|
554 |
-
torch.cuda.empty_cache()
|
555 |
-
predict_from_model(input)
|
556 |
-
```
|
|
|
1 |
+
atitude_mean: 39.95184413388056
|
2 |
latitude_std: 0.0006308700565432299
|
3 |
longitude_mean: -75.19147985909444
|
4 |
longitude_std: 0.0006379960634765379
|
5 |
|
6 |
To run input tensors to `predict_from_model(input_tensor)`:
|
7 |
|
8 |
+
|
9 |
```
|
10 |
import torch
|
11 |
import torch.nn as nn
|
|
|
25 |
from datasets import load_dataset
|
26 |
from huggingface_hub import hf_hub_download
|
27 |
import numpy as np
|
28 |
+
|
29 |
+
torch.cuda.empty_cache()
|
30 |
+
|
31 |
#############
|
32 |
path_map = {"best region models/region_model_lr_0.0002_step_10_gamma_0.1_epochs_15.pth" : hf_hub_download(repo_id="IanAndJohn/region_ensemble_model", filename="best region models/region_model_lr_0.0002_step_10_gamma_0.1_epochs_15.pth"),
|
33 |
"best region models/region_model_lr_0.00035_step_10_gamma_0.1_epochs_50.pth" : hf_hub_download(repo_id="IanAndJohn/region_ensemble_model", filename="best region models/region_model_lr_0.00035_step_10_gamma_0.1_epochs_50.pth"),
|
34 |
+
"best region models/region_model_lr_0.0005_step_10_gamma_0.1_epochs_50.pth" : hf_hub_download(repo_id="IanAndJohn/region_ensemble_model", filename="best region models/region_model_lr_0.0005_step_10_gamma_0.1_epochs_50.pth"),
|
35 |
"best region models/region_model_lr_0.0005_step_10_gamma_0.1_epochs_60.pth" : hf_hub_download(repo_id="IanAndJohn/region_ensemble_model", filename="best region models/region_model_lr_0.0005_step_10_gamma_0.1_epochs_60.pth"),
|
36 |
"best region models/region_model_lr_0.002_step_10_gamma_0.1_epochs_100.pth" : hf_hub_download(repo_id="IanAndJohn/region_ensemble_model", filename="best region models/region_model_lr_0.002_step_10_gamma_0.1_epochs_100.pth"),
|
37 |
"best region models/model_histories.json" : hf_hub_download(repo_id="IanAndJohn/region_ensemble_model", filename="best region models/model_histories.json"),
|
|
|
142 |
def __init__(self, tensors, transform=None, lat_mean=None, lat_std=None, lon_mean=None, lon_std=None, useRegions=False, give_originals=False):
|
143 |
# self.hf_dataset = hf_dataset.map(
|
144 |
self.tensors = tensors
|
145 |
+
|
146 |
def __len__(self):
|
147 |
return len(self.tensors)
|
148 |
|
|
|
208 |
class_weights = [0.2839, 0.4268, 0.5583, 0.3873, 1.0000, 0.6036, 0.6009]
|
209 |
#####################
|
210 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
211 |
+
# print(f'Using device: {device}')
|
212 |
|
213 |
per_model_weights = []
|
214 |
with open(path_map['region_ensemble_weights.json'], 'r') as file:
|
|
|
283 |
po_predicted_region_lst[po.predicted_region].append(po)
|
284 |
|
285 |
po_datasets = [PredictionObjectDataset(x, give_originals=True) for x in po_predicted_region_lst]
|
286 |
+
# print([len(ds) for ds in po_datasets])
|
287 |
po_loaders = [DataLoader(x, batch_size=32, shuffle=False) for x in po_datasets]
|
288 |
|
289 |
# lat_mean_lst = [x.latitude_mean for x in po_datasets]
|
|
|
310 |
# model_all_regions = []
|
311 |
|
312 |
val_dataloader = po_loaders[i]
|
313 |
+
if (len(val_dataloader) == 0):
|
314 |
+
continue
|
315 |
|
316 |
state_dict = torch.load(path_map[f'models/location_model_{i}.pth'])
|
317 |
|
|
|
367 |
# all_preds.append([model_all_preds])
|
368 |
# all_actuals.append([model_all_actuals])
|
369 |
all_preds_norm.append([model_all_preds_norm])
|
370 |
+
# print("images predicted: ", len(all_preds_norm))
|
371 |
# all_actuals_norm.append([model_all_actuals_norm])
|
372 |
# all_regions.append(model_all_regions)
|
373 |
|
|
|
558 |
# plt.legend()
|
559 |
# plt.grid(True)
|
560 |
# plt.show()
|
561 |
+
```
|
|
|
|
|
|