[英]Tensorflow InvalidArgumentError (see above for traceback): Incompatible shapes: [10000,10] vs. [10000]
[英]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开始而不是从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.