1、测试输入

# fila_name: temp.py
import tensorflow as tfFLAGS = tf.app.flags.FLAGStf.app.flags.DEFINE_string('string', 'train', 'This is a string')
tf.app.flags.DEFINE_float('learning_rate', 0.001, 'This is the rate in training')
tf.app.flags.DEFINE_boolean('flag', True, 'This is a flag')print('string: ', FLAGS.string)
print('learning_rate: ', FLAGS.learning_rate)
print('flag: ', FLAGS.flag)# python3 tf_app.py --string 'test' --learning_rate 0.2 --flag 0string:  train
learning_rate:  0.001
flag:  True

2、参数传入

import tensorflow as tfFLAGS = tf.app.flags.FLAGStf.app.flags.DEFINE_string('string', 'train', 'This is a string')
tf.app.flags.DEFINE_float('learning_rate', 0.001, 'This is the rate in training')
tf.app.flags.DEFINE_boolean('flag', True, 'This is a flag')def main(_):print('string: ', FLAGS.string)print('learning_rate: ', FLAGS.learning_rate)print('flag: ', FLAGS.flag)def test_name(args):print('字符: ', FLAGS.string)print('学习率: ', FLAGS.learning_rate)print('标示: ', FLAGS.flag)if __name__ == '__main__':# tf.app.run()  # 默认调用maintf.app.run(test_name) #指定函数名调用#python3 tf_run.py --string 'test' --learning_rate 0.2 --flag 0

3、tf.logging机制

当使用tf.logging.set_verbosity(tf.logging.DEBUG)设定日志级别为DEBUG级别时,所有的logging输出都会被打印到屏幕上,

当使用tf.logging.set_verbosity(tf.logging.INFO)设定日志级别为INFO级别时,只有INFO级别及以上的logging会被打印到屏幕上,

当使用tf.logging.set_verbosity(tf.logging.WARN)设定日志级别为WARN级别时,只有WARN级别及以上的logging会被打印到屏幕上,

当使用tf.logging.set_verbosity(tf.logging.ERROR)设定日志级别为ERROR级别时,只有ERROR级别及以上的logging会被打印到屏幕上,

当使用tf.logging.set_verbosity(tf.logging.FATAL)设定日志级别为FATAL级别时,只有FATAL级别及以上的logging会被打印到屏幕上。

import tensorflow as tf
import numpy as nptf.logging.set_verbosity(tf.logging.DEBUG)
# tf.logging.set_verbosity(tf.logging.INFO)
# tf.logging.set_verbosity(tf.logging.WARN)
# tf.logging.set_verbosity(tf.logging.ERROR)
# tf.logging.set_verbosity(tf.logging.FATAL)
tf.logging.debug('Test tf logging output image size: %dx%d' % (100, 100))
tf.logging.info('Test tf logging output image  size: %dx%d' % (100, 100))
tf.logging.warn('Test tf logging output image  size: %dx%d' % (100, 100))
tf.logging.error('Test tf logging output image  size: %dx%d' % (100, 100))
tf.logging.fatal('Test tf logging output image  size: %dx%d' % (100, 100))a = np.array([[1, 0, 0], [0, 1, 1]])
a1 = np.array([[3, 2, 3], [4, 5, 6]])equal_one = tf.equal(a, 1)
equal_one_index = tf.where(equal_one)
new_al = tf.where(tf.equal(a, 1), a1, 1 - a1)with tf.Session() as sess:print('equal_one --------------------------')print(equal_one.eval())print('equal_one_index --------------------------')print(equal_one_index.eval())print('new_al --------------------------')print(new_al.eval())

输出结果:

2021-11-19 14:04:05.524456: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2021-11-19 14:04:05.543600: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2299965000 Hz
2021-11-19 14:04:05.543867: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x28dabf0 executing computations on platform Host. Devices:
2021-11-19 14:04:05.543880: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
2021-11-19 14:04:05.545813: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set.  If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU.  To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.
equal_one --------------------------
[[ True False False][False  True  True]]
equal_one_index --------------------------
[[0 0][1 1][1 2]]
new_al --------------------------
[[ 3 -1 -2][-3  5  6]]

4、tf.app.flags机制

import tensorflow as tfFLAGS = tf.app.flags.FLAGStf.app.flags.DEFINE_string('train_directory', './','Training data directory')
tf.app.flags.DEFINE_string('string', 'train', 'This is a string')
tf.app.flags.DEFINE_float('learning_rate', 0.001, 'This is the rate in training')
tf.app.flags.DEFINE_boolean('flag', True, 'This is a flag')def main(unuse_args):print('train_directory', FLAGS.train_directory)print('string: ', FLAGS.string)print('learning_rate: ', FLAGS.learning_rate)print('flag: ', FLAGS.flag)if __name__ == '__main__':tf.app.run()
# python tf_flag.py --train_directory test1  --string test2 --learning_rate 0.002 --flag T

输出结果:

WARNING:tensorflow:From tf_flag.py:20: The name tf.app.run is deprecated. Please use tf.compat.v1.app.run instead.train_directory test1
string:  test2
learning_rate:  0.002
flag:  True

参考:https://blog.csdn.net/u011089570/article/details/99636150

简单使用tf.app.run()、tf.logging和tf.app.flags机制相关推荐

  1. tf.logging.set_verbosity()和tf.app.run()

    用法如下 tf.logging.set_verbosity(tf.logging.INFO)#将日志级别设置为info,也可以设置为ERROR定义在:tensorflow/python/platfor ...

  2. tensorflow2:tf.app.run()

    在很多TensorFlow公布的Demo中,都有这样的代码存在,如下,这是干什么的呢? if __name__ == "__main__": tf.app.run() 我们来看一下 ...

  3. tf.app.flags和tf.app.run的使用

    tf.app.flags和tf.app.run的使用 tf.app.flags主要用于处理命令行参数的解析工作,其实可以理解为一个封装好了的argparse包(argparse是一种结构化的数据存储格 ...

  4. tensorflow代码中tf.app.run()什么意思

    # 前面的代码省略了... ... ... ... def main(argv=None):mnist = input_data.read_data_sets("F:\mydata\Tens ...

  5. tensorflow代码中的tf.app.run()

    一般 if __name__ == '__main__':之后紧接着的是主函数的运行入口,但在tensorflow的代码里头经常可以看到其后面的是tf.app.run(),这个究竟是什么意思呢??? ...

  6. tf.app.run()

    在很多TensorFlow公布的Demo中,都有这样的代码存在,如下,这是干什么的呢? if __name__ == "__main__":tf.app.run() 我们来看一下源 ...

  7. tf.app.flags.DEFINE_string()和tf.app.flags.FLAGS和tf.app.run()

    tf.app.flags tf.app.flags主要用于处理命令行参数的解析工作,其实可以理解为一个封装好了的argparse包(argparse是一种结构化的数据存储格式,类似于Json.XML) ...

  8. tf.logging.set_verbosity(tf.logging.DEBUG)

    在tensorflow中有函数可以直接log打印,这个跟ROS系统中打印函数差不多. TensorFlow使用五个不同级别的日志消息. 按照上升的顺序,它们是DEBUG,INFO,WARN,ERROR ...

  9. TensorFlow 学习(二)—— tf.Graph、tf.Session() 与 tf.Session().run()

    session: with tf.Session() as sess:/ tf.InteractiveSession() 初始化: tf.global_variables_initializer() ...

最新文章

  1. oracle中的sql%rowcount,sql%found、sql%notfound、sql%rowcount和sql%isopen
  2. 成功解决运行tensorflow时ModuleNotFoundError: No module named ‘numpy.core._multiarray_umath‘
  3. mongodb Install the MongoDB service
  4. Android之DiskLruCache(缓存工具)
  5. 比较完整的URL验证
  6. commonJS — 数字操作(for Number)
  7. 全国计算机机专业考试试题,2010全国非计算机专业一级考试试题
  8. 实现查询所有商品功能
  9. 案例:演示out对象的使用及原理分析
  10. android ndk 多线程mk,Android NDK 开发教程六: application.mk
  11. html5期末考试题答案,HTML5期末考试题型
  12. RecyclerView源码学习笔记(一)构造函数和setLayoutManager方法
  13. 百子作业 —— 中国邮递员问题
  14. 学会其中一个,轻松日入400+,今日头条隐藏的6大赚钱功能
  15. 运维之查看服务器cpu、内存、硬盘
  16. 《把时间当作朋友》第1章读后感(一)
  17. android studio TCP客户端通讯
  18. 【Lombok】@Builder | 提供 Builder 形式轻松实现对象创建
  19. fiddler抓包工具:生成证书
  20. 云之梦php免费教学视频下载_[全套视频] 云知梦2017最新PHP工程师全套视频教程 laravel框架版...

热门文章

  1. 【文章】在安达信的日子
  2. S3R:Self-Supervised Sparse Representation for Video Anomaly Detection 【ECCV 2022】
  3. Nodejs学习笔记(十一)--- 数据采集器示例(request和cheerio)
  4. CANopen eds对象字典1007 Synchronous Window Length
  5. 职场 | 2019届毕业生 银行,运营商,外企的笔面试经验(完结)
  6. 将大量文件归类的技巧分享
  7. JavaScript 判断Url格式/判断Uri格式/Link格式/Http地址 正则表达式 亲测
  8. Origin 画不等距数据分布直方图
  9. UE4光源、体积雾、IES
  10. win10同账号多人远程破解