S-aiueo32 / contextual_loss_pytorch

Contextual Loss (CX) and Contextual Bilateral Loss (CoBi).
MIT License
171 stars 45 forks source link

Nan when using cl.ContextualBilateralLoss(use_vgg=False, loss_type='cosine').cuda() #14

Open laulampaul opened 2 years ago

laulampaul commented 2 years ago

When I use the codes :

def calculate_cobiloss(img,gt):
    bb = img.shape[0]
    loss = 0.
    cobiloss = cl.ContextualBilateralLoss(use_vgg=False, loss_type='cosine').cuda()
    for i in range(bb):
        imgpatches = sample_patches(img[i],10,5)
        gtpatches = sample_patches(gt[i],10,5)
        c, patch_size, patch_size, n_patches = imgpatches.shape
        imgpatches = imgpatches.reshape(1,c*patch_size*patch_size,n_patches,1)
        gtpatches = gtpatches.reshape(1,c*patch_size*patch_size,n_patches,1)
        #pdb.set_trace()
        loss = loss +  cobiloss(imgpatches,gtpatches)
    return loss/bb

After some iterations, I face the NAN problem, how can I debug ?? Thanks.