nima.pytorch icon indicating copy to clipboard operation
nima.pytorch copied to clipboard

your emd loss seems wrong

Open HuaZheLei opened this issue 5 years ago • 1 comments

Your implement is as below:

    samplewise_emd = torch.sqrt(torch.mean(torch.pow(torch.abs(cdf_diff), 2)))
    return samplewise_emd.mean()

However, I think the correct implement should be:

    emd = torch.sqrt(torch.mean(torch.pow(torch.abs(cdf_diff), 2), -1))
    return emd.mean()

As https://github.com/titu1994/neural-image-assessment/blob/master/train_mobilenet.py mentioned,

def earth_mover_loss(y_true, y_pred): cdf_ytrue = K.cumsum(y_true, axis=-1) cdf_ypred = K.cumsum(y_pred, axis=-1) samplewise_emd = K.sqrt(K.mean(K.square(K.abs(cdf_ytrue - cdf_ypred)), axis=-1)) return K.mean(samplewise_emd)

Please check it!

HuaZheLei avatar Jul 19 '19 09:07 HuaZheLei

I also found this problem... It turns out that it's not samplewise emd after applying mean function without setting dimension.

jingwenh avatar Apr 03 '20 16:04 jingwenh