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)

  1. #!/usr/bin/env python
  2. # _*_ coding: utf-8 _*_
  3. import tensorflow as tf
  4. import numpy as np
  5. input1 = tf.placeholder(tf.float32)
  6. input2 = tf.placeholder(tf.float32)
  7. output = tf.multiply(input1, input2)
  8. with tf.Session() as sess:
  9. print sess.run(output, feed_dict = {input1:[3.], input2: [4.]})

代码片段-2(计算矩阵相乘,x*x)

    1. #!/usr/bin/env python
    2. # _*_ coding: utf-8 _*_
    3. import tensorflow as tf
    4. import numpy as np
    5. x = tf.placeholder(tf.float32, shape=(1024, 1024))
    6. y = tf.matmul(x, x)
    7. with tf.Session() as sess:
    8. #  print(sess.run(y))  # ERROR: x is none now
    9. rand_array = np.random.rand(1024, 1024)
    10. print(sess.run(y, feed_dict={x: rand_array}))  # Will succeed.

tf.placeholder使用说明的更多相关文章

  1. TensorFlow 辨异 —— tf.placeholder 与 tf.Variable

    https://blog.csdn.net/lanchunhui/article/details/61712830 https://www.cnblogs.com/silence-tommy/p/70 ...

  2. 深度学习原理与框架-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表示 ...

  3. tf.placeholder

    tf.placeholder placeholder( dtype, shape=None, name=None ) 功能说明: 是一种占位符,在执行时候需要为其提供数据 参数列表: 参数名 必选 类 ...

  4. TensorFlow函数(一)tf.placeholder()函数

    tf.placeholder(dtype, shape=None, name=None) 此函数用于定义过程,在执行的时候再赋具体的值 参数: dtype:数据类型.常用的是tf.float32,tf ...

  5. Tensorflow函数——tf.placeholder()函数

    tf.placeholder()函数 Tensorflow中的palceholder,中文翻译为占位符,什么意思呢? 在Tensoflow2.0以前,还是静态图的设计思想,整个设计理念是计算流图,在编 ...

  6. tf.placeholder类似函数中的形参

    tf.placeholder(dtype, shape=None, name=None) 此函数可以理解为形参,用于定义过程,在执行的时候再赋具体的值 参数: dtype:数据类型.常用的是tf.fl ...

  7. tf.Variable()、tf.get_variable()和tf.placeholder()

    1.tf.Variable() tf.Variable(initializer,name) 功能:tf.Variable()创建变量时,name属性值允许重复,检查到相同名字的变量时,由自动别名机制创 ...

  8. tf.placeholder函数说明

    函数形式: tf.placeholder(     dtype,     shape=None,     name=None ) 参数: dtype:数据类型.常用的是tf.float32,tf.fl ...

  9. tensorflow学习之tf.placeholder

    placeholder函数相当于一个占位符,tf.placeholder(dtype, shape=None, name=None) dtype:数据类型.常用的是tf.float32,tf.floa ...

随机推荐

  1. REDIS 六. 修复方案

    六. 修复方案 6.1 禁止一些高危命令(重启redis才能生效) 修改 redis.conf 文件,禁用远程修改 DB 文件地址 rename-command FLUSHALL "&quo ...

  2. 修改机器名、IP对arcgis server、portal的影响?

    修改机器名.IP是否对ArcGIS Server .Portal等有影响? 请教赛姐:修改IP对ArcGIS Server .Portal 无影响,不过建议将ArcGIS Server .Portal ...

  3. JS模块化编程(二)

    背景 我们常在页面引用js遇到下面情况 <script src="1.js"></script> <script src="2.js&quo ...

  4. 【生产问题】LDF丢失

    参考 : https://www.cnblogs.com/gered/p/9450622.html CREATE DATABASE db_logs ON PRIMARY ( NAME % ) LOG ...

  5. 让人抓狂的MySQL安装-8.0.12版本

    今天一个下午就做了一件事,把MySQL安装成功,安装的过程让人很狂躁.于是一边骂,一边查错,才把这个软件给安装成功了. 详细的安装步骤,这里就不赘述了.参见https://blog.csdn.net/ ...

  6. Weka——PrincipalComponents分析

    package weka.filters.unsupervised.attribute; PrincipalComponents 属性: /** The data to transform analy ...

  7. Map<String, String>循环遍历的方法

    Map<String, String>循环遍历的方法 Map<String, String>循环遍历的方法 Map<String, String>循环遍历的方法 下 ...

  8. Django实现cookie&session以及认证系统

    COOKIE&SESSION 知识储备 由于http协议无法保持状态,但实际情况,我们却又需要“保持状态”,因此cookie就是在这样一个场景下诞生. cookie的工作原理是:由服务器产生内 ...

  9. 初次使用git上传代码(转)

    转自 http://www.cnblogs.com/cxk1995/p/5800196.html 首先你需要一个github账号,所有还没有的话先去注册吧! https://github.com/ 我 ...

  10. app的底部菜单设计

    一.个人看法. 1.一般都是四个菜单或者五个菜单,这个是绝对主流,我估计占比达99%.当然也有三个菜单图标的,也有零个菜单图标的 2.如果该app软件功能复杂,那么尽量选择5个图标布局.比如苹果app ...