zoukankan      html  css  js  c++  java
  • Tensorflow (1)

    'tf.placeholder' or 'tf.Variable'

    The difference is that with tf.Variable you have to provide an initial value when you declare it. With tf.placeholder you don't have to provide an initial value and you can specify it at run time with the feed_dict argument inside Session.run

    'Session.run()' or 'Tensor.eval()'

    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 different 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])  # runs 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.

  • 相关阅读:
    在HTML网页中嵌入脚本的方式
    纪念品分组(贪心、排序)
    合并果子(STL优先队列)
    铺地毯(取最上层的地毯)
    多项式方程的输出
    BF算法(蛮力匹配)
    数位的处理
    两个数的差
    多项式计算器
    随机数生成器java实现
  • 原文地址:https://www.cnblogs.com/zhanglianbo/p/6149864.html
Copyright © 2011-2022 走看看