-
Notifications
You must be signed in to change notification settings - Fork 6
/
train.py
60 lines (44 loc) · 1.79 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
59
import time
from pathlib import Path
from comet_ml import Experiment
import sys
import copy
from models.SonderVITON import SonderFlowEstimator
from utils import load_opts, Timer, set_mode
from data.dataloader import get_loader
from addict import Dict
# from data import CreateDataLoader
# from models import create_model
# from util.visualizer import Visualizer
if __name__ == "__main__":
root = Path(__file__).parent.resolve()
opt_file = "shared/defaults.yml"
opt = load_opts(path=root / opt_file)
# Set up comet experiment:
comet_exp = Experiment(workspace=opt.comet.workspace, project_name=opt.comet.project_name)
if comet_exp is not None:
comet_exp.log_asset(file_data=str(root / opt_file), file_name=root / opt_file)
comet_exp.log_parameters(opt)
opt.comet.exp = comet_exp
opt = set_mode("train", opt)
val_loader = get_loader(opt)
test_display_images = [iter(val_loader).next() for i in range(opt.comet.display_size)]
opt = set_mode("train", opt)
loader = get_loader(opt)
train_display_images = [iter(loader).next() for i in range(opt.comet.display_size)]
model = SonderFlowEstimator()
model.initialize(opt)
model.setup()
total_steps = 0
for epoch in range(opt.train.epochs):
epoch_start_time = time.time()
iter_data_time = time.time()
epoch_iter = 0
for i, data in enumerate(loader):
with Timer("Elapsed time in update " + str(i) + ": %f"):
total_steps += opt.data.loaders.batch_size
epoch_iter += opt.data.loaders.batch_size
model.set_input(Dict(data))
model.optimize_parameters()
if total_steps % opt.val.save_im_freq == 0:
model.save_test_images(test_display_images, total_steps)