张量流占位符 - 理解`shape=[None,` [英] tensorflow placeholder - understanding `shape=[None,`

查看:125
本文介绍了张量流占位符 - 理解`shape=[None,`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试理解 tensorflow 中的占位符.具体来说,shape=[None, 在下面的例子中是什么意思.

I'm trying to understand placeholders in tensorflow. Specifically what shape=[None, means in the example below.

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

这个 回答将其描述为:

您可以将 TensorFlow 中的占位符视为指定将输入的数据的形状和类型的操作graph.placeholder X 定义了未指定数量的形状行float32 类型的 (128, 128, 3) 将被送入图中.一种占位符不保存状态,仅定义类型和形状流入图表的数据.

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.

当它说未指定行数"时,它真的意味着未指定数量的形状为 128*128*3 的张量吗?就像您正在为 CNN 的输入图像创建输入图像的占位符?

When it says "unspecified number of ROWS" does it really mean unspecified number of tensors of shape 128*128*3? Like you are creating a placeholder for input images for input images to a CNN?

推荐答案

第一个维度代表样本的数量(在你的例子中是图像).您不想对特定数字进行硬编码的原因是为了保持灵活性并允许任意数量的样本.通过将 None 作为张量的第一个维度,您可以启用它.考虑以下 3 个非常常见的操作:

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. Consider the following 3 very common actions:

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

所有这些一般都适用于不同数量的样本.但是,您不必担心,因为 None 可以满足您的需求.

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.

这篇关于张量流占位符 - 理解`shape=[None,`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆