tensorflow placeholder - understanding `shape=[None,`

后端 未结 1 988
一向
一向 2021-01-17 14:58

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

X = tf.placeholder(tf.float32,         


        
相关标签:
1条回答
  • 2021-01-17 15:45

    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. 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

    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.

    0 讨论(0)
提交回复
热议问题