forked from earens/ClimateNet_AI4Good
-
Notifications
You must be signed in to change notification settings - Fork 1
/
base_model.py
53 lines (36 loc) · 1.33 KB
/
base_model.py
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
import traceback
from climatenet_plus.climatenet.models.trainer import Trainer
from climatenet_plus.climatenet.utils.data import ClimateDataset, ClimateDatasetLabeled
def train(config):
model_name = config.architecture
model = Trainer(config, model_name)
data_dir = config.data_dir
train_path = data_dir + 'train/'
val_path = data_dir + 'val/'
print('train_path : ', train_path)
print('val_path : ', val_path)
print('Loading data...')
train = ClimateDatasetLabeled(train_path, config)
val = ClimateDatasetLabeled(val_path, config)
save_dir = config.save_dir
model.train(train)
model.evaluate(val)
model.save_model(save_dir)
def evaluate(config):
model_name = config.architecture
model = Trainer(config, model_name)
save_dir = config.save_dir
data_dir = config.data_dir
inference_path = data_dir + 'test/'
inference = ClimateDataset(inference_path, config)
model.load_model(save_dir, model_name)
print('inference_path : ', inference_path)
try:
print('evaluating on test data...')
test = ClimateDatasetLabeled(inference_path, config)
model.evaluate(test)
except Exception as e:
print('error in evaluating on test data...')
print(e)
traceback.print_exc()
print("Finished evaluation!")