在很多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. [ZJOI 2010]count 数字计数

    Description 题库链接 问你 \([l,r]\) 区间内所有整数中各个数码出现了多少次. \(1\leq a\leq b\leq 10^{12}\) Solution 数位 \(DP\) . ...

  2. [JSOI 2007]麻将

    Description 题库链接 给你一副麻将,胡牌的条件是一对将和若干顺子和刻子组成.现在给你 \(m\) 张牌,牌共 \(n\) 种,问你听哪一张牌. \(1\leq n\leq 400,1\le ...

  3. [Codeforces 864A]Fair Game

    Description Petya and Vasya decided to play a game. They have n cards (n is an even number). A singl ...

  4. [USACO08JAN]haybale猜测Haybale Guessing

    题目描述 The cows, who always have an inferiority complex about their intelligence, have a new guessing ...

  5. 计蒜客NOIP模拟赛(3) D1T2 信息传递

    一个数据包在一个无向网络中传递.在时刻0,该数据包将依照特定的概率随机抵达网络中的某个节点.网络可以看做一张完全带权无向图,包含N个节点,若t时刻数据包在节点i,则在t+1时刻,数据包被传递到节点j的 ...

  6. bzoj2683简单题 cdq分治

    2683: 简单题 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 1803  Solved: 731[Submit][Status][Discuss] ...

  7. [3.19FJ四校联考]

    来自FallDream的博客.未经允许,请勿转载,谢谢. ---------------------------------------------------- A.积分,不会  以后补 B.给定一 ...

  8. 勤拂拭软件 java web 开发教程(1) - 开发环境搭建

    勤拂拭软件系列教程 之 Java Web开发之旅(1) Java Web开发环境搭建 1 前言 工作过程中,遇到不少朋友想要学习jsp开发,然而第一步都迈不出,连一个基本的环境都没有,试问,如何能够继 ...

  9. Python作业之购物车

    作业之购物车 购物车的要求如下: 输入总金额 选择购买的商品,金额足够时,把选择的商品添加到购物车,金额不足时,进行提示,商品将不会添加到购物车 随时可以退出程序,同时输出已购买的商品 具体代码如下: ...

  10. c语言第二次作业2

    ---恢复内容开始--- (一)改错题 1.输出带框文字:在屏幕上输出以下3行信息. 源程序 对源程序进行编译 错误信息1: 错误原因:stdio.h输入错误 改正方法:i和d互换位置 错误信息2: ...