tensorflow-softmax忽略负标签(就像caffe一样) [英] tensorflow - softmax ignore negative labels (just like caffe)

查看:346
本文介绍了tensorflow-softmax忽略负标签(就像caffe一样)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Caffe中,有一个选项带有SoftmaxWithLoss函数,可忽略计算概率中的所有负标签(-1),因此只有0或正标签概率加起来为1。

In Caffe, there is an option with its SoftmaxWithLoss function to ignore all negative labels (-1) in computing probabilities, so that only 0 or positive label probabilities add up to 1.

Tensorflow softmax损失有类似的功能吗?

Is there a similar feature with Tensorflow softmax loss?

推荐答案

只是想出一种解决方法---我使用tf在标签索引上创建了一个单张量。 one_hot(深度设置为标签数)。 tf.one_hot自动将所得的one_hot张量(形状为[批处理,标签的数量])中所有带有-1的索引归零。

Just came up with a work-around --- I created a one-hot tensor on the label indices using tf.one_hot (with the depth set at the # of labels). tf.one_hot automatically zeros out all indices with -1 in the resulting one_hot tensor (of shape [batch, # of labels])

这将启用softmax损失(即tf。 nn.softmax_cross_entropy_with_logits)以忽略所有-1个标签。

This enables softmax loss (i.e. tf.nn.softmax_cross_entropy_with_logits) to "ignore" all -1 labels.

这篇关于tensorflow-softmax忽略负标签(就像caffe一样)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆