我试图理解 tensorflow 中的占位符。具体来说,shape=[None,
在下面的示例中意味着什么。
X = tf.placeholder(tf.float32, shape=[None, 128, 128, 3], name="X")
This答案将其描述为:
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. a Placeholder does not hold state and merely defines the type and shape of the data to flow into the graph.
当它说“未指定数量的 ROWS”时,它真的意味着未指定数量的形状为 128*128*3 的张量吗?就像您正在为 CNN 的输入图像创建输入图像占位符一样?
最佳答案
第一个维度表示样本数(在您的例子中是图像)。您不想对特定数字进行硬编码的原因是为了保持灵 active 并允许任意数量的样本。通过将 None
作为张量的第一维,您可以启用它。考虑以下 3 个非常常见的操作:
- 批量训练:您将使用长度相对较小的批量样本(32、64、...)
- 训练评估:对所有训练样本的性能评估
- 测试评估:对所有测试样本的评估性能
所有这些通常都适用于不同数量的样本。不过,您不必担心,因为 None
已涵盖在内。
关于python - tensorflow 占位符 - 理解 `shape=[None,`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51366871/