【发布时间】:2021-06-23 09:03:23
【问题描述】:
我正在尝试实现论文“Large-Scale Object Detection in the Wild from Imbalanced Multi-Labels”中给出的所谓的“并发”softmax 函数。下面是并发softmax的定义:
注意:我暂时不使用 (1-rij) 术语,因为我认为它不适用于我的问题,因为与论文相比,我的训练数据集具有不同类型的标签。
为了让我自己保持简单,我开始使用 for 循环以一种非常低效但易于遵循的方式实现它。但是,我得到的输出对我来说似乎是错误的。以下是我正在使用的代码:
# here is a one-hot encoded vector for the multi-label classification
# the image thus has 2 correct labels out of a possible 3 classes
y = [0, 1, 1]
# these are some made up logits that might come from the network.
vec = torch.tensor([0.2, 0.9, 0.7])
def concurrent_softmax(vec, y):
for i in range(len(vec)):
zi = torch.exp(vec[i])
sum_over_j = 0
for j in range(len(y)):
sum_over_j += (1-y[j])*torch.exp(vec[j])
out = zi / (sum_over_j + zi)
yield out
for result in concurrent_softmax(vec, y):
print(result)
从这个实现中我意识到,无论我给 'vec' 中的第一个 logit 赋予什么值,我总是会得到 0.5 的输出(因为它基本上总是计算 zi / (zi+zi))。这似乎是一个主要问题,因为我预计 logits 的值会对生成的 concurrent-softmax 值产生一些影响。那么我的实现是否存在问题,或者函数的这种行为是否正确并且理论上我不理解某些东西?
【问题讨论】:
-
我不明白为什么看到您将 r_ij 术语排除在外,这是错误的?
标签: python pytorch normalization loss-function softmax