-
Notifications
You must be signed in to change notification settings - Fork 12
/
train.py
57 lines (44 loc) · 1.63 KB
/
train.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
53
54
55
56
57
"""
Example usage: CUDA_VISIBLE_DEVICES=1, python train.py --settings_file "config/settings_DDD17.yaml"
"""
import argparse
import wandb
from config.settings import Settings
from training.ess_trainer import ESSModel
from training.ess_supervised_trainer import ESSSupervisedModel
import numpy as np
import torch
import random
import os
# random seed
seed_value = 6
np.random.seed(seed_value)
random.seed(seed_value)
os.environ['PYTHONHASHSEED'] = str(seed_value)
torch.manual_seed(seed_value)
torch.cuda.manual_seed(seed_value)
torch.cuda.manual_seed_all(seed_value)
torch.backends.cudnn.deterministic = True
def main():
parser = argparse.ArgumentParser(description='Train network.')
parser.add_argument('--settings_file', help='Path to settings yaml', required=True)
args = parser.parse_args()
settings_filepath = args.settings_file
settings = Settings(settings_filepath, generate_log=True)
wandb.init(name=(settings.dataset_name_b.split("_")[0] + '_' + settings.timestr), project="zhaoning_sun_semester_thesis", entity="zhasun", sync_tensorboard=True)
if settings.model_name == 'ess':
trainer = ESSModel(settings)
elif settings.model_name == 'ess_supervised':
trainer = ESSSupervisedModel(settings)
else:
raise ValueError('Model name %s specified in the settings file is not implemented' % settings.model_name)
wandb.config = {
"random_seed": seed_value,
"lr_front": settings.lr_front,
"lr_back": settings.lr_back,
"batch_size_a": settings.batch_size_a,
"batch_size_b": settings.batch_size_b
}
trainer.train()
if __name__ == "__main__":
main()