Tensorflow tf.nn.in_top_k报错 Error targets[0] is out of range

用cifar10在做分类问题的的时候遇到了这个问题

在国内网站上貌似没有相关的信息

但是在stackoverflow上面有人在讨论:

https://stackoverflow.com/questions/37587622/tf-nn-in-top-k-targets-out-of-range

其中有个人的回复很有意思

--------------------------------------------

To sum it up, the function tf.nn.in_top_k(predictions, targets, k) (see the doc) has arguments:

  • predictions: shape [batch_size, num_classes], type float32
  • targets (the correct label): shape [batch_size], type int32 or int64

The function raises the error InvalidArgumentError: targets[i] is out of range when the element targets[i] is out of range in predictions[i].

For instance, there are 2 classes (num_classes=2) and targets=[1, 3]. With these targets, you will see an error InvalidArgumentError: targets[1] is out of range because targets[1] = 3 is out of range for predictions[1] which has only shape 2.


To check that your labels are correct, you can print the max of them:

labels = ...
labels_max = tf.reduce_max(labels)

sess = tf.Session()
print sess.run(labels_max)

If the value printed is superior to num_classes, you have a problem.

--------------------------------------------

以上是一个很好的分析思路

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值