def parse_args(self): """ parse args """ self.set_default_args() #load user defined conf file flags.DEFINE_custom( #'conf_file', args.conf_file, 'load flags from conf file', 'conf_file', './conf/demo_local.conf', 'load flags from conf file', action=LoadConfFile, sec_name="Evaluate") #append additional args self.append_additional_args(FLAGS)
def parse_args(self): """ parse args and load config from conf file """ #init ArgumentParser """ parser = argparse.ArgumentParser() parser.add_argument("--conf_file") args = parser.parse_args() """ """ set the necessary default args. Fault-tolerant in frame, even though the necessary args is not define in user conf file. """ self.set_default_args() #load user defined conf file flags.DEFINE_custom( #'conf_file', args.conf_file, 'load flags from conf file', 'conf_file', './conf/demo_local.conf', 'load flags from conf file', action=LoadConfFile, sec_name="Train") #append additional args self.append_additional_args(FLAGS) if FLAGS.debug_mode: logging.info("base_lr: %f\n" "CUDA_VISIBLE_DEVICES: %s\n" "num_gpus: %d\n" "file_list: %s\n" "dataset_dir: %s\n" % (FLAGS.base_lr, str(FLAGS.cuda_visible_devices), FLAGS.num_gpus, FLAGS.file_list, FLAGS.dataset_dir ) ) return
#fp.close() def test(**kwargs): """ print kwargs """ print(kwargs) if __name__ == "__main__": FLAGS = flags.FLAGS flags.DEFINE_string("test_str", None, "test string") flags.DEFINE_boolean("test_bool", True, "test bool") flags.DEFINE_integer("test_int", None, "test int") flags.DEFINE_float("test_float", None, "test float") flags.DEFINE_custom("conf_file", "./conf/test/test.conf", "conf file", action=LoadConfFile, sec_name="test") print("%s, %s" % (FLAGS.test_str, type(FLAGS.test_str))) print("%s, %s" % (FLAGS.test_bool, type(FLAGS.test_bool))) print("%s, %s" % (FLAGS.test_int, type(FLAGS.test_int))) print("%s, %s" % (FLAGS.test_float, type(FLAGS.test_float))) print("%s, %s" % (FLAGS.conf_file, type(FLAGS.conf_file))) test(**flags.get_flags_dict()) #FLAGS.conf_file.seek(0) #print FLAGS.conf_file.read()
else: label = int(idx < pos_num) yield prefix_input + pos_input + [("label", [label]), ("qid", [logid])] idx += 1 if __name__ == '__main__': from utils import flags from utils.load_conf_file import LoadConfFile FLAGS = flags.FLAGS flags.DEFINE_custom( "conf_file", "./conf/test/test.conf", #"conf file", action=LoadConfFile, sec_name="Train") "conf file", action=LoadConfFile, sec_name="Evaluate") sys.stderr.write('----------- Configuration Arguments -----------\n') for arg, value in sorted(flags.get_flags_dict().items()): sys.stderr.write('%s: %s\n' % (arg, value)) sys.stderr.write('------------------------------------------------\n') dataset_instance = PoiQacPersonalized(FLAGS) def _dump_vec(data, name): print("%s\t%s" % (name, " ".join(map(str, np.array(data))))) def _data_generator():