1. 程式人生 > >tensorflow 使用flags定義命令列引數的方法

tensorflow 使用flags定義命令列引數的方法

tf定義了tf.app.flags,用於支援接受命令列傳遞引數,相當於接受argv。

FLAGS = tf.app.flags.FLAGS
#第一個引數是引數名稱,第二個是引數預設值,第三個是引數描述
tf.app.flags.DEFINE_string(
    'dataset_name', 'pascalvoc',
    'The name of the dataset to convert.')
tf.app.flags.DEFINE_string(
    'dataset_dir', None,
    'Directory where the original dataset is stored.')
tf.app.flags.DEFINE_string(
    'output_name', 'pascalvoc',
    'Basename used for TFRecords output files.')
tf.app.flags.DEFINE_string(
    'output_dir', './',
    'Output directory where to store TFRecords files.')

 

在命令列中使用的方式:

python  tf_convert_data.py     \
    --dataset_name=pascalvoc    \
    --dataset_dir=./voc2007/     \
    --output_name=voc_2007_train \
    --output_dir=./records