【tensorflow】命令行参数解析

1. tf.app.flags,用于支持接受命令行传递参数

import tensorflow as tf
#第一个是参数名称,第二个参数是默认值,第三个是参数描述
tf.app.flags.DEFINE_string('str_name', 'def_v_1',"descrip1")
tf.app.flags.DEFINE_integer('int_name', 10,"descript2")
tf.app.flags.DEFINE_boolean('bool_name', False, "descript3")
FLAGS = tf.app.flags.FLAGS

调用参数:FLAGS.int_name = 14
python tt.py --str_name test_str --int_name 99 --bool_name True

  1. 使用argparse包
parser = argparse.ArgumentParser()
parser.add_argument("--input_dir", help="path to folder containing images")
parser.add_argument("--mode", required=True, choices=["train", "test", "export"])
parser.add_argument("--output_dir", required=True, help="where to put output files")
parser.add_argument("--seed", type=int)

a = parser.parse_args()
调用参数a.mode = "train"

猜你喜欢

转载自blog.csdn.net/PartyPartyAnimal/article/details/81333026