(self, predication, label)
| 443 | self.laplace_operator.weight = self.laplace |
| 444 | |
| 445 | def forward(self, predication, label): |
| 446 | grd_x = self.diff_x(predication) |
| 447 | grd_y = self.diff_y(predication) |
| 448 | grd_z = self.diff_z(predication) |
| 449 | diff = self.laplace_operator(predication) |
| 450 | |
| 451 | # length |
| 452 | length = torch.sqrt(grd_x ** 2 + grd_y ** 2 + grd_z ** 2 + 1e-8) |
| 453 | length = (length - length.min()) / (length.max() - length.min() + 1e-8) |
| 454 | |
| 455 | # curvature |
| 456 | if self.types: |
| 457 | curvature = torch.abs(diff) |
| 458 | curvature = (curvature - curvature.min()) / \ |
| 459 | (curvature.max() - curvature.min() + 1e-8) |
| 460 | else: |
| 461 | """ |
| 462 | maybe more powerful |
| 463 | """ |
| 464 | curvature = torch.abs( |
| 465 | diff) / ((grd_x ** 2 + grd_y ** 2 + grd_z ** 2 + 1) ** 0.5 + 1e-8) |
| 466 | curvature = (curvature - curvature.min()) / \ |
| 467 | (curvature.max() - curvature.min() + 1e-8) |
| 468 | # region |
| 469 | label = label.float() |
| 470 | c_in = torch.ones_like(predication) |
| 471 | c_out = torch.zeros_like(predication) |
| 472 | region_in = torch.abs(torch.sum(predication * ((label - c_in) ** 2))) |
| 473 | region_out = torch.abs( |
| 474 | torch.sum((1 - predication) * ((label - c_out) ** 2))) |
| 475 | region = self.miu * region_in + region_out |
| 476 | |
| 477 | # elastic |
| 478 | elastic = torch.sum((self.alpha + self.beta * curvature ** 2) * length) |
| 479 | return region + elastic |
| 480 | |
| 481 | |
| 482 | class FastACELoss3DV2(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected