tf.placeholder使用说明
tf.placeholder(dtype, shape=None, name=None)
placeholder,占位符,在tensorflow中类似于函数参数,运行时必须传入值。
- dtype:数据类型。常用的是tf.float32,tf.float64等数值类型。
- shape:数据形状。默认是None,就是一维值,也可以是多维,比如[2,3], [None, 3]表示列是3,行不定。
- name:名称。
代码片段-1(计算3*4=12)
- #!/usr/bin/env python
- # _*_ coding: utf-8 _*_
- import tensorflow as tf
- import numpy as np
- input1 = tf.placeholder(tf.float32)
- input2 = tf.placeholder(tf.float32)
- output = tf.multiply(input1, input2)
- with tf.Session() as sess:
- print sess.run(output, feed_dict = {input1:[3.], input2: [4.]})
代码片段-2(计算矩阵相乘,x*x)
- #!/usr/bin/env python
- # _*_ coding: utf-8 _*_
- import tensorflow as tf
- import numpy as np
- x = tf.placeholder(tf.float32, shape=(1024, 1024))
- y = tf.matmul(x, x)
- with tf.Session() as sess:
- # print(sess.run(y)) # ERROR: x is none now
- rand_array = np.random.rand(1024, 1024)
- print(sess.run(y, feed_dict={x: rand_array})) # Will succeed.
tf.placeholder使用说明的更多相关文章
- TensorFlow 辨异 —— tf.placeholder 与 tf.Variable
https://blog.csdn.net/lanchunhui/article/details/61712830 https://www.cnblogs.com/silence-tommy/p/70 ...
- 深度学习原理与框架-Tensorflow基本操作-变量常用操作 1.tf.random_normal(生成正态分布随机数) 2.tf.random_shuffle(进行洗牌操作) 3. tf.assign(赋值操作) 4.tf.convert_to_tensor(转换为tensor类型) 5.tf.add(相加操作) tf.divide(相乘操作) 6.tf.placeholder(输入数据占位
1. 使用tf.random_normal([2, 3], mean=-1, stddev=4) 创建一个正态分布的随机数 参数说明:[2, 3]表示随机数的维度,mean表示平均值,stddev表示 ...
- tf.placeholder
tf.placeholder placeholder( dtype, shape=None, name=None ) 功能说明: 是一种占位符,在执行时候需要为其提供数据 参数列表: 参数名 必选 类 ...
- TensorFlow函数(一)tf.placeholder()函数
tf.placeholder(dtype, shape=None, name=None) 此函数用于定义过程,在执行的时候再赋具体的值 参数: dtype:数据类型.常用的是tf.float32,tf ...
- Tensorflow函数——tf.placeholder()函数
tf.placeholder()函数 Tensorflow中的palceholder,中文翻译为占位符,什么意思呢? 在Tensoflow2.0以前,还是静态图的设计思想,整个设计理念是计算流图,在编 ...
- tf.placeholder类似函数中的形参
tf.placeholder(dtype, shape=None, name=None) 此函数可以理解为形参,用于定义过程,在执行的时候再赋具体的值 参数: dtype:数据类型.常用的是tf.fl ...
- tf.Variable()、tf.get_variable()和tf.placeholder()
1.tf.Variable() tf.Variable(initializer,name) 功能:tf.Variable()创建变量时,name属性值允许重复,检查到相同名字的变量时,由自动别名机制创 ...
- tf.placeholder函数说明
函数形式: tf.placeholder( dtype, shape=None, name=None ) 参数: dtype:数据类型.常用的是tf.float32,tf.fl ...
- tensorflow学习之tf.placeholder
placeholder函数相当于一个占位符,tf.placeholder(dtype, shape=None, name=None) dtype:数据类型.常用的是tf.float32,tf.floa ...
随机推荐
- TACOTRON:端到端的语音合成
tacotron主要是将文本转化为语音,采用的结构为基于encoder-decoder的Seq2Seq的结构.其中还引入了注意机制(attention mechanism).在对模型的结构进行介绍之前 ...
- 小希的迷宫---hdu1272
http://acm.hdu.edu.cn/showproblem.php?pid=1272 #include<stdio.h> #include<string.h> #inc ...
- Python装饰器与面向切面编程(转)
add by zhj: 装饰器的作用是将代码中可以独立的功能独立出来,实现代码复用,下面那个用于统计函数运行时间的装饰器就是很好的例子,我们不用修改原有的函数和调用原有函数的地方,这遵循了开闭原则.装 ...
- Jmeter之正则
正则转换网站:http://tool.oschina.net/regex/ 后置处理器,正则表达式提取器,写正则 待匹配文本框:放你的源文件或源代码,正则表达式:也就是你关联的那句匹配结果:根据匹配结 ...
- java-信息安全(八)-迪菲-赫尔曼(DH)密钥交换【不推荐,推荐Oakley】
概述 信息安全基本概念: DH(Diffie–Hellman key exchange,迪菲-赫尔曼密钥交换) DH 是一种安全协议,,一种确保共享KEY安全穿越不安全网络的方法,它是OAKLEY的一 ...
- ROS学习笔记一(ROS的catkin工作空间)
在安装完成ROS indigo之后,需要查看环境变量是否设置正确,并通过创建一个简单的实例来验证ROS能否正常运行. 1 查看环境变量 在ROS的安装过程中,我们执行了如下命令:(此命令就是向当前用户 ...
- Scala系统学习(五):Scala访问修辞符
本章将介绍Scala访问修饰符.包,类或对象的成员可以使用私有(private)和受保护(protected)的访问修饰符进行标注,如果不使用这两个关键字的其中一个,那么访问将被视为公开(public ...
- HDU1010:Tempter of the Bone(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...
- FDR错误发现率-P值校正学习[转载]
转自:https://baike.baidu.com/item/FDR/16312044?fr=aladdin https://blog.csdn.net/taojiea1014/article/d ...
- PAT 1072 Gas Station[图论][难]
1072 Gas Station (30)(30 分) A gas station has to be built at such a location that the minimum distan ...