From 2182048242c0b06600baf74a141dde9264b6ab24 Mon Sep 17 00:00:00 2001 From: Huayuan Ye <110151316+huayuan4396@users.noreply.github.com> Date: Fri, 27 Dec 2024 13:33:22 +0800 Subject: [PATCH] Update __init__.py Avoid obtaining NaN loss value during training --- pytorch_iou/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_iou/__init__.py b/pytorch_iou/__init__.py index ead1f724..3ece53e0 100644 --- a/pytorch_iou/__init__.py +++ b/pytorch_iou/__init__.py @@ -10,7 +10,7 @@ def _iou(pred, target, size_average = True): for i in range(0,b): #compute the IoU of the foreground Iand1 = torch.sum(target[i,:,:,:]*pred[i,:,:,:]) - Ior1 = torch.sum(target[i,:,:,:]) + torch.sum(pred[i,:,:,:])-Iand1 + Ior1 = torch.sum(target[i,:,:,:]) + torch.sum(pred[i,:,:,:])-Iand1 + 1e-6 IoU1 = Iand1/Ior1 #IoU loss is (1-IoU1)