MCPcopy Create free account
hub / github.com/ZhengPeng7/BiRefNet / IoULoss

Class IoULoss

loss.py:71–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69
70
71class IoULoss(torch.nn.Module):
72 def __init__(self):
73 super(IoULoss, self).__init__()
74
75 def forward(self, pred, target):
76 b = pred.shape[0]
77 IoU = 0.0
78 for i in range(0, b):
79 # compute the IoU of the foreground
80 Iand1 = torch.sum(target[i, :, :, :] * pred[i, :, :, :])
81 Ior1 = torch.sum(target[i, :, :, :]) + torch.sum(pred[i, :, :, :]) - Iand1
82 IoU1 = Iand1 / Ior1
83 # IoU loss is (1-IoU1)
84 IoU = IoU + (1-IoU1)
85 # return IoU/b
86 return IoU
87
88
89class StructureLoss(torch.nn.Module):

Callers 2

__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected