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. Blocks POJ - 1390 多维dp

    题意:有一排box,各有不同的颜色.你可以通过点击某个box使得与其相邻的同色box全部消掉,然后你可以得到的分数为消去长度的平方,问怎样得到最高分? 题解:考虑用一维dp,/*dp[i]为1~i个b ...

  2. Primitive Data Types

    Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics) http ...

  3. 显示界面的流畅性FHHFPSIndicator

    github地址https://github.com/jvjishou/FHHFPSIndicator 1.使用cocoapods  pod 'FHHFPSIndicator' 使用方法: 然后在Ap ...

  4. vue中使用better-scroll实现滑动效果

    1.安装:npm install better-scroll 2.引入:import BetterScrol from "better-scroll"; 1.滚动效果 better ...

  5. PHPExcel使用-使用PHPExcel导入文件

    导入步骤: 1. 实例化excel读取对象 2. 加载excel文件 ----------------> ( 1>. 全部加载. 2>. 选择加载. ) 3. 读取excel文件 - ...

  6. Py-apply用法学习【转载】

    转自:https://blog.csdn.net/anshuai_aw1/article/details/82347016 1.Apply Python中apply函数的格式为:apply(func, ...

  7. PAT 1021 Deepest Root[并查集、dfs][难]

    1021 Deepest Root (25)(25 分) A graph which is connected and acyclic can be considered a tree. The he ...

  8. 【Cocos2dx 3.3 Lua】剪裁结点ClippingNode

    参考资料:     http://shahdza.blog.51cto.com/2410787/1561937 http://blog.csdn.net/jackystudio/article/det ...

  9. Java-使用IO流对大文件进行分割和分割后的合并

    有的时候我们想要操作的文件很大,比如:我们想要上传一个大文件,但是收到上传文件大小的限制,无法上传,这是我们可以将一个大的文件分割成若干个小文件进行操作,然后再把小文件还原成源文件.分割后的每个小文件 ...

  10. list的*运算使用过程中遇到的问题

    目的: 想生成一个[[],[],[]] 这样的列表, 所以就 [[]]*3 这样做了,但是这样做会有问题,这样list中的三个list其实是同一个list. 例如:a=[[]]*3,然后a[0].ap ...