import tensorflow as tf
import random
import numpy as np
x = tf.placeholder('float')
x = tf.reshape(x, [-1,28,28,1])
with tf.Session() as sess:
x1 = np.asarray([random.uniform(0,1) for i in range(784)])
result = sess.run(x, feed_dict={x: x1})
print(result)
I had some problems using mnist data on reshaping, but this question is simplified version of my problem... Why actually isn't this code working?
It shows
"ValueError: Cannot feed value of shape (784,) for Tensor 'Reshape:0', which has shape '(?, 28, 28, 1)' ".
How could I solve it?
To flatten the tensor, we're going to use the TensorFlow reshape operation. So tf. reshape, we pass in our tensor currently represented by tf_initial_tensor_constant, and then the shape that we're going to give it is a -1 inside of a Python list.
After you reassign, x is a tensor with shape [-1,28,28,1]
and as error says, you cannot shape (784,)
to (?, 28, 28, 1)
. You can use a different variable name:
import tensorflow as tf
import random
import numpy as np
x = tf.placeholder('float')
y = tf.reshape(x, [-1,28,28,1])
with tf.Session() as sess:
x1 = np.asarray([random.uniform(0,1) for i in range(784)])
result = sess.run(y, feed_dict={x: x1})
print(result)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With