Tag Archives: you must feed a value for placeholder tensor

[Solved] TensorFlow Error: you must feed a value for placeholder tensor

Copy the placeholder this way:


input_placeholder = tf.placeholder(tf.int32, 
  [batch_size, sequence_len], 
  name="input")

copy_input = tf.Variable(initial_value=input_placeholder, 
  trainable=False)

Then this sentence reports an error:

sess.run(tf.global_variables_initializer())

Solution:
copy the placeholder in this way:

copy_input = tf.get_variable(
                initializer=tf.constant(0, shape=[batch_size, sequence_len]),    
                name="copy_placeholder",
                dtype=tf.int32, trainable=False)
copy_input.assign(input_placeholder)