-
Notifications
You must be signed in to change notification settings - Fork 2
/
train.py
executable file
·46 lines (35 loc) · 1.32 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
import argparse
from lavis.common.dist_utils import init_distributed_mode
from lavis.common.logger import setup_logger
from lavis.common.utils import now
from nice.common.config import Config
from nice.common.utils import setup_seeds
from nice.runners.runner_base import RunnerBase
from nice.tasks import NICECaptionTask
def parse_args():
parser = argparse.ArgumentParser(description="Training")
parser.add_argument("--cfg-path", required=True, help="path to configuration file.")
parser.add_argument(
"--options",
nargs="+",
help="override some settings in the used config, the key-value pair "
"in xxx=yyy format will be merged into config file (deprecate), "
"change to --cfg-options instead.",
)
args = parser.parse_args()
return args
def main():
job_id = now()
cfg = Config(parse_args())
init_distributed_mode(cfg.run_cfg)
setup_seeds(cfg)
# set after init_distributed_mode() to only log on master.
setup_logger()
cfg.pretty_print()
task = NICECaptionTask.setup_task(cfg)
datasets = task.build_datasets(cfg)
model = task.build_model(cfg)
runner = RunnerBase(cfg=cfg, job_id=job_id, task=task, model=model, datasets=datasets)
runner.train()
if __name__ == "__main__":
main()