forked from ryanhe312/ABAW2-FPNMAA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmono_fit.py
42 lines (34 loc) · 1.13 KB
/
mono_fit.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
from argparse import ArgumentParser
import pytorch_lightning as pl
import pretty_errors
import yaml
from datasets import *
from model import *
def cli_main():
pl.seed_everything(1234, workers=True)
# ------------
# args
# ------------
parser = ArgumentParser()
parser = pl.Trainer.add_argparse_args(parser)
parser.add_argument('--train', action="store_true")
parser.add_argument('--config', type=str, default=None)
parser.add_argument('--checkpoint', type=str, default=None)
args = parser.parse_args()
# ------------
# trainer
# ------------
trainer = pl.Trainer.from_argparse_args(args)
# ------------
# model
# ------------
model_args = yaml.safe_load(open(args.config, 'r')) if args.config else {}
dm = BalancedDataModule(model_args)
model = MonoPyramidClassifier.load_from_checkpoint(args.checkpoint, strict=False) if args.checkpoint else MonoPyramidClassifier(model_args)
# ------------
# training
# ------------
if args.train: trainer.fit(model, datamodule=dm)
trainer.validate(model, datamodule=dm)
if __name__ == '__main__':
cli_main()