无效参数错误(请参见上面的回溯):indices[1] = 10不在[0, 10)中。

3
我正在使用tensorflow 1.0 CPU在Ubuntu和Python 3.5上。我将tensorflow的一个示例应用于自己的数据集 https://github.com/martin-gorner/tensorflow-mnist-tutorial。只要输出数量少于10个,它就可以正常运行。当输出数量超过10个时,我会收到以下错误提示:
InvalidArgumentError (see above for traceback): indices[1] = 10 is not in [0, 10)

[[Node: Gather_4 = Gather[Tindices=DT_INT64, 
     Tparams=DT_FLOAT, 
     validate_indices=true, 
     _device="/job:localhost/replica:0/task:0/cpu:0"](grayscale_to_rgb, ArgMax_4)]]

需要帮助吗?


那么回溯信息在哪里? - jwodder
请问您能否发布/链接您所使用的代码(所做的更改)? - Harsha Pokkalla
1
我完全不了解TensorFlow,但[0, 10)表示有效区间是左开右闭的,换句话说,有效值不包括10 - Łukasz Rogalski
2个回答

4

我也遇到了相同的错误,折腾了两天后,我发现这个错误出现的主要原因有两个,我在下面列出来,希望能帮助到任何遇到同样问题的人:

  1. The dimensions of your data and your labels being different

  2. In my case, the problem was that when building my vocabulary I have indexed the words from 1 and not from 0. But the embedded layer starts indexing from 0. So it kept giving me the mentioned error. I fixed the error by indexing my vocabulary from 0.

    previous code:

    dictionary = Counter(words)
    sorted_split_words = sorted(dictionary, key=dictionary.get, reverse=True)
    vocab_to_int = {c: i for i, c in enumerate(sorted_split_words, 1)}
    

    to fix it I changed the last line to (removed 1):

    vocab_to_int = {c: i for i, c in enumerate(sorted_split_words)}
    

1
输入单词的索引超出了词汇表的长度,或者是不包含在词汇表中的新单词。
请尝试扩大词汇表长度。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接