【发布时间】:2017-05-27 04:54:58
【问题描述】:
我是tensorflow的新手,真的不知道怎么解决。
代码如下:
-
为火车提供价值:
sess.run(train_op, feed_dict={images: e, labels: l, keep_prob_fc2: 0.5}) -
使用CNN中的值:
x = tf.placeholder(tf.float32, [None, 10 * 1024])
那就报错
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"]()]]
我使用print(e.dtype) 打印输入值类型,结果是float32 和e.shape:(10, 32, 32, 1)。
我真的不知道为什么会发生这个错误。
代码格式
第一:
define the CNN model
"image = tf.placeholder(tf.float32, [FLAGS.batch_size, 32,32,1])" is here
第二:
loss funtion and train_op is here
"label = tf.placeholder(tf.float32, [None, FLAGS.batch_size])" is here
三是会话:
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()
【问题讨论】:
标签: python tensorflow