MCPcopy Create free account
hub / github.com/HiLab-git/ACELoss / forward

Method forward

aceloss.py:508–541  ·  view source on GitHub ↗
(self, predication, label)

Source from the content-addressed store, hash-verified

506 self.laplace_operator.weight = self.laplace
507
508 def forward(self, predication, label):
509 min_pool_x = nn.functional.max_pool3d(predication * -1, 3, 1, 1) * -1
510 contour = torch.relu(nn.functional.max_pool3d(
511 min_pool_x, 3, 1, 1) - min_pool_x)
512
513 diff = self.laplace_operator(predication)
514
515 # length
516 length = torch.abs(contour)
517
518 # curvature
519 if self.types:
520 curvature = torch.abs(diff)
521 curvature = (curvature - curvature.min()) / \
522 (curvature.max() - curvature.min() + 1e-8)
523 else:
524 """
525 maybe more powerful
526 """
527 curvature = torch.abs(diff) / ((length ** 2 + 1) ** 0.5 + 1e-8)
528 curvature = (curvature - curvature.min()) / \
529 (curvature.max() - curvature.min() + 1e-8)
530 # region
531 label = label.float()
532 c_in = torch.ones_like(predication)
533 c_out = torch.zeros_like(predication)
534 region_in = torch.abs(torch.sum(predication * ((label - c_in) ** 2)))
535 region_out = torch.abs(
536 torch.sum((1 - predication) * ((label - c_out) ** 2)))
537 region = self.miu * region_in + region_out
538
539 # elastic
540 elastic = torch.sum((self.alpha + self.beta * curvature ** 2) * length)
541 return region + elastic
542
543
544"test demo"

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected