HRNet-Image-Classification icon indicating copy to clipboard operation
HRNet-Image-Classification copied to clipboard

the loss become nan

Open niyunsheng opened this issue 5 years ago • 1 comments

when i was trying to recurrence the face-xray, I modified the HRNet-Image-Calssification, but I got a bug that loss is nan. this is what i added after stage4 in the cls_hrnet.py:

        # Upsampling
        x0_h, x0_w = y_list[0].size(2), y_list[0].size(3)
        x1 = F.interpolate(y_list[1], size=(x0_h, x0_w), mode='bilinear',align_corners=True)
        x2 = F.interpolate(y_list[2], size=(x0_h, x0_w), mode='bilinear',align_corners=True)
        x3 = F.interpolate(y_list[3], size=(x0_h, x0_w), mode='bilinear',align_corners=True)

        x = torch.cat([y_list[0], x1, x2, x3], 1)
        x = self.one_conv2d(x) # one conv2d to make the channel to 1
       
        x = F.interpolate(x, size=(224,224),mode='bilinear',align_corners=True)
        xray = torch.sigmoid(x)

then I found the xray is almost zero and the loss is nan, what's wrong?

I write the loss function below:

    def criterion(pred,target):
        x = torch.add(torch.mul(target,torch.log(pred)),torch.mul(torch.sub(1,target),torch.log(torch.sub(1,pred))))
        loss = -torch.mean(x)
        return loss

niyunsheng avatar May 15 '20 03:05 niyunsheng

hello,do you know how to train my own dataset?

xiaoshuyun avatar Apr 14 '21 03:04 xiaoshuyun