在莫烦Python教程的“Dropout 解决 overfitting”一节中,出现错误如下:

InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [?,10]

runfile('E:/python/kerasTest/tfDropoutTest9.py', wdir='E:/python/kerasTest')
C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\sklearn\cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning) runfile('E:/python/kerasTest/tfDropoutTest9.py', wdir='E:/python/kerasTest')
Traceback (most recent call last): File "<ipython-input-2-64f3a3bcd083>", line 1, in <module>
runfile('E:/python/kerasTest/tfDropoutTest9.py', wdir='E:/python/kerasTest') File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
execfile(filename, namespace) File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace) File "E:/python/kerasTest/tfDropoutTest9.py", line 67, in <module>
train_result = sess.run(merged,feed_dict={xs:X_train,ys:y_train,keep_prob:1}) File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 895, in run
run_metadata_ptr) File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 1128, in _run
feed_dict_tensor, options, run_metadata) File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 1344, in _do_run
options, run_metadata) File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 1363, in _do_call
raise type(e)(node_def, op, message) InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [?,10]
[[Node: Placeholder_1 = Placeholder[dtype=DT_FLOAT, shape=[?,10], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]] Caused by op 'Placeholder_1', defined at:
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\spyder\utils\ipython\start_kernel.py", line 241, in <module>
main()
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\spyder\utils\ipython\start_kernel.py", line 237, in main
kernel.start()
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\ipykernel\kernelapp.py", line 477, in start
ioloop.IOLoop.instance().start()
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\zmq\eventloop\ioloop.py", line 177, in start
super(ZMQIOLoop, self).start()
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\tornado\ioloop.py", line 888, in start
handler_func(fd_obj, events)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper
return fn(*args, **kwargs)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\zmq\eventloop\zmqstream.py", line 440, in _handle_events
self._handle_recv()
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\zmq\eventloop\zmqstream.py", line 472, in _handle_recv
self._run_callback(callback, msg)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\zmq\eventloop\zmqstream.py", line 414, in _run_callback
callback(*args, **kwargs)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper
return fn(*args, **kwargs)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 283, in dispatcher
return self.dispatch_shell(stream, msg)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 235, in dispatch_shell
handler(stream, idents, msg)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 399, in execute_request
user_expressions, allow_stdin)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\ipykernel\ipkernel.py", line 196, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 2698, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 2808, in run_ast_nodes
if self.run_code(code, result):
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-64f3a3bcd083>", line 1, in <module>
runfile('E:/python/kerasTest/tfDropoutTest9.py', wdir='E:/python/kerasTest')
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
execfile(filename, namespace)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "E:/python/kerasTest/tfDropoutTest9.py", line 39, in <module>
ys = tf.placeholder(tf.float32,[None,10])
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1680, in placeholder
return gen_array_ops._placeholder(dtype=dtype, shape=shape, name=name)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 4105, in _placeholder
"Placeholder", dtype=dtype, shape=shape, name=name)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 3160, in create_op
op_def=op_def)
File "C:\Users\Admin\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 1625, in __init__
self._traceback = self._graph._extract_stack() InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [?,10]
[[Node: Placeholder_1 = Placeholder[dtype=DT_FLOAT, shape=[?,10], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

代码如下:

import tensorflow as tf
from sklearn.datasets import load_digits
from sklearn.cross_validation import train_test_split
from sklearn.preprocessing import LabelBinarizer #load data
digits = load_digits()
X = digits.data#从0到9的图片
y = digits.target
y =LabelBinarizer().fit_transform(y)
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=.3) def add_layer(inputs,in_size,out_size,layer_name,activation_function=None):
#add one more layer and return the output of this layer
Weights = tf.Variable(tf.random_normal([in_size,out_size]))
biases = tf.Variable(tf.zeros([1, out_size]) + 0.1)
Wx_plus_b = tf.matmul(inputs, Weights) + biases
Wx_plus_b = tf.nn.dropout(Wx_plus_b,keep_prob)
if activation_function is None:
outputs = Wx_plus_b
else:
outputs = activation_function(Wx_plus_b)
tf.summary.histogram(layer_name+'/outputs',outputs)
return outputs xs = tf.placeholder(tf.float32,[None,64])#8*8
ys = tf.placeholder(tf.float32,[None,10])
keep_prob = tf.placeholder(tf.float32) #add output layer
l1 = add_layer(xs,64,50,'l1',activation_function=tf.nn.tanh)
prediction = add_layer(l1,50,10,'l2',activation_function=tf.nn.softmax) #the loss between prediction and real data
cross_entropy = tf.reduce_mean(-tf.reduce_sum(ys * tf.log(prediction),
reduction_indices=[1]))#loss
tf.summary.scalar('loss',cross_entropy)
train_step = tf.train.GradientDescentOptimizer(0.6).minimize(cross_entropy) sess = tf.Session()
merged = tf.summary.merge_all()
train_writer = tf.summary.FileWriter("logs/train",sess.graph)
test_writer = tf.summary.FileWriter("logs/test",sess.graph) sess.run(tf.global_variables_initializer()) for i in range(500):
sess.run(train_step,feed_dict={xs:X_train,ys:y_train,keep_prob:0.5})
if i % 50 == 0:
train_result = sess.run(merged,feed_dict={xs:X_train,ys:y_train,keep_prob:1})
test_result = sess.run(merged,feed_dict={xs:X_test,ys:y_test,keep_prob:1})
train_writer.add_summary(train_result,i)
test_writer.add_summary(test_result,i)

原因:

在feed_dict中没有加入keep_prob的key和value

sess.run(train_step,feed_dict={xs:X_train,ys:y_train,keep_prob:0.5})中,没有写入keep_prob:0.5

造成feed_dict和placeholder的对应问题,但改正后,仍报该错误。反复检查了几遍,并没有发现问题。

最后实在无解,关闭了Spyder和anaconda,再打开anaconda和Spyder,居然可以正常运行了。。

但是也只是第一次可以正常运行,当删了生成的log文件,再次运行时,仍报该错误..至于为什么第二次运行就又报错仍未解决。

虽然问题不大,但是改了feed_dict后,问题还是没能解决,被困扰了一天,因此记录一下。

InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1' with dtype float and shape [?,10]的更多相关文章

  1. tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'x_1' with dtype float and shape [?,227,227,3]

    记一次超级蠢超级折磨我的bug. 报错内容: tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a ...

  2. Tensorflow报错:InvalidArgumentError: You must feed a value for placeholder tensor 'input_y' with dtype

    此错误神奇之处是每次第一次运行不会报错,第二次.第三次第四次....就都报错了.关掉重启,又不报错了,运行完再运行一次立马报错!搞笑! 折磨了我半天,终于被我给解决了! 问题解决来源于这边博客:htt ...

  3. 关于placeholder中 文字添加换行 用转义字符&#13;&#10;代替<br>

    今天遇到一个问题 UI给的效果图中 文本域的提示文字 是两行显示, 于是就想到placeholder中能否解析html标签, 尝试后发现并无卵用, 经过调查后发现 可以用转义字符代替<br> ...

  4. typeError:The value of a feed cannot be a tf.Tensor object.Acceptable feed values include Python scalars,strings,lists.numpy ndarrays,or TensorHandles.For reference.the tensor object was Tensor...

    如上贴出了:错误信息和错误代码. 这个问题困扰了自己两天,报错大概是说输入的数据和接受的格式不一样,不能作为tensor. 后来问了大神,原因出在tf.reshape(),因为网络训练时用placeh ...

  5. InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [2048,38] rhs shape= [2048,2]

    做tensorflow object detection 中,清空下checkpoint就可以啦

  6. tensorflow ValueError: Cannot feed value of shape (5000,) for Tensor 'output:0', which has shape '(?, 10)'

    提供的训练数据和定义的模型之间的维度不对应. 在MNIST手写数字识别时,在 mnist = input_data.read_data_sets("MNIST_data/") 中, ...

  7. 实战Google深度学习框架-C3-TensorFlow入门

    第三章:TensorFlow入门 TensorFlow存在计算模型,数据模型和运算模型(本文用TF代表TensorFlow) 3.1 计算模型-计算图 3.1.1 计算图的概念 TensorFlow这 ...

  8. 使用TensorFlow的卷积神经网络识别自己的单个手写数字,填坑总结

    折腾了几天,爬了大大小小若干的坑,特记录如下.代码在最后面. 环境: Python3.6.4 + TensorFlow 1.5.1 + Win7 64位 + I5 3570 CPU 方法: 先用MNI ...

  9. [2] TensorFlow 向前传播算法(forward-propagation)与反向传播算法(back-propagation)

    TensorFlow Playground http://playground.tensorflow.org 帮助更好的理解,游乐场Playground可以实现可视化训练过程的工具 TensorFlo ...

随机推荐

  1. 菜鸟vimer成长记——第2.3章、insert模式

    大部分的Vim 命令都在非插入模式中执行,不过有些功能在插入模式中会更好实现些. 如果没有输入当前文件不存在的新文本的需求时,建议通过其他模式来操作完成. 目的 掌握inser模式下常用操作的语法和概 ...

  2. Win10版本号区分

      版本号 内部版本号 UniversalApiContract  首个正式版 1507 10240 1  首个重大更新 1511 10586 2  一周年更新 Anniversary Update ...

  3. bootstrap学习笔记(5)

    Bootstrap输入框组 主要记住一个原则 创建输入框的步骤 把前缀或后缀元素放在一个带有 class .input-group 的 <div> 中. 接着,在相同的 <div&g ...

  4. 【日常训练】 Help Greg the Dwarf(CodeForces-99E)

    题意与分析 题意是这样的,问你把一个长方形从一个L型街道的一端移动到另一端,固定了该长方形的长,求他的最大宽. 这种问题我是第一次独立解决(以前都是抱队友大腿QAQ),现在没法子只好自己硬着头皮做,看 ...

  5. 用人工智能学习,凡亿推出PCB问题解答智能搜索机器人:pcb助手

    对于学习者,你是不是经常遇到这样的问题:在我们狠狠下定决心学习PCB技术的时候,我们常常遇到很多大大小小的问题,遗憾的是身边没有一个能及时给自己解答问题的高手指点,通过论坛.群等方式询问可能半天也得不 ...

  6. Tetris(俄罗斯方块)

    一天有个小朋友问我OpenGL俄罗斯方块怎么写. 俄罗斯方块分成两部分游戏逻辑和画面渲染. 1. 游戏逻辑 一个简单的俄罗斯方块的逻辑部分需要考虑的情况如下: 1. 方块的表示(坐标, 旋转, 上下左 ...

  7. Unity3D画面渲染官方教程(一)对光照和渲染的介绍

    本系列是对官方教程的翻译加上自己的一些理解译著的,官方网址:https://unity3d.com/cn/learn/tutorials/s/graphics 翻译上尽量保证准确性,但不排除省略或者添 ...

  8. python所遇到的坑

    我是在ubuntu中,自带的有python2,python3有安装了anaconda套件,所以python的版本很多,曾经想删除过不用的python. 先执行 sudo apt remove pyth ...

  9. python之模块_随手记录的模块

    目录 1.StringIO模块 2.string模块 3.pprint模块 4.struct模块 5.uuid模块 6.itertools 7.prettytable 1.StringIO (1)使用 ...

  10. sprint2(第二天)

    昨天没有想到餐桌的功能,今天加到展板.然后今天我们完成了餐桌模板,可以实现添加桌子的桌号.人数.修改和删除功能.不过由于今天学校网络不是很好,晚上我们clone了很久都没clone下来,所以没有上传代 ...