Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
447 views
in Technique[技术] by (71.8m points)

python - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...