PaddleDetection
PaddleDetection copied to clipboard
修改ssd_loss的softmax_with_cross_entropy为focal_loss
修改ssd_loss的softmax_with_cross_entropy为focal_loss
我在detection.py文件里面添加了下面这个函数
def softmax_focal_loss(pred, label, alpha=0.25, gamma=2, epsilon=1e-6):
'''
alpha 越大越关注y=1的情况
gamma 越大越关注不确定的情况
'''
pred = nn.softmax(pred, axis=-1)
label = tensor.cast(label,dtype='float64')
pred = nn.clip(pred, epsilon, 1 - epsilon)
loss = -1 * (alpha * nn.pow((1 - pred), gamma) * label * nn.log(pred) + (1 - alpha) * nn.pow(pred, gamma) * (1 - label) * nn.log(1 - pred))
loss = nn.reduce_mean(loss, dim=-1)
loss = nn.unsqueeze(loss, axes=[1])
并将ssd_loss里面的softmax_with_cross_entropy替换为了 softmax_focal_loss
可以运行,loss也在下降,但是预测效果明显不如softmax_with_cross_entropy,原来map为90多,现在只有15左右,请问是我修改的不对么?
我也在搞这个,感觉不太对。label里是类别的序号,不是01值
Since this issue has not been updated for more than three months, it will be closed, if it is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up. It is recommended to pull and try the latest code first. 由于该问题超过三个月未更新,将会被关闭,若问题未解决或有后续问题,请随时重新打开(建议先拉取最新代码进行尝试),我们会继续跟进。