个人理解:就是TF的一种输入语法。

跟C语言的scanf(),C++的 cin>> 意思差不多,只是长相奇怪了点而已。

做完下面几个例子,基本也就适应了。

首先占位符申请空间;使用的时候,通过占位符“喂(feed)”给程序。然后程序就可以run了。。。

理解的不一定对,也不够深入,仅供参考。

import tensorflow as tf
  • tf.placeholder 占位符
  • tf.Session 会话

1. 输出 Hello World

Str = tf.placeholder(tf.string)

with tf.Session() as sess:
output = sess.run(Str, feed_dict={Str: 'Hello World !'})
print(output)
Hello World !

2.字符串拼接

Str1 = tf.placeholder(tf.string)
Str2 = tf.placeholder(tf.string)
Str3 = tf.placeholder(tf.string) Str = tf.string_join([Str1, Str2, Str3], separator=" ") with tf.Session() as sess:
output = sess.run(Str, feed_dict={Str1: 'I', Str2: 'like', Str3: 'TensorFlow !'})
print(output.decode())
I like TensorFlow !

3.浮点数乘积

Num1 = tf.placeholder(tf.float32)
Num2 = tf.placeholder(tf.float32) Result = tf.multiply(Num1, Num2) with tf.Session() as sess:
print(sess.run(Result, feed_dict={Num1:[.],Num2:[.]}))
[ .]

4.不用占位符,而用常量,也可完成。

只是验证一下,不推荐使用。初始化时的常量值将会被覆盖。

Num1 = tf.constant(1.0)
Num2 = tf.constant(2.0) Result = tf.multiply(Num1, Num2) with tf.Session() as sess:
print (sess.run(Result, feed_dict = {Num1: ., Num2: .}))
30.0

5.矩阵乘法

顺道学点新东西

定义两个矩阵,分别为 2*3 和 3*2矩阵,完成乘法运算

Matrix1 = tf.Variable(tf.random_normal([,]))
Matrix2 = tf.Variable(tf.truncated_normal([,])) Result = tf.matmul(Matrix1,Matrix2) with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print ('Matrix1:')
print (sess.run(Matrix1))
print ('Matrix2:')
print (sess.run(Matrix2))
print ('Result:')
print (sess.run(Result))
Matrix1:
[[-1.00879586 0.61892986 -0.39552122]
[-0.83463311 -0.54309726 -0.31309164]]
Matrix2:
[[ 1.35596943 0.67712855]
[-0.09836598 -0.41533285]
[ 0.20601694 -0.14825489]]
Result:
[[-1.51026201 -0.88150841]
[-1.14281678 -0.29317039]]

使用 feed_dict完成矩阵乘法

表达看上去更繁琐。。。对比一下是为了更好地理解feed_dict。。。

Matrix1_Value = tf.random_normal([,])
Matrix2_Value = tf.truncated_normal([,]) Matrix1 = tf.placeholder(dtype=tf.float32,shape=[,])
Matrix2 = tf.placeholder(dtype=tf.float32,shape=[,]) Result = tf.matmul(Matrix1,Matrix2) with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print ('Matrix1:')
print (sess.run(Matrix1_Value))
print ('Matrix2:')
print (sess.run(Matrix2_Value))
print ('Result:')
print (sess.run(Result,feed_dict={Matrix1:sess.run(Matrix1_Value),Matrix2:sess.run(Matrix2_Value)}))
Matrix1:
[[-0.6228959 0.04135797 -0.76592982]
[ 0.04814498 -0.98519218 -0.88335162]]
Matrix2:
[[-0.73028505 0.62314421]
[-0.64763296 -0.18691106]
[ 0.0198773 0.68467569]]
Result:
[[-1.66321826 -2.89716744]
[ 1.28906226 2.08242035]]

TensorFlow学习笔记(三)-- feed_dict 使用的更多相关文章

  1. tensorflow学习笔记三:实例数据下载与读取

    一.mnist数据 深度学习的入门实例,一般就是mnist手写数字分类识别,因此我们应该先下载这个数据集. tensorflow提供一个input_data.py文件,专门用于下载mnist数据,我们 ...

  2. tensorflow学习笔记三----------基本操作

    tensorflow中的一些操作和numpy中的很像,下面列出几个比较常见的操作 import tensorflow as tf #定义三行四列的零矩阵 tf.zeros([3,4]) #定义两行三列 ...

  3. tensorflow学习笔记(三):实现自编码器

    黄文坚的tensorflow实战一书中的第四章,讲述了tensorflow实现多层感知机.Hiton早年提出过自编码器的非监督学习算法,书中的代码给出了一个隐藏层的神经网络,本人扩展到了多层,改进了代 ...

  4. tensorflow学习笔记(三十四):Saver(保存与加载模型)

    Savertensorflow 中的 Saver 对象是用于 参数保存和恢复的.如何使用呢? 这里介绍了一些基本的用法. 官网中给出了这么一个例子: v1 = tf.Variable(..., nam ...

  5. tensorflow学习笔记(三十九):双向rnn

    tensorflow 双向 rnn 如何在tensorflow中实现双向rnn 单层双向rnn 单层双向rnn (cs224d) tensorflow中已经提供了双向rnn的接口,它就是tf.nn.b ...

  6. 深度学习-tensorflow学习笔记(2)-MNIST手写字体识别

    深度学习-tensorflow学习笔记(2)-MNIST手写字体识别超级详细版 这是tf入门的第一个例子.minst应该是内置的数据集. 前置知识在学习笔记(1)里面讲过了 这里直接上代码 # -*- ...

  7. tensorflow学习笔记——使用TensorFlow操作MNIST数据(2)

    tensorflow学习笔记——使用TensorFlow操作MNIST数据(1) 一:神经网络知识点整理 1.1,多层:使用多层权重,例如多层全连接方式 以下定义了三个隐藏层的全连接方式的神经网络样例 ...

  8. tensorflow学习笔记——自编码器及多层感知器

    1,自编码器简介 传统机器学习任务很大程度上依赖于好的特征工程,比如对数值型,日期时间型,种类型等特征的提取.特征工程往往是非常耗时耗力的,在图像,语音和视频中提取到有效的特征就更难了,工程师必须在这 ...

  9. tensorflow学习笔记——VGGNet

    2014年,牛津大学计算机视觉组(Visual Geometry Group)和 Google DeepMind 公司的研究员一起研发了新的深度卷积神经网络:VGGNet ,并取得了ILSVRC201 ...

  10. tensorflow学习笔记——使用TensorFlow操作MNIST数据(1)

    续集请点击我:tensorflow学习笔记——使用TensorFlow操作MNIST数据(2) 本节开始学习使用tensorflow教程,当然从最简单的MNIST开始.这怎么说呢,就好比编程入门有He ...

随机推荐

  1. Easyui 编辑表格行删除

    1.问题描述 easyui 编辑表格新增一条数据后,删除最后一行删除不了,原因是没有提交数据acceptChanges. 源码中deleteRow方法,根据坐标获取行html,方法为opts.find ...

  2. 用javascript技术读取注册表中软件安装位置并启动本地软件

    1.首先读取注册表中本地软件安装的位置,如果未安装则无就跳转到下载页面. 2.启动软件,关闭页面. 3.如报错提示. <SCRIPT language=javascript>  <! ...

  3. 【SPOJ】8222. Substrings(后缀自动机)

    http://www.spoj.com/problems/NSUBSTR/ 题意:给一个字符串S,令F(x)表示S的所有长度为x的子串中,出现次数的最大值.求F(1)..F(Length(S)) 这题 ...

  4. 【BZOJ】1034: [ZJOI2008]泡泡堂BNB(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1034 弱的比弱的强就用,强的比强的强就用: 否则弱的和强的比. 输的情况就是2n-ans(b,a), ...

  5. JAVA 并发编程-多个线程之间共享数据(六)

    多线程共享数据的方式: 1.假设每一个线程运行的代码同样.能够使用同一个Runnable对象,这个Runnable对象中有那个共享数据,比如,卖票系统就能够这么做. 2,假设每一个线程运行的代码不同. ...

  6. VC++分页打印实现

    VC++分页打印实现:  C++ Code  12345678910111213141516171819202122232425262728293031323334353637383940414243 ...

  7. Boost库初见

    Boost库是一个功能强大.构造精巧.跨平台.开源并且完全免费的C++库,有C++"准"标准库的美称! Boost有着与其它程序库(如MFC等)无法比拟的优点. Boost库采用了 ...

  8. AWS系列-创建AMI

    AMI创建 在XEN中pv是半虚拟化,hvm是全虚拟化,pv只能用于linux内核的系统,效率更高,hvm可以虚拟所有常见操作系统(可以使用 windows),理论效率比pv略低,另外,hvm需要cp ...

  9. python真值表

    author:headsen chen  date :2018-06-01  10:53:39 notice:not allowed to copy or you will count law que ...

  10. 基于k8s的promethus监控

    没有监控 就没有眼睛. 除了k8s的基本监控外(pod运行状况.占用内存.cpu).为了对微服务项目中的(1)各种参数线程池.QPS.RT.业务指标(2)系统负载.thread.mem.class.t ...