我在TensorFlow图像识别学习中,遇到的困难!!!
错误:
Traceback (most recent call last):
File "as1_train.py", line 199, in <module>
main()
File "as1_train.py", line 174, in main
run_training()
File "as1_train.py", line 68, in run_training
summary_str = sess.run(summary_op)
File "/home/mrzhang/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 895, in run
run_metadata_ptr)
File "/home/mrzhang/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1124, in _run
feed_dict_tensor, options, run_metadata)
File "/home/mrzhang/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1321, in _do_run
options, run_metadata)
File "/home/mrzhang/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1340, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: targets[20] is out of range
[[Node: accuracy/InTopK = InTopK[T=DT_INT32, k=1, _device="/job:localhost/replica:0/task:0/cpu:0"](softmax_linear/softmax_linear_1/_5333, Reshape_1/_5335)]]
Caused by op u'accuracy/InTopK', defined at:
File "as1_train.py", line 199, in <module>
main()
File "as1_train.py", line 174, in main
run_training()
File "as1_train.py", line 40, in run_training
train_acc = as1_model.evaluation(train_logits,label_batch)
File "/home/mrzhang/xin/py3/test/as1_model.py", line 135, in evaluation
correct = tf.nn.in_top_k(logits, labels, 1)
File "/home/mrzhang/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 1466, in in_top_k
targets=targets, k=k, name=name)
File "/home/mrzhang/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
op_def=op_def)
File "/home/mrzhang/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2630, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/home/mrzhang/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1204, in __init__
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
InvalidArgumentError (see above for traceback): targets[20] is out of range
[[Node: accuracy/InTopK = InTopK[T=DT_INT32, k=1, _device="/job:localhost/replica:0/task:0/cpu:0"](softmax_linear/softmax_linear_1/_5333, Reshape_1/_5335)]]
找了好久,终于找到错误原因,不过并没有解决!!
可以参考:https://stackoverflow.com/questions/38881918/tensorflow-tf-nn-in-top-k-targets-out-of-range-error
上面大意是:比如我分类8类,如果我的标签labels是(1,2,3,4,6,7,8,9),就会出现上面的错误;必须改成(1,2,3,4,5,6,7,8);然而我遇到的问题是必须从0开始,即标签必须是(0,1,2,3,4,5,6,7)。然后可以训练了。
为什么会出现这个错误?还没有找到原因,原文中说:it`s an issue
有兴趣的可以去找找原因!!!