Search code examples
tensorflowimage-resizing

Tensorflow image reshaping


length of train image set 40 X_train shape: (40, 32, 32, 3) y_train shape: (40,) Im getting this error: Cannot feed value of shape (40, 32, 32, 3) for Tensor 'Placeholder_17:0', which has shape '(1, 32, 32, 3)'

x = tf.placeholder(dtype=tf.float32, shape=[1, 32, 32, 3])

c1 = tf.layers.conv2d(inputs=x, activation=tf.nn.relu, filters=32, 
kernel_size=[5,5], padding='VALID', strides=1)
p1 = tf.layers.max_pooling2d(inputs=c1, pool_size=[2,2], strides=2)

c2 = tf.layers.conv2d(inputs=p1, activation=tf.nn.relu, filters=64, 
kernel_size=[5,5], padding='VALID', strides=1)
p2 = tf.layers.max_pooling2d(inputs=c2, pool_size=[2,2], strides=2)

f = tf.contrib.layers.flatten(p2) 

fc1 = tf.layers.dense(inputs=f, units=64, activation=tf.nn.relu) 

logits = tf.layers.dense(inputs = fc1, units=2)

tf.layers.dropout(inputs = fc1, rate = 0.4) 



epochs = 50

for i in range(epochs):
    sess.run([trainer], feed_dict={x:X_train/255., y:y_train})
    [acc, l] = sess.run([accuracy, loss], feed_dict={x:X_train/255., y:y_train})
    print('Epoch %d - Loss: | %.2f Accuracy: %.2f'%(i,np.mean(l),acc))

Solution

  • You need to have placeholder dimensions and input dimensions match. So you will have to set placeholder_17 to (40, 32, 32, 3) or iteratively feed in each of the image into placeholder_17 with dimension (1, 32, 32, 3).