简体   繁体   English

tensorflow占位符 - 理解`shape = [无,`

[英]tensorflow placeholder - understanding `shape=[None,`

I'm trying to understand placeholders in tensorflow. 我试图理解张量流中的占位符。 Specifically what shape=[None, means in the example below. 具体是什么shape=[None,意味着在下面的例子中。

X = tf.placeholder(tf.float32, shape=[None, 128, 128, 3], name="X")

This answer describes it as: 这个答案将其描述为:

You can think of a placeholder in TensorFlow as an operation specifying the shape and type of data that will be fed into the graph.placeholder X defines that an unspecified number of rows of shape (128, 128, 3) of type float32 will be fed into the graph. 你可以把TensorFlow中的占位符看作一个操作,指定将被输入到graph中的数据的形状和类型.placeholder X定义了一个未指定数量的float32类型的行(128,128,3)将被馈送进入图表。 a Placeholder does not hold state and merely defines the type and shape of the data to flow into the graph. 占位符不保持状态,只定义要流入图表的数据的类型和形状。

When it says "unspecified number of ROWS" does it really mean unspecified number of tensors of shape 128*128*3? 当它说“未指定数量的ROWS”时它真的意味着未指定数量的128 * 128 * 3形状的张量? Like you are creating a placeholder for input images for input images to a CNN? 就像你正在为输入图像创建一个占位符来输入图像到CNN?

The first dimension represents the number of samples (images in your case). 第一个维度表示样本数(在您的情况下为图像)。 The reason why you do not want to hardcode a specific number there is to keep things flexible and allow for any number of samples. 您不想对特定数字进行硬编码的原因是为了保持灵活性并允许任意数量的样本。 By putting None as the first dimension of the tensor you enable that. 通过将None作为张量的第一个维度,您可以启用它。 Consider the following 3 very common actions: 考虑以下3个非常常见的操作:

  1. Batch training : You are going to use batches of samples of relatively small length (32, 64, ...) 批量培训 :您将使用相对较小长度的样品批次(32,64,...)
  2. Train evaluation : evaluation of perfomance over all training samples 培训评估 :评估所有培训样本的性能
  3. Test evaluation : evaluation performance over all testing samples 测试评估 :评估所有测试样品的性能

All of these will work with a different number of samples in general. 所有这些一般都适用于不同数量的样本。 However, you do not have to worry because the None got you covered. 但是,您不必担心,因为“ None让您满意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM