forked from lkhphuc/pytorch-3d-point-cloud-generation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
train_stg2.py
49 lines (37 loc) · 1.69 KB
/
train_stg2.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
import options
import utils
from trainer import TrainerStage2
if __name__ == "__main__":
print("=======================================================")
print("Train structure generator with joint 2D optimization from novel viewpoints")
print("=======================================================")
cfg = options.get_arguments()
EXPERIMENT = f"{cfg.model}_{cfg.experiment}"
MODEL_PATH = f"models/{EXPERIMENT}"
LOG_PATH = f"logs/{EXPERIMENT}"
utils.make_folder(MODEL_PATH)
utils.make_folder(LOG_PATH)
criterions = utils.define_losses()
dataloaders = utils.make_data_novel(cfg)
#dataloaders = utils.make_data_fixed(cfg)
model = utils.build_structure_generator(cfg).to(cfg.device)
optimizer = utils.make_optimizer(cfg, model)
scheduler = utils.make_lr_scheduler(cfg, optimizer)
logger = utils.make_logger(LOG_PATH)
writer = utils.make_summary_writer(EXPERIMENT)
def on_after_epoch(model, df_hist, images, epoch, saveEpoch):
utils.save_best_model(MODEL_PATH, model, df_hist)
utils.checkpoint_model(MODEL_PATH, model, epoch, saveEpoch)
utils.log_hist(logger, df_hist)
utils.write_on_board_losses_stg2(writer, df_hist)
utils.write_on_board_images_stg2(writer, images, epoch)
if cfg.lrSched is not None:
def on_after_batch(iteration):
utils.write_on_board_lr(writer, scheduler.get_lr(), iteration)
scheduler.step()
else: on_after_batch = None
trainer = TrainerStage2(
cfg, dataloaders, criterions, on_after_epoch, on_after_batch)
hist = trainer.train(model, optimizer, scheduler)
hist.to_csv(f"{LOG_PATH}.csv", index=False)
writer.close()