(self, predication, label)
| 32 | self.diff_y.weight = self.sobel_y |
| 33 | |
| 34 | def forward(self, predication, label): |
| 35 | grd_x = self.diff_x(predication) |
| 36 | grd_y = self.diff_y(predication) |
| 37 | |
| 38 | # length |
| 39 | length = torch.sum( |
| 40 | torch.abs(torch.sqrt(grd_x ** 2 + grd_y ** 2 + 1e-8))) |
| 41 | length = (length - length.min()) / (length.max() - length.min() + 1e-8) |
| 42 | length = torch.sum(length) |
| 43 | |
| 44 | # region |
| 45 | label = label.float() |
| 46 | c_in = torch.ones_like(predication) |
| 47 | c_out = torch.zeros_like(predication) |
| 48 | region_in = torch.abs(torch.sum(predication * ((label - c_in) ** 2))) |
| 49 | region_out = torch.abs( |
| 50 | torch.sum((1 - predication) * ((label - c_out) ** 2))) |
| 51 | region = self.miu * region_in + region_out |
| 52 | |
| 53 | return region + length |
| 54 | |
| 55 | |
| 56 | class ACLossV2(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected