-
Notifications
You must be signed in to change notification settings - Fork 119
/
runner.py
executable file
·93 lines (78 loc) · 2.93 KB
/
runner.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# Developed by Haozhe Xie <cshzxie@gmail.com>
import logging
import matplotlib
import multiprocessing as mp
import numpy as np
import os
import sys
# Fix problem: no $DISPLAY environment variable
matplotlib.use('Agg')
from argparse import ArgumentParser
from datetime import datetime as dt
from pprint import pprint
from config import cfg
from core.train import train_net
from core.test import test_net
def get_args_from_command_line():
parser = ArgumentParser(description='Parser of Runner of Pix2Vox')
parser.add_argument('--gpu',
dest='gpu_id',
help='GPU device id to use [cuda0]',
default=cfg.CONST.DEVICE,
type=str)
parser.add_argument('--rand', dest='randomize', help='Randomize (do not use a fixed seed)', action='store_true')
parser.add_argument('--test', dest='test', help='Test neural networks', action='store_true')
parser.add_argument('--batch-size',
dest='batch_size',
help='name of the net',
default=cfg.CONST.BATCH_SIZE,
type=int)
parser.add_argument('--epoch', dest='epoch', help='number of epoches', default=cfg.TRAIN.NUM_EPOCHES, type=int)
parser.add_argument('--weights', dest='weights', help='Initialize network from the weights file', default=None)
parser.add_argument('--out', dest='out_path', help='Set output path', default=cfg.DIR.OUT_PATH)
args = parser.parse_args()
return args
def main():
# Get args from command line
args = get_args_from_command_line()
if args.gpu_id is not None:
cfg.CONST.DEVICE = args.gpu_id
if not args.randomize:
np.random.seed(cfg.CONST.RNG_SEED)
if args.batch_size is not None:
cfg.CONST.BATCH_SIZE = args.batch_size
if args.epoch is not None:
cfg.TRAIN.NUM_EPOCHES = args.epoch
if args.out_path is not None:
cfg.DIR.OUT_PATH = args.out_path
if args.weights is not None:
cfg.CONST.WEIGHTS = args.weights
if not args.test:
cfg.TRAIN.RESUME_TRAIN = True
# Print config
print('Use config:')
pprint(cfg)
# Set GPU to use
if type(cfg.CONST.DEVICE) == str:
os.environ["CUDA_VISIBLE_DEVICES"] = cfg.CONST.DEVICE
# Start train/test process
if not args.test:
train_net(cfg)
else:
if 'WEIGHTS' in cfg.CONST and os.path.exists(cfg.CONST.WEIGHTS):
test_net(cfg)
else:
print('[FATAL] %s Please specify the file path of checkpoint.' % (dt.now()))
sys.exit(2)
if __name__ == '__main__':
# Check python version
if sys.version_info < (3, 0):
raise Exception("Please follow the installation instruction on 'https://github.com/hzxie/Pix2Vox'")
# Setup logger
mp.log_to_stderr()
logger = mp.get_logger()
logger.setLevel(logging.INFO)
main()