提供占位符时出错

时间:2017-08-01 08:23:00

标签: tensorflow jupyter-notebook conv-neural-network

我在我的占位符(keep_prob)中遇到问题。错误说我必须提供一个浮点值,但我已经在做了。我一直试图解决它,但我找不到解决方案。我的代码在这里:

Error while running a convolutional network using my own data in Tensorflow

我的错误是:

File "<ipython-input-81-fd184c90091e>", line 4, in <module>
keep_prob = tf.placeholder(tf.float32)
File "c:\python36\lib\site-packages\tensorflow\python\ops\array_ops.py", 
line 1530, in placeholder
return gen_array_ops._placeholder(dtype=dtype, shape=shape, name=name)
File "c:\python36\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", 
line 1954, in _placeholder
name=name)
File "c:\python36\lib\site-
packages\tensorflow\python\framework\op_def_library.py", line 767, in 
apply_op
op_def=op_def)
File "c:\python36\lib\site-packages\tensorflow\python\framework\ops.py", 
line 2506, in create_op
original_op=self._default_original_op, op_def=op_def)
File "c:\python36\lib\site-packages\tensorflow\python\framework\ops.py", 
line 1269, in __init__
self._traceback = _extract_stack()

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

谢谢。

1 个答案:

答案 0 :(得分:2)

我怀疑你的错误不是来自你认为的那一行。我无法运行你的代码,但看着它,我的猜测如下:

您在这里提供keep_prob值,这对于培训是可以的:

train_step.run(feed_dict={x: image_batch_eval, y_: label_batch_eval, 
  keep_prob: 0.5})

但是你没有在这里提供keep_prob值,你也必须这样做:

print('Precisión %g' % accuracy.eval(feed_dict={x: image_test_batch_eval, 
y_: label_test_batch_eval}))

如果查看代码,accuracy操作最终会占用此操作,这需要占位符:

h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)

因此,如果您正在评估验证或测试准确性,那么饲料值1.0否则会喂养您正在喂养的任何培训。

试一试?