简体   繁体   中英

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

I am using tensorflow 1.0 CPU on ubuntu and python 3.5.

I adapted an example of tensorflow to work on my own dataset https://github.com/martin-gorner/tensorflow-mnist-tutorial

It works fine as long as the number of outputs is under 10. When the number of outputs is above 10,I get the error:

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

Any help?

I also came across the same error, and after fiddling with it for 2 days I came to realize there are 2 main reasons this error was getting thrown for my code and I mentioned them below to help anyone struggling with the same problem:

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

The index of the input word exceeds the length of the vocabulary, or the new words that are not included in the vocabulary.

Please try to enlarge vocabulary length.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM