Tensorflow 打印所有tf.flags 参数的方法

32 篇文章 0 订阅
10 篇文章 2 订阅

深度学习离不开大量的参数配置,Tensorflow内置的参数方法 tf.flags 是很多TF使用者的选择

我在设置参数之后想要每次运行程序时打印出所有参数用来核对与记录,费了些功夫找到了方法

不多说,上代码

import tensorflow as tf

Flags=tf.flags

Flags.DEFINE_float('learning_rate', 0.0001, 'The learning rate for the network')
Flags.DEFINE_integer('decay_step', 500000, 'The steps needed to decay the learning rate')
Flags.DEFINE_float('decay_rate', 0.1, 'The decay rate of each decay step')
Flags.DEFINE_string('mode','train', 'The mode of the model train, test.')

FLAGS = Flags.FLAGS

def print_configuration_op(FLAGS):
    print('My Configurations:')
    #pdb.set_trace()
    for name, value in FLAGS.__flags.items():
        value=value.value
        if type(value) == float:
            print(' %s:\t %f'%(name, value))
        elif type(value) == int:
            print(' %s:\t %d'%(name, value))
        elif type(value) == str:
            print(' %s:\t %s'%(name, value))
        elif type(value) == bool:
            print(' %s:\t %s'%(name, value))
        else:
            print('%s:\t %s' % (name, value))
    #for k, v in sorted(FLAGS.__dict__.items()):
        #print(f'{k}={v}\n')        
    print('End of configuration')

def main(argv):
    print_configuration_op(FLAGS)


if __name__ == '__main__':
    tf.app.run()

输出

My Configurations:
 learning_rate:	 0.000100
 decay_step:	 500000
 decay_rate:	 0.100000
 mode:	 train
 h:	 False
 help:	 False
 helpfull:	 False
 helpshort:	 False
End of configuration

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值