-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtrain.py
executable file
·62 lines (50 loc) · 1.94 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import logging
import argparse
import tensorflow as tf
from configs import Config
from configs import build_configs
from trainers import MultiGPUTrainer
from trainers import SingleGPUTrainer
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--detector",
type=str,
default="CenterNet",
help="The detector name, e.g.`efficientdet`, `efficient_fcos`.")
parser.add_argument("--gpus",
type=str,
default="0,1,2,3",
help="Use multi-gpu training or not, default False, means use one gpu.")
parser.add_argument("--cfg",
type=str,
default=None,
help="The conifg file (yaml), if None, using default.")
parser.add_argument("--num_classes",
type=int,
default=80,
help="The number of classes, default 80 (COCO).")
args = parser.parse_args()
os.environ["CUDA_VISIBLE_DEVICES"] = args.gpus
tf.random.set_seed(2333)
# tf.config.optimizer.set_jit(True)
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logging.basicConfig(format="%(asctime)s %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S")
physical_devices = tf.config.experimental.list_physical_devices("GPU")
for device in physical_devices:
tf.config.experimental.set_memory_growth(device, True)
if args.cfg is None:
cfg = build_configs(args.detector)(args.num_classes)
else:
cfg = Config()
cfg.parse_from_yaml(args.cfg)
num_gpus = len(args.gpus.strip().split(","))
if num_gpus > 1:
trainer = MultiGPUTrainer(cfg=cfg, logger=logger)
else:
trainer = SingleGPUTrainer(cfg=cfg, logger=logger)
trainer.run()
if __name__ == '__main__':
main()