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

标签 python tensorflow

我试图理解 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 个非常常见的操作:

  1. 批量训练:您将使用长度相对较小的批量样本(32、64、...)
  2. 训练评估:对所有训练样本的性能评估
  3. 测试评估:对所有测试样本的评估性能

所有这些通常都适用于不同数量的样本。不过,您不必担心,因为 None 已涵盖在内。

关于python - tensorflow 占位符 - 理解 `shape=[None,`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51366871/

相关文章:

python - Azure 日志分析 InsufficientAccessError

python - 如何将 iter(v,w) 与函数一起使用?

python - 如何用Scrapy爬取本地HTML文件

python - Tensorflow实现crf损失

python - 将 CSV 文件转换为 TF 记录

tensorflow - 将共享 GPU 内存与 TensorFlow 一起使用?

用于搜索文件的 Python 脚本

python - 无法将循环限制为 21 行

javascript - TensorFlowJS 无法加载 JS 生成的图像

ubuntu - TensorFlow:解析 .d 文件时出错