TensorFlow 索引无效(越界) [英] TensorFlow Indices are not valid (out of bounds)
问题描述
我目前正在尝试使用自己的图像数据运行 TensorFlow.但是当我尝试运行这些函数时它崩溃了:它来自 mnist.py
Hi i'am currently trying to run TensorFlow with own image data. But it crashes when i'am trying to run these function: its from mnist.py
def loss_fn(logits, labels):
batch_size = tf.size(labels)
labels = tf.expand_dims(labels, 1)
indices = tf.expand_dims(tf.range(0, batch_size, 1), 1)
concated = tf.concat(1, [indices, labels])
onehot_labels = tf.sparse_to_dense(
concated, tf.pack([batch_size, NUM_CLASSES]), 1.0, 0.0)
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(logits,
onehot_labels,name='xentropy')
loss = tf.reduce_mean(cross_entropy, name='xentropy_mean')
return loss
出现此错误:
Compute status: Invalid argument: Indices are not valid (out of bounds). Shape: dim { size: 100 } dim { size: 447 }
数字 100 是我的批次大小,447 是我的类数.
the number 100 is my batch_size and 447 is my number of classes.
我也尝试像这里一样解决这个问题https://github.com/tensorflow/tensorflow/issues/194将 indeces 行更改为此行:
i also try to solve that issue like here https://github.com/tensorflow/tensorflow/issues/194 changing the indeces line into this line:
indices = tf.expand_dims(tf.range(0, batch_size, 1), 1)
没有解决我的问题.有人有想法吗?
didn't solve my problem. Does anybody have an idea?
推荐答案
我也遇到了这个错误.我意识到了我的错误.如果您有 10 个类,则您的标签值应介于 0-9 之间,包括 0-9.该错误在 TensorFlow CIFAR10 示例中重现,与 SVHN 数据集一起使用.请参阅下面的问答.
I had this error as well. And I realized my mistake. If you have 10 classes, your label values should range between 0-9, inclusive. The error was reproduced on the TensorFlow CIFAR10 example, used with SVHN dataset. Refer to question and answer below.
这篇关于TensorFlow 索引无效(越界)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!