簡體   English   中英

InvalidArgumentError(參見上面的回溯):indices [1] = 10不在[0,10]中

[英]InvalidArgumentError (see above for traceback): indices[1] = 10 is not in [0, 10)

我在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)]]

有幫助嗎?

我也遇到了同樣的錯誤,在擺弄它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)} 

輸入詞的索引超出詞匯的長度,或詞匯中未包括的新詞。

請盡量擴大詞匯長度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM