forked from ml-lab/TensorBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
executable file
·38 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
import argparse
import os
import json
import datetime
from model import TensorBox
def main():
'''
Parse command line arguments and return the hyperparameter dictionary H.
H first loads the --hypes hypes.json file and is further updated with
additional arguments as needed.
'''
parser = argparse.ArgumentParser()
parser.add_argument('--weights', default=None, type=str)
parser.add_argument('--gpu', default=None, type=int)
parser.add_argument('--hypes', required=True, type=str)
parser.add_argument('--max_iter', required=False, type=int, default=None)
parser.add_argument('--logdir', default='output', type=str)
args = parser.parse_args()
with open(args.hypes, 'r') as f:
H = json.load(f)
if args.gpu is not None:
H['solver']['gpu'] = args.gpu
if args.max_iter is not None:
H['solver']['max_iter'] = args.max_iter
if len(H.get('exp_name', '')) == 0:
H['exp_name'] = args.hypes.split('/')[-1].replace('.json', '')
H['save_dir'] = args.logdir + '/%s_%s' % (H['exp_name'],
datetime.datetime.now().strftime('%Y_%m_%d_%H.%M'))
if args.weights is not None:
H['solver']['weights'] = args.weights
os.environ['CUDA_VISIBLE_DEVICES'] = str(args.gpu)
tensorbox = TensorBox(H)
tensorbox.train()
if __name__ == '__main__':
main()