I’m not getting a negative loss in any of the two approaches:
conf_consistency_criterion = torch.nn.KLDivLoss(size_average=False, reduce=False).cuda()
output = torch.randn(16, 1, 8, 224, 224  )
flip_op = torch.randn(16, 1, 8, 224, 224)
output = torch.flip(output, [4])
output = torch.mean(output, 2) # 16, 1, 224, 224
flip_op = torch.mean(flip_op, 2) # 16, 1, 224, 224
output = torch.squeeze(output, 1) # 16, 224, 224
flip_op = torch.squeeze(flip_op, 1) # 16, 224, 224
# CONS_LOSS
output += 1e-7
flip_op += 1e-7
cons_loss_a = conf_consistency_criterion(F.logsigmoid(output), torch.sigmoid(flip_op)).sum(-1).mean()
print(cons_loss_a)


output = torch.randn(16, 1, 8, 224, 224)
flip_op = torch.randn(16, 1, 8, 224, 224)
output = torch.flip(output, [4])    
# CONS_LOSS
output += 1e-7
flip_op += 1e-7
cons_loss_a = conf_consistency_criterion(F.logsigmoid(output), F.sigmoid(flip_op)).sum(-1).mean()
print(cons_loss_a)

so don’t know what might be causing this issue.