BalancedMSE icon indicating copy to clipboard operation
BalancedMSE copied to clipboard

About the "bmc_loss_md"

Open SongYxing opened this issue 2 years ago • 3 comments

Thanks for your work.

def bmc_loss_md(pred, target, noise_var): I = torch.eye(pred.shape[-1]) logits = MVN(pred.unsqueeze(1), noise_var*I).log_prob(target.unsqueeze(0)) loss = F.cross_entropy(logits, torch.arange(pred.shape[0])) loss = loss * (2 * noise_var).detach() return loss

My size of pred and target are [30,3,256,256] when running this code "loss = F.cross_entropy(logits, torch.arange(pred.shape[0]))",i got a error because "torch.arange(pred.shape[0])"is 1d,and logits is 4d.

How can i solve this error

SongYxing avatar Sep 23 '22 10:09 SongYxing

You may resize both pred & target to 2D tensors with size [30,3x256x256].

jiawei-ren avatar Oct 01 '22 05:10 jiawei-ren

I have tried.But it will out of memory when creating diagonal matrix. I run this code "pred=pred.reshape(pred.shpe[0],-1)" ,the shape of output is[30,3x256x256].

微信图片_20221001140150

SongYxing avatar Oct 01 '22 06:10 SongYxing

I have not tested balanced mse on image reconstruction but you may try downsampling the image to a smaller resolution, e.g., 32x32. Sorry for the late reply.

jiawei-ren avatar Oct 04 '22 11:10 jiawei-ren