-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_train.py
51 lines (38 loc) · 1.42 KB
/
run_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
import pathlib
import hydra
import omegaconf
import pytorch_lightning as pl
from pytorch_lightning.callbacks import ModelCheckpoint
from torch.utils.data import DataLoader
import data
import models
import utils
@hydra.main(config_path="configs/run_train", config_name="ours")
def train(config: omegaconf.DictConfig):
logger = utils.Logger(**config.wandb)
logger.log_config(config)
dataset = data.HumansDataset(**config.dataset)
data_loader = DataLoader(dataset, **config.data_loader)
if config.resume.id is not None:
checkpoint = models.HumanGAN._get_checkpoint_path(**config.resume)
model = models.HumanGAN.load_from_checkpoint(checkpoint)
else:
checkpoint = None
model = models.HumanGAN(
dataset.resolution,
dataset.num_keypoints,
dataset.num_frames,
kwargs_a=config.augmentation,
kwargs_d=config.discriminator,
kwargs_g=config.generator,
**config.model,
)
logger.log_model_summary(model)
dirpath = pathlib.Path("checkpoints/gan", str(logger.version))
checkpoint_callback = ModelCheckpoint(dirpath, filename="{step:08d}", save_top_k=-1, every_n_train_steps=10000)
trainer = pl.Trainer(
resume_from_checkpoint=checkpoint, logger=logger, callbacks=[checkpoint_callback], **config.trainer,
)
trainer.fit(model, data_loader)
if __name__ == "__main__":
train()