VS_FF
VS_FF

Reputation: 2363

Error from tf.reshape() after trying to convert vector into matrix

I am trying to convert a one-dimensional array into a TF matrix, for use in a convolutional network, similar to how its done in the TF deep MNIST example, by using tf.reshape():

X = tf.placeholder(tf.float32, [None, 480])
X = tf.reshape(X, shape=[-1, 60, 8, 1])

I am getting the following error:

ValueError: Cannot feed value of shape (5, 480) for Tensor 'Reshape_1:0', which has shape '(?, 60, 8, 1)'

5 is my batch_size and 480 is the length of the original array. I want to convert it into a 60x8 tensor, plus 1 output channel, so I am following with the TF MNIST example of using the target shape of [-1, 60, 8, 1].

  1. Any idea why I'm getting this? Seems like in the MNIST example they use -1 to adjust the single line into AxA matrix and add one extra dimension for the output channel?
  2. Can I even use non-square matrixes like this, or will it give me an error down the road? I tried doing something like 400=20x20 as well just to see if the error is caused by the uneven shape, but still getting the error...

Upvotes: 2

Views: 906

Answers (1)

Aaron
Aaron

Reputation: 2364

On your first line of code you define a placeholder and store it in the python variable X. On the second line of code you define a reshape operator and also store it in the python variable X. You have now overwritten the previous value of X and lost access to the placeholder. You are trying to feed in a value to the placeholder but you are actually feeding it to the reshape operator. If you use different names for these variables then you will not see this error.

Upvotes: 2

Related Questions