tensorflow运行cnn卷积神经网络时出现问题具体如下:
Traceback (most recent call last): File "cnn_mnist.py", line 88, in <module> train_loss, train_op = sess.run([loss, train_op], {input_x: batch[0], output_y:batch[1]}) File "/home/wmm/wmmf/Envs/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 929, in run run_metadata_ptr) File "/home/wmm/wmmf/Envs/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1137, in _run self._graph, fetches, feed_dict_tensor, feed_handles=feed_handles) File "/home/wmm/wmmf/Envs/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 471, in __init__ self._fetch_mapper = _FetchMapper.for_fetch(fetches) File "/home/wmm/wmmf/Envs/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 261, in for_fetch return _ListFetchMapper(fetch) File "/home/wmm/wmmf/Envs/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 370, in __init__ self._mappers = [_FetchMapper.for_fetch(fetch) for fetch in fetches] File "/home/wmm/wmmf/Envs/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 258, in for_fetch type(fetch))) TypeError: Fetch argument None has invalid type <type 'NoneType'>而且循环的第一步进行得很顺畅,从第二步开始报这个错误。
可以根据报错看到问题出现在第88行:
train_loss, train_op = sess.run([loss, train_op], {input_x: batch[0], output_y:batch[1]})为什么第一次没有错,而第二次出错呢? 可以看到这一行有两个相同变量train_op,在第一次迭代时,train_op变量被赋值了sess.run()结果的第二个元素,恰好是None,导致第二次迭代中sess.run()中的train_op变成了None,就出错了。 解决的方法很简单,就是把两个变量的第二个变量改为“_”(或者是任意的变量名如“hhh”):
train_loss, _ = sess.run([loss, train_op], {input_x: batch[0], output_y:batch[1]})参考(转载)自:https://blog.csdn.net/qq_41000891/article/details/84555225