abracadabra
abracadabra

Reputation: 381

You must feed a value for placeholder tensor 'Placeholder' with dtype float and shape [2,2]

I am having You must feed a value for placeholder tensor 'Placeholder' with dtype float and shape [2,2]error.I have already fed the placeholderaa

import numpy as np
import tensorflow as tf

aa = tf.placeholder(dtype=tf.float32, shape=(2, 2))
bb = tf.Variable(aa)
init = tf.global_variables_initializer()
with tf.Session() as sess:
  sess.run(init)
  print(sess.run(bb,feed_dict={aa:np.random.rand(2,2)}))

Upvotes: 1

Views: 859

Answers (1)

javidcf
javidcf

Reputation: 59701

The problem is in sess.run(init); you need a value for aa in order to initialize bb. aa is not needed to retrieve bb later, though, since it already has been assigned a value.

import numpy as np
import tensorflow as tf

aa = tf.placeholder(dtype=tf.float32, shape=(2, 2))
bb = tf.Variable(aa)
init = tf.global_variables_initializer()
with tf.Session() as sess:
  sess.run(init, feed_dict={aa: np.random.rand(2, 2)})
  print(sess.run(bb))

Upvotes: 2

Related Questions