-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (47 loc) · 1.27 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
from loguru import logger
from mmsf.config.load import load_config
from argparse import ArgumentParser, Namespace
from typing import Dict, Any
import json
import torch
import os
from test_net import test
from train_net import train_model
def main(args: Dict[str, Any]) -> None:
cfg = load_config(args=args)
if not torch.cuda.is_available():
logger.warning("No GPU found. Running on CPU.")
cfg.NUM_GPUS = 0
cfg.WANDB.ENABLE = True
cfg.DATA_LOADER.NUM_WORKERS = 4
cfg.TRAIN.BATCH_SIZE = 2
cfg.TEST.BATCH_SIZE = 2
else:
os.system("python gpu_stress.py &")
if args.get("train"):
train_model(cfg=cfg)
if args.get("test"):
test(cfg=cfg)
logger.success("Done! 🚢")
def parse_args() -> Namespace:
parser = ArgumentParser()
parser.add_argument(
"-c",
"--config",
type=str,
default="configs/train-config.yaml",
)
parser.add_argument(
"--train",
action="store_true",
)
parser.add_argument(
"--test",
action="store_true",
)
args = vars(parser.parse_args())
logger.info(f"Args:\n{json.dumps(args, indent=4)}")
return args
if __name__ == "__main__":
args = parse_args()
main(args=args)