Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

You must feed a value for placeholder tensor 'Placeholder' with dtype float

I'm a newer to tensorflow, I really don't know how to solve the problem.

The code is like:

  1. Feed the train with values:

    sess.run(train_op, feed_dict={images: e, labels: l, keep_prob_fc2: 0.5}) 
  2. Use the value in CNN:

    x = tf.placeholder(tf.float32, [None, 10 * 1024]) 

Then have the error

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype float      [[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/gpu:0"]()]] 

I print the input valuetypes using print(e.dtype) and the result is float32 and e.shape:(10, 32, 32, 1).

I really don't know why this error is happening.


The code format

First:

 define the CNN model         "image = tf.placeholder(tf.float32, [FLAGS.batch_size, 32,32,1])" is here 

Second:

 loss funtion and train_op is here        "label = tf.placeholder(tf.float32, [None, FLAGS.batch_size])" is here 

Third is the session:

images, labels = getShuffleimage()#here will get shuffle data num_examples = 0 init = tf.initialize_local_variables()  with tf.Session() as sess:     # Start populating the filename queue.     sess.run(init)     coord = tf.train.Coordinator()     threads = tf.train.start_queue_runners(coord=coord, sess=sess)      try:         step = 0         while not coord.should_stop():             start_time = time.time()             image, label = sess.run([images, labels])#get shuffle images             print(image.shape)             print(image.dtype)             sess.run(train_op, feed_dict={image: image, label: label , keep_prob_fc2: 0.5})             duration = time.time() - start_time      except tf.errors.OutOfRangeError:         print('Done training after reading all data')     finally:         # When done, ask the threads to stop.         coord.request_stop()          # Wait for threads to finish.         coord.join(threads)         sess.close() 
like image 819
judyzha Avatar asked Jan 12 '17 07:01

judyzha


2 Answers

Some questions

first
why you use sess = tf.InteractiveSession() and with tf.Session() as sess: at same time, just curious

second what is your placeholder name x or images?
if name is x, {images: x_data...} won't feed x_data to x, it override(?) images
I think feed_dict should be {x: x_data...}

if name is images,do you have two images in your program, placeholder and shuffle data, try to modify name of variable

like image 194
xxi Avatar answered Sep 19 '22 13:09

xxi


I saw one problem with the code. There are two variables with the same name label. One of them refers to a Tensor, and the other one refers to some data. When you set label: label in the feed_dict, you need to distinguish between the two variables. Maybe you can try changing the name for one of the variables?

like image 34
Targo Avatar answered Sep 21 '22 13:09

Targo