您必须使用dtype float输入占位符张量'占位符'的值
问题内容:
我是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 = Placeholderdtype=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()
问题答案:
一些问题
第一
,为什么你使用sess = tf.InteractiveSession()
,并with tf.Session() as sess:
在同一时间,只是好奇
第二你有什么占位符的名称x
或images
?
如果name是x
,{images: x_data...}
则不会提供x_data
给x
,它会覆盖(?)images
我认为feed_dict应该是{x: x_data...}
如果name是images
,images
程序中是否有两个,placeholder
并且shuffle data
,请尝试修改变量的名称