-
Notifications
You must be signed in to change notification settings - Fork 11
/
train.py
58 lines (48 loc) · 1.56 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
58
"""
Copyright (c) 2021, Mattia Segu
Licensed under the MIT License (see LICENSE for details)
"""
import sys
import time
import torch
import auxiliary.argument_parser as argument_parser
import auxiliary.my_utils as my_utils
from auxiliary.my_utils import yellow_print
import training.trainer as trainer
opt = argument_parser.parser()
torch.cuda.set_device(opt.multi_gpu[0])
my_utils.plant_seeds(random_seed=opt.random_seed)
trainer = trainer.Trainer(opt)
trainer.build_dataset()
trainer.build_network()
trainer.build_optimizer()
trainer.build_losses()
trainer.start_train_time = time.time()
if opt.demo:
trainer.reload_best_network()
with torch.no_grad():
trainer.demo(opt.demo_input_dir, opt.class_choice)
sys.exit(0)
if opt.run_single_eval:
trainer.reload_best_network()
trainer.flags.build_website = True
with torch.no_grad():
trainer.test_epoch()
sys.exit(0)
trainer.dump_stats()
for epoch in range(trainer.epoch, opt.nepoch):
trainer.train_epoch()
with torch.no_grad():
trainer.test_epoch()
trainer.dump_stats()
trainer.increment_epoch()
trainer.save_network()
# Run eval with best model
trainer.reload_best_network()
with torch.no_grad():
trainer.test_epoch()
trainer.dump_stats()
trainer.demo(opt.demo_input_dir, opt.class_choice)
yellow_print(f"Visdom url http://localhost:{trainer.opt.visdom_port}/")
yellow_print(f"Netvision report url http://localhost:{trainer.opt.http_port}/{trainer.opt.dir_name}/index.html")
yellow_print(f"Training time {(time.time() - trainer.start_time) // 60} minutes.")