• tensorflow函数解析: tf.Session() 和tf.InteractiveSession()


    链接如下:

    http://stackoverflow.com/questions/41791469/difference-between-tf-session-and-tf-interactivesession

    英文

    Question:

    Questions says everything, for taking sess= tf.Session() and sess=tf.InteractiveSession() which cases should be considered for what purpose ? When I am using former one some function didn't work and when changed to the later it worked (for example .eval()).

    Answer:

    Mainly taken from official documentation:

    The only difference with a regular Session is that an InteractiveSession installs itself as the default session on construction. The methods Tensor.eval() and Operation.run() will use that session to run ops.

    This allows to use interactive context, like shell, as it avoids having to pass an explicit Session object to run op:

    sess = tf.InteractiveSession()
    a = tf.constant(5.0)
    b = tf.constant(6.0)
    c = a * b
    # We can just use 'c.eval()' without passing 'sess'
    print(c.eval())
    sess.close()
    

    It is also possible to say, that InteractiveSession supports less typing, as allows to run variables without needing to constantly refer to the session object.

     

    中文

    问题: tf.Session()和tf.InteractiveSession()的区别?

    答案:

    唯一的区别在于:tf.InteractiveSession()加载它自身作为默认构建的session,tensor.eval()和operation.run()取决于默认的session.

    换句话说:InteractiveSession 输入的代码少,原因就是它允许变量不需要使用session就可以产生结构。

  • 相关阅读:
    php+apache+mysql环境搭建
    怎么理解依赖注入
    maven修改远程和本地仓库地址
    idea创建的java web项目打包发布到tomcat
    MYSQL 导入导出数据库文件
    MySQL约束
    mysql字符集校对
    prime
    POJ-2564 01背包问题
    POJ-1564 dfs
  • 原文地址:https://www.cnblogs.com/antflow/p/7234213.html
Copyright © 2020-2023  润新知