【问题标题】:TensorFlow Indices are not valid (out of bounds)TensorFlow 索引无效(超出范围)
【发布时间】:2015-11-26 08:35:19
【问题描述】:

您好,我目前正在尝试使用自己的图像数据运行 TensorFlow。 但是当我试图运行这些函数时它崩溃了:它来自 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 是我的 batch_size,447 是我的类数。

我也尝试像这里一样解决这个问题 https://github.com/tensorflow/tensorflow/issues/194 将 indeces 行更改为此行:

indices = tf.expand_dims(tf.range(0, batch_size, 1), 1)

没有解决我的问题。 有人有想法吗?

【问题讨论】:

  • 您能否分享一些有关错误消息的上下文,包括失败的鼻子的名称?另外,您能否打印logits.get_shape()labels.get_shape() 以找出这些张量的预期形状是什么?
  • @mrry 嗨。我试过你的建议。我的标签是空的。所以我开始调试。然后我查看了我的 .tfrecords 文件,我看到标签和深度字段的值没有被写入。我使用了这个脚本中的 convert_to() 函数:link
  • @mrry 起初我想在第 56 行 (dat.shape[0], num_examples) 这个脚本里面有输入错误我认为它应该是 (images.shape[0], num_examples)第二件事是 .tfrecords 文件中的深度和标签值是空的。只有当我将第 69 行和第 70 行更改为 [code] ('depth': _bytes_feature(str(depth)),'label': _bytes_feature(label),) 时,我才能在 .tfrecords 文件中看到传递的深度和标签值。在那次更改之后,我最终出现了另一个错误,但如果我自己无法解决,我将发布一个新问题。非常感谢您的提示。
  • 您应该接受您的评论,解释您如何解决此问题并使其成为答案。我知道它没有让您的代码正常工作,但在这里它被认为是一个有效的答案。通过将其发布为答案,这将对其他人有所帮助,因为并非所有人都在 cmets 中寻找答案。

标签: python tensorflow


【解决方案1】:

我也有这个错误。我意识到我的错误。如果您有 10 个类,则您的标签值应介于 0-9 之间(含)。该错误在 TensorFlow CIFAR10 示例中重现,与 SVHN 数据集一起使用。请参阅下面的问答。

TensorFlow CIFAR10 Example

【讨论】:

    猜你喜欢
    • 2020-06-08
    • 1970-01-01
    • 2021-02-11
    • 2019-01-22
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多