zoukankan      html  css  js  c++  java
  • tensorflow 中 feed的用法

    Feed 

    上述示例在计算图中引入了 tensor, 以常量或变量的形式存储. TensorFlow 还提供了 feed 机制, 该机制 可以临时替代图中的任意操作中的 tensor 可以对图中任何操作提交补丁, 直接插入一个 tensor.

    feed 使用一个 tensor 值临时替换一个操作的输出结果. 你可以提供 feed 数据作为 run() 调用的参数. feed 只在调用它的方法内有效, 方法结束, feed 就会消失. 最常见的用例是将某些特殊的操作指定为 "feed" 操作, 标记的方法是使用 tf.placeholder() 为这些操作创建占位符. 

    
    input1 = tf.placeholder(tf.float32)
    input2 = tf.placeholder(tf.float32)
    output = tf.mul(input1, input2)
    
    with tf.Session() as sess:
      print sess.run([output], feed_dict={input1:[7.], input2:[2.]})
    
    # 输出:
    # [array([ 14.], dtype=float32)]
    -------------------------------------------------------------------------------------------------------------
    trX = np.linspace(-1, 1, 101)
    trY = 2 * trX + np.random.randn(*trX.shape) * 0.33 # create a y value which is approximately linear 

    X = tf.placeholder("float") # create symbolic variables
    Y = tf.placeholder("float")

    sess = tf.Session()
    init = tf.initialize_all_variables() # you need to initialize variables (in this case just variable W)
    sess.run(init)
    
    for i in range(100):
        for (x, y) in zip(trX, trY): 
            sess.run(train_op, feed_dict={X: x, Y: y})
    
    print(sess.run(w))  # something around 2



     
  • 相关阅读:
    sql-select for update
    java-JDK动态代理
    idea-热部署jreble的使用
    vue-【el-table】转成【pl-table】
    mybatis-字段值为null或为''无法存储到数据库
    vue-本地开发热部署编译缓慢
    chrome-截长图
    el-cascader 级联选择器中选中任意一级去掉圆形按钮
    idea-绿色注释颜色16进制
    markdown 语法
  • 原文地址:https://www.cnblogs.com/xinping-study/p/7160335.html
Copyright © 2011-2022 走看看