truskovskiyk / nima.pytorch

NIMA: Neural IMage Assessment
MIT License
330 stars 79 forks source link

your emd loss seems wrong #24

Open HuaZheLei opened 5 years ago

HuaZheLei commented 5 years ago

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!

jingwenh commented 4 years ago

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