Python / Tensorflow - Input to reshape is a tensor with 92416 values, but the requested shape requires a multiple of 2304

Let's come to your original error:

Input to reshape is a tensor with 92416 values, but the requested shape requires a multiple of 2304

This is because you adapt your code from a code with original input image size 24*24. The tensor shape after two convolution and two max-pooling layers is [-1, 6, 6, 64]. However, as your input image shape is 150*150, the intermediate shape becomes [-1, 38, 38, 64].

try change w3

w3 = tf.Variable(tf.random_normal([38*38*64, 1024]))

You should always keep an eye on your tensor shape flow.


The error is happening here:

maxpool_reshaped = tf.reshape(maxpool_out2, [-1,w3.get_shape().as_list()[0]])

As it states: Input to reshape is a tensor with 92416 values, but the requested shape requires a multiple of 2304

Meaning

w3.get_shape().as_list()[0] = 2304

and

maxpool_out2 has 92416 values

but 92416 /2304 has a fractional remainder so python can't fit the rest evenly into "-1".

So you need to recheck the shapes of w3 and what you expect it to be.

Alternative suggestion Update:

x_reshaped = tf.reshape(x, shape=[-1,150,150,1])
batch_size = x_reshaped.get_shape().as_list()[0]

... Same code as above ...

maxpool_reshaped = tf.reshape(maxpool_out2, [batch_size, -1])