def __init__(self, net, cfg, data_iter=None, log_name='logs.txt'): self._input_list = [] self._output_list = [] self._outputs = [] self.graph_ops = None self.cfg = cfg self.net = net self.cur_epoch = 0 self.summary_dict = {} # timer self.tot_timer = Timer() self.gpu_timer = Timer() self.read_timer = Timer() # logger self.logger = colorlogger(self.cfg.log_dir, log_name=log_name) # initialize tensorflow tfconfig = tf.ConfigProto(allow_soft_placement=True, log_device_placement=False) tfconfig.gpu_options.allow_growth = True self.sess = tf.Session(config=tfconfig) # build_graph self.build_graph() # get data iter self._data_iter = data_iter
parser.add_argument('--model', '-m', type=str, dest='test_model') args = parser.parse_args() # test gpus if not args.gpu_ids: args.gpu_ids = str(np.argmin(mem_info())) if '-' in args.gpu_ids: gpus = args.gpu_ids.split('-') gpus[0] = 0 if not gpus[0].isdigit() else int(gpus[0]) gpus[1] = len(mem_info()) if not gpus[1].isdigit() else int(gpus[1]) + 1 args.gpu_ids = ','.join(map(lambda x: str(x), list(range(*gpus)))) if args.test_epochs and not ',' in args.test_epochs: args.test_epochs = '%d,%d' % (int(args.test_epochs), int(args.test_epochs) + 1) assert args.test_epochs or args.test_model, 'Test epoch or model to test is required.' return args global args args = parse_args() if args.test_model: logger = colorlogger(cfg.output_dir, 'test_model_{}'.format(args.test_model.split('/')[-1].split('.')[0])) test(args.test_model, logger) else: for i in range(*eval(args.test_epochs)): log_name = 'test_epoch_{}.logs'.format(i) logger = colorlogger(cfg.output_dir, log_name) test(i, logger)