Search code examples
tensorflowdeep-learningdimensions

input dimension reshape in Tensorflow conolutional network


In the expert mnist tutorial in tensorflow website, it have something like this :

x_image = tf.reshape(x, [-1,28,28,1])

I know that the reshape is like

tf.reshape(input,[batch_size,width,height,channel])

Q1 : why is the batch_size equals -1? What does the -1 means?

And when I go down the code there's one more thing I can not understand

W_fc1 = weight_variable([7 * 7 * 64, 1024])

Q2:What does the image_size * 64 means?


Solution

  • Q1 : why is the batch_size equals -1? What does the -1 means?

    -1 means "figure this part out for me". For example, if I run:

    reshape([1, 2, 3, 4, 5, 6, 7, 8], [-1, 2])
    

    It creates two columns, and whatever number of rows it needs to get everything to fit:

    array([[1, 2],
           [3, 4],
           [5, 6],
           [7, 8]])
    

    Q2:What does the image_size * 64 means?

    It is the number of filters in that particular filter activation. Shapes of filters in conv layers follow the format [height, width, # of input channels (number of filters in the previous layer), # of filters].