zoukankan      html  css  js  c++  java
  • Difference Between Session.run and Tensor.eval

    【Question】:

    TensorFlow has two ways to evaluate part of graph: Session.run on a list of variables and Tensor.eval. Is there a difference between these two?

    【Answer】:

    If you have a Tensor t, calling t.eval() is equivalent to calling tf.get_default_session().run(t).

    You can make a session the default as follows:

    t = tf.constant(42.0)
    sess = tf.Session()
    with sess.as_default():   # or `with sess:` to close on exit
        assert sess is tf.get_default_session()
        assert t.eval() == sess.run(t)

    The most important difference is that you can use sess.run() to fetch the values of many tensors in the same step:

    t = tf.constant(42.0)
    u = tf.constant(37.0)
    tu = tf.mul(t, u)
    ut = tf.mul(u, t)
    with sess.as_default():
       tu.eval()  # runs one step
       ut.eval()  # runs one step
       sess.run([tu, ut])  # evaluates both tensors in a single step

    Note that each call to eval and run will execute the whole graph from scratch. To cache the result of a computation, assign it to a tf.Variable.

    ----------------------------------------------------------

    参考:

    1. http://blog.csdn.net/zcf1784266476/article/details/70259676
  • 相关阅读:
    C++ 内置函数 判断字母、数字及大小写转换
    C++11 随机数 random
    rpc
    C++11 智能指针
    xargs 命令使用
    记录优秀的文章
    腾讯 测试开发
    struts2文件上传、下载、防止重复提交
    注解
    @RestController注解
  • 原文地址:https://www.cnblogs.com/hezhiyao/p/8196645.html
Copyright © 2011-2022 走看看