在很多TensorFlow公布的Demo中,都有这样的代码存在,如下,这是干什么的呢?

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

我们来看一下源代码:

# tensorflow/tensorflow/python/platform/default/_app.py

# Copyright 2015 Google Inc. 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_import
from __future__ import division
from __future__ import print_function

import sys

from tensorflow.python.platform import flags

def run(main=None):
  f = flags.FLAGS
  f._parse_flags()
  main = main or sys.modules['__main__'].main
  sys.exit(main(sys.argv))

处理flag解析,然后执行main函数,那么flag解析是什么意思呢?诸如这样的:

tf.app.flags.DEFINE_boolean("self_test", False, "True if running a self test.")
tf.app.flags.DEFINE_boolean('use_fp16', False,
                            "Use half floats instead of full floats if True.")
FLAGS = tf.app.flags.FLAGS

参考资料

http://stackoverflow.com/questions/33703624/how-does-tf-app-run-work

tf.app.run()的更多相关文章

  1. tensorflow中的tf.app.run()的使用

    指明函数的入口,即从哪里执行函数. 如果你的代码中的入口函数不叫main(),而是一个其他名字的函数,如test(),则你应该这样写入口tf.app.run(test()) 如果你的代码中的入口函数叫 ...

  2. tf.app.run() got unexpected keyword argument 'argv'

    运行的代码是mnist_with_summaries.py.出现的问题是 tf.app.run() got unexpected keyword argument 'argv' 昨天一直以为是我自己不 ...

  3. tf.app.run()的作用

    tf.app.run() 如果你的代码中的入口函数不叫main(),而是一个其他名字的函数,如test(),则你应该这样写入口tf.app.run(test) 如果你的代码中的入口函数叫main(), ...

  4. tf.app.run() 运行结束时,报错:SystemExit exception: no description

    环境:Python3.6.6 + tensorflow-gpu 源码如下: import tensorflow as tf def main(): print("hello tf.app.r ...

  5. tensorflow2:tf.app.run()

    在很多TensorFlow公布的Demo中,都有这样的代码存在,如下,这是干什么的呢? 我们来看一下源代码: # tensorflow/tensorflow/python/platform/defau ...

  6. TensorFlow学习笔记之--[tf.app.flags使用方法]

    很多时候在运行python代码的时候我们需要从外部定义参数,从而避免每次都需要改动代码.所以一般我们都会使用 argparse 这个库.其实TensorFlow也提供了这个功能,那就是 tf.app. ...

  7. TensorFlow tf.app&tf.app.flags用法介绍

    TensorFlow tf.app&tf.app.flags用法介绍 TensorFlow tf.app argparse  tf.app.flags 下面介绍 tf.app.flags.FL ...

  8. 【转载】 TensorFlow tf.app&tf.app.flags用法介绍

    作 者:marsggbo 出 处:https://www.cnblogs.com/marsggbo版权声明:署名 - 非商业性使用 - 禁止演绎,协议普通文本 | 协议法律文本. ---------- ...

  9. tensorflow API _ 2 (tf.app.flags.FLAGS)

    tf.app.flags.FLAGS 的使用,主要是在用命令行执行程序时,需要传些参数,代码如下:新建一个名为:app_flags.py 的文件. #coding:utf-8  import tens ...

随机推荐

  1. [SDOI2016]储能表

    Description 有一个 n 行 m 列的表格,行从 0 到 n−1 编号,列从 0 到 m−1 编号.每个格子都储存着能量.最初,第 i 行第 j 列的格子储存着 (i xor j) 点能量. ...

  2. 【LSGDOJ 1850】滑雪课程

    题目描述 贝西去科罗拉多州去滑雪,不过还她不太会玩,只是个能力为 1 的渣渣.贝西从 0 时刻进入滑雪场,一到 T 时刻就必须离开.滑雪场里有 N 条斜坡,第 i 条斜坡滑行一次需要 D i 分钟,要 ...

  3. ●BZOJ 4698 Sdoi2008 Sandy的卡片

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=4698 题解: 后缀数组,二分这个题还是比较套路的.首先依据题意,把各个串差分以后,用分割符号 ...

  4. 用js来实现那些数据结构11(字典)

    我们这篇文章来说说Map这种数据结构如何用js来实现,其实它和集合(Set)极为类似,只不过Map是[键,值]的形式存储元素,通过键来查询值,Map用于保存具有映射关系的数据,Map里保存着两组数据: ...

  5. Java并发编程:JMM(Java内存模型)和volatile

    1. 并发编程的3个概念 并发编程时,要想并发程序正确地执行,必须要保证原子性.可见性和有序性.只要有一个没有被保证,就有可能会导致程序运行不正确. 1.1. 原子性 原子性:即一个或多个操作要么全部 ...

  6. Unity3d 简单的小球沿贝塞尔曲线运动(适合场景漫游使用)

        简单的小球沿贝塞尔曲线运动,适合场景漫游使用 贝塞尔曲线:(贝塞尔曲线的基本想法部分摘自http://blog.csdn.net/u010019717/article/details/4768 ...

  7. c++读写MySQL

    看过很多C或是C++操作MySQL数据库的文章,大部分太吃力了,甚至有一部分根本没有很好的组织文字,初学者比较难以接受,即使是C++或是C高手也是比较难看懂.写这篇文章的目的不是别的,就一个,告诉您用 ...

  8. TensorFlow Serving-TensorFlow 服务

    TensorFlow服务是一个用于服务机器学习模型的开源软件库.它处理机器学习的推断方面,在培训和管理他们的生命周期后采取模型,通过高性能,引用计数的查找表为客户端提供版本化访问. 可以同时提供多个模 ...

  9. chrome不支持embed标签解决方案

    <!DOCTYPE html> <html> <head> <title></title> <meta http-equiv=&quo ...

  10. nodejs基础教程回顾01

    最近在复习nodejs,因为框架太多隔一段时间不用就会忘了,所以没办法必须时常拿出来练练,就像家里有好几辆车,要时不常的轮流开一圈.我就从最基础的开始写,怎么下载安装就不说了,首先是nodejs的三类 ...