博客园  :: 首页  :: 新随笔  :: 管理

tensorflow中的Fetch、Feed(02-3)

Posted on 2020-02-13 01:47  wsg_blog  阅读(710)  评论(0编辑  收藏  举报
import tensorflow as tf

#Fetch概念 在session中同时运行多个op
input1=tf.constant(3.0)     #constant()是常量不用进行init初始化
input2=tf.constant(2.0)
input3=tf.constant(5.0)

add=tf.add(input2, input3)
mul=tf.multiply(input1,add)

with tf.Session() as sess:
    result=sess.run([mul,add])  #这里的[]就是Fetch操作
    print(result)

#Feed
#创建占位符
input1=tf.placeholder(tf.float32)
input2=tf.placeholder(tf.float32)
#定义乘法op,op被调用时可通过Feed的方式将input1、input2传入
output=tf.multiply(input1,input2)

with tf.Session() as sess:
    #feed的数据以字典的形式传入
    print(sess.run(output,feed_dict={input1:[7.],input2:[2.]}))

 

 

目录:

  1. tensorflow简介、目录
  2. tensorflow中的图(02-1)
  3. tensorflow变量的使用(02-2)
  4. tensorflow中的Fetch、Feed(02-3)
  5. tensorflow版helloworld---拟合线性函数的k和b(02-4)
  6. tensorflow非线性回归(03-1)
  7. MNIST手写数字分类simple版(03-2)
  8. 二次代价函数、交叉熵(cross-entropy)、对数似然代价函数(log-likelihood cost)(04-1)
  9. 多层网络通过防止过拟合,增加模型的准确率(04-2)
  10. 修改优化器进一步提升准确率(04-3)
  11. 手写数字识别-卷积神经网络cnn(06-2)
  12. 循环神经网络rnn与长短时记忆神经网络简述(07-2)
  13. 循环神经网络lstm代码实现(07-3)
  14. tensorflow模型保存和使用08
  15. 下载inception v3  google训练好的模型并解压08-3
  16. 使用inception v3做各种图像分类识别08-4
  17. word2vec模型训练简单案例
  18. word2vec+textcnn文本分类简述及代码