【问题标题】:InvalidArgumentError (see above for traceback): indices[1] = 10 is not in [0, 10)InvalidArgumentError(参见上面的回溯):indices[1] = 10 is not in [0, 10)
【发布时间】:2017-07-22 21:15:38
【问题描述】:

我在 ubuntu 和 python 3.5 上使用 tensorflow 1.0 CPU。

我改编了一个 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)]]

有什么帮助吗?

【问题讨论】:

  • 那么回溯在哪里?
  • 能否请您发布/链接到您使用的代码(您所做的更改)?
  • 我根本不知道tensorflow,但是[0, 10)表示有效区间是左开右闭,也就是说有效值不包括10

标签: python python-3.x tensorflow


【解决方案1】:

我也遇到了同样的错误,在摆弄了 2 天后,我意识到我的代码引发了这个错误的主要原因有两个,我在下面提到了它们,以帮助任何遇到同样问题的人:

  1. 数据和标签的维度不同

  2. 就我而言,问题是 在建立我的词汇表时,我已经索引了 1 和 不是从 0 开始。但是嵌入层从 0 开始索引。所以它 一直给我提到的错误。我通过索引我的 从 0 开始的词汇。

    之前的代码:

    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)}
    

    为了修复它,我将最后一行更改为(删除 1):

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

【讨论】:

    【解决方案2】:

    输入词的索引超过了词表的长度,或者词表中没有包含的新词。

    请尝试扩大词汇长度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-28
      • 1970-01-01
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 2019-01-03
      • 2018-03-24
      相关资源
      最近更新 更多