TensorFlow函数——tf.placeholder()
来源:互联网 发布:淘宝网商城女装冬装 编辑:程序博客网 时间:2024/05/20 03:40
占位符
TensorFlow提供一个占位符操作,必须在执行时提供数据。 有关更多信息,请参阅Feeding数据部分。
Tf.placeholder(dtype,shape=None,name=None)
插入一个总是需要放入数据的张量的占位符。
重要提示:如果evaluated,该张量会产生错误。 必须使用feed_dict可选参数为Session.run(),Tensor.eval()或Operation.run()提供其值。
创建一个占位符作为一个张量(tensor),并且只有在赋值后才可以放到节点中执行。
For example:
x = tf.placeholder(tf.float32, shape=(1024, 1024))
y = tf.matmul(x, x)
with tf.Session() as sess:
print(sess.run(y)) # ERROR: will fail because x was not fed.
rand_array = np.random.rand(1024, 1024)
print(sess.run(y, feed_dict={x: rand_array})) # Will succeed.
Args:
dtype: 要放给张量(tensor)中的元素类型
shape: 要放到张量(tensor)中的形状(向量维数)(可选)。如果未指定形状,则可以为任何形状的张量
name: 操作的名称(可选).
返回:
可以用作手段来提供值但不直接评估的张量。
tf.placeholder_with_default(input, shape, name=None)
一个占位符的操作,当它的输出没有被馈送时,通过input传递
Args:
Input:A Tensor(某一张量),当它的输出没有被馈送时,A的默认值将被传送进来。
Shape:A的tf.TensorShape或者ints列表。张量(可能部分的)形状
Name:操作的名称(可选)
Returns:
张量. 与输入的类型相同.一个占位符张量,如果没有输入则默认为输入。
对于作为复合类型的稀疏传感器,有一个方便的功能:
tf.sparse_placeholder(dtype, shape=None, name=None)
插入一个占位符,用于总是馈送的稀疏张量。
重要:如果评估,这个稀疏张量会产生错误。 必须使用feed_dict可选参数为Session.run(),Tensor.eval()或Operation.run()提供其值。
例如:
x = tf.sparse_placeholder(tf.float32)
y = tf.sparse_reduce_sum(x)
with tf.Session() as sess:
print(sess.run(y)) # ERROR: will fail because x was not fed.
indices = np.array([[3, 2, 0], [4, 5, 1]], dtype=np.int64)
values = np.array([1.0, 2.0], dtype=np.float32)
shape = np.array([7, 9, 2], dtype=np.int64)
print(sess.run(y, feed_dict={x: tf.SparseTensorValue(indices, values, shape)}))
# Will succeed.
print(sess.run(y, feed_dict={ x: (indices, values, shape)})) # Will succeed.
sp = tf.SparseTensor(indices=indices, values=values, shape=shape)
sp_value = sp.eval(session)
print(sess.run(y, feed_dict={x: sp_value})) # Will succeed.
Args:
dtype:要提供的张量中的值元素的类型。
形状:要进给的张量的形状(可选)。 如果没有指定形状,可以输入任何形状的稀疏张量。
name:用于前缀操作的名称(可选)。
Returns:
一个稀疏传感器,可用作提供值的句柄,但不直接评估。
- TensorFlow函数——tf.placeholder()
- 【Tensorflow】tf.placeholder函数
- Tensorflow tf.placeholder函数
- 【Tensorflow】tf.placeholder函数
- TensorFlow 辨异 —— tf.placeholder 与 tf.Variable
- TensorFlow 辨异 —— tf.placeholder 与 tf.Variable
- TensorFlow 辨异 —— tf.placeholder 与 tf.Variable
- TensorFlow 辨异 —— tf.placeholder 与 tf.Variable
- tensorflow tf.placeholder
- 3. Tensorflow学习笔记之tf.placeholder函数
- tensorflow——tf.one_hot以及tf.sparse_to_dense函数
- TensorFlow函数——tf.variable( )
- Tensorflow函数——tf.set_random_seed(seed)
- Tensorflow函数——tf.variable_scope()
- TensorFlow 插曲-- tf.placeholder 与 tf.Variable
- 转载!Tensorflow函数——tf.set_random_seed(seed)
- 【Tensorflow】tf.reshape 函数
- 【Tensorflow】tf.argmax函数
- Linux 相关技能
- github入门指南
- get和load方式 .
- 常用SQL查询语句
- 简单工厂模式
- TensorFlow函数——tf.placeholder()
- 【PHP入门】Zend Studio常用快捷键
- Retrofit+RxJava实现app崩溃处理(一)上传文件
- 实现对未登录用户进行相关操作的拦截
- Double Profiles CodeForces
- Linux(文件的用途)
- JQUERY 登录验证
- MathType中如何实现上下两行公式“=”号或者任意地方对齐
- JavaScript 中的字符串分割 slice()、substr()、substring()