-
Notifications
You must be signed in to change notification settings - Fork 34
/
train.py
32 lines (23 loc) · 1.05 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
from argparse import ArgumentParser
import pytorch_lightning as pl
from omegaconf import OmegaConf
import torch
from utils.common import instantiate_from_config, load_state_dict
def main() -> None:
parser = ArgumentParser()
parser.add_argument("--config", type=str, default='configs/train_ccsr_stage2.yaml')
args = parser.parse_args()
config = OmegaConf.load(args.config)
pl.seed_everything(config.lightning.seed, workers=True)
data_module = instantiate_from_config(config.data)
model = instantiate_from_config(OmegaConf.load(config.model.config))
# TODO: resume states saved in checkpoint.
if config.model.get("resume"):
load_state_dict(model, torch.load(config.model.resume, map_location="cpu"), strict=True)
callbacks = []
for callback_config in config.lightning.callbacks:
callbacks.append(instantiate_from_config(callback_config))
trainer = pl.Trainer(callbacks=callbacks, **config.lightning.trainer)
trainer.fit(model, datamodule=data_module)
if __name__ == "__main__":
main()