TensorFlow学习笔记3——Placeholders and feed_dict
2017-08-19 15:11
459 查看
1. Placeholders
placeholders,顾名思义,就是占位的意思,举个例子:我们定义了一个关于x,y的函数 f(x,y)=2x+y,但是我们并不知道x,y的值,那么x,y就是等待确定的值输入的placeholders。
我们如下定义一个placeholders:
tf.placeholder(dtype, shape=None, name=None)
一个简单的实例如下:
1 a = tf.placeholder(tf.float32, shape=[3]) 2 b = tf.constant([5, 5, 5], tf.float32) 3 c =a + b 4 with tf.Session() as sess: 5 print(sess.run(c, feed_dict={a: [1, 2, 3]}))
输出:
[ 6. 7. 8.]
看到那个 feed_dict 吗?顺理成章,我们接下来聊聊 feed_dict .
2. feed_dict
刚刚上面不是说“x,y就是等待确定的值输入的placeholders”吗?ok,我们就是通过feed_dict输入那个placeholders苦苦等待的确定的值。
再看一个例子:
1 # create Operations, Tensors, etc (using the default graph) 2 a = tf.add(2, 5) 3 b = tf.multiply(a, 3) 4 # start up a `Session` using the default graph 5 sess = tf.Session() 6 # define a dictionary that says to replace the value of `a` with 15 7 replace_dict = {a: 15} 8 # Run the session, passing in `replace_dict` as the value to `feed_dict` 9 sess.run(b, feed_dict=replace_dict) # returns 45
相关文章推荐
- Placeholders and feed_dict
- Tensorflow学习笔记2:About Session, Graph, Operation and Tensor
- TensorFlow学习笔记10----Logging and Monitoring Basics with tf.contrib.learn
- 深度学习笔记——深度学习框架TensorFlow(八)[Logging and Monitoring Basics with tf.contrib.learn]
- Tensorflow学习笔记2:About Session, Graph, Operation and Tensor
- tensorflow48 《面向机器智能的TensorFlow实战》笔记-03-03 tensorflow基本矢量图、summary、feed_dict
- tensorflow学习笔记(八):模型持久化 saver and restore
- Tensorflow学习教程------Fetch and Feed
- Tensorflow学习笔记2:About Session, Graph, Operation and Tensor
- [转]WPF and Silverlight 学习笔记(二十五):使用CollectionView实现对绑定数据的排序、筛选、分组
- TensorFlow官方教程学习笔记之2-用于机器学习初学者学习的MNIST数据集(MNIST For ML Beginners)
- WTL 学习笔记 -- Property Sheets and Wizards
- TensorFlow学习-- 变量Variables/ Fetch/ Feed
- Data Structures and Other Objects Using C++ (Chapter 2) 学习笔记四
- TensorFlow学习笔记1
- tensorflow学习笔记--embedding_lookup()用法
- Neural Networks and Deep Learning 学习笔记(十一)
- tensorflow学习fully_connected_feed.py
- WPF and Silverlight 学习笔记(一):开发环境及参考资料
- 01. Tensorflow学习笔记_Linux基础 (补充)