tensorflow中tf.app.run()的含义
来源:互联网 发布:软件数据接口 编辑:程序博客网 时间:2024/05/29 21:36
今天在学习 mnist 代码的时候,看到主函数中有如下的代码:
FLAGS, unparsed = parser.parse_known_args()tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
第一行的含义是对运行命令行时传进来的参数进行解析,如果传进来的参数是之前被add到parser中的,则被传给FLAGS,否则讲传给unpared。
如我们在运行程序时在后面加上了 --epoch 32 参数,如果这个参数之前被加入到parser中,则将parser中的epoch参数更改为32并传诶FLAGS,否则 则将 --epoch 32写入到unparsed中
为了了解第二行的含义,我们在/tensorflow/python/platform中找到app.py并打开。
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.# =============================================================================="""Generic entry point script."""from __future__ import absolute_importfrom __future__ import divisionfrom __future__ import print_functionimport sys as _sysfrom tensorflow.python.platform import flagsfrom tensorflow.python.util.all_util import remove_undocumenteddef _benchmark_tests_can_log_memory(): return Truedef run(main=None, argv=None): """Runs the program with an optional 'main' function and 'argv' list.""" f = flags.FLAGS # Extract the args from the optional `argv` list. args = argv[1:] if argv else None # Parse the known flags from that list, or from the command # line otherwise. # pylint: disable=protected-access flags_passthrough = f._parse_flags(args=args) # pylint: enable=protected-access main = main or _sys.modules['__main__'].main # Call the main function, passing through any arguments # to the final program. _sys.exit(main(_sys.argv[:1] + flags_passthrough))我们给这个方法传递了两个参数,一个是要运行的主方法,另一个是:
argv=[sys.argv[0]] + unparsed这个列表中储存了我们要运行的程序的位置,以及没有被parser匹配的参数。
help中写道run()方法的用途是用argv列表运行一个可选的main方法。
下面的语句将没有被parser匹配的参数放入args中并且通过一个flags对象传入要执行的函数中。
args = argv[1:] if argv else Noneflags_passthrough = f._parse_flags(args=args)如果我们传入了一个函数名,则程序会去用没有匹配的参数执行这个函数,否则,则会用没有匹配的参数去执行__main__。main = main or _sys.modules['__main__'].main_sys.exit(main(_sys.argv[:1] + flags_passthrough))
阅读全文
0 0
- tensorflow中tf.app.run()的含义
- TensorFlow插曲之 tf.app.run()
- Tensorflow tf.app.run() hands-on
- tf.app.run()的作用
- tensorflow学习笔记十四:tensorflow中的tf.app.run()
- TensorFlow 中 tf.app.flags.FLAGS 的用法介绍
- tf.app.run()
- tf.app.run()
- tf.app.run()
- tf.app.run
- TensorFlow学习--tf.session.run()
- tensorflow中tf.maximum,tf.minimum,tf.argmax,tf.argmain的对比
- TensorFlow中flags传递参数 解读tf.app.flags
- tensorflow中tf.random_normal和tf.truncated_normal的区别
- Tensorflow中tf.get_variable和tf.variable_scope的使用
- tensorflow中tf.nn.conv2d_transpose的应用
- TensorFlow中tf.train.exponential_decay的用法
- Tensorflow中axis的含义
- Spring 整合JDBCTemplate
- 桥接模式(Bridge)(对象结构型模式)
- 闭包为何可实现变量持久性
- 手机突然没信号!伪基站究竟是怎样搞鬼的?
- 浅谈js中 call, apply, bind 的区别
- tensorflow中tf.app.run()的含义
- Redis学习(一)概述
- android https 绕证书
- mysql索引类型和索引方法
- 日期格式工具类
- eclipse在选定区域范围内替换文本
- Unsupported major.minor version 51.0解决 maven
- 微信公众号上传图文素材thumb_media_id的获得
- 产品的一生:从需求发现到开发完成上线