Spaces:
Sleeping
Sleeping
File size: 992 Bytes
8fca640 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | """Three adjacent OCT B-scans as image channels, with center-frame outputs."""
import torch
from torch import nn
from torch.nn import functional as F
from src.models.unet import BoundaryNet, Block
class ContextBoundaryNet(BoundaryNet):
def __init__(self, n_boundaries, base, prior_height=None):
super().__init__(n_boundaries, base)
self.down[0] = Block(3, base)
if prior_height is None:
self.register_parameter("axial_prior", None)
else:
self.axial_prior = nn.Parameter(
torch.zeros(1, n_boundaries, prior_height, 1)
)
def forward(self, image):
logits = super().forward(image)
if self.axial_prior is None:
return logits
prior = self.axial_prior
if prior.shape[-2] != logits.shape[-2]:
prior = F.interpolate(
prior, size=(logits.shape[-2], 1), mode="bilinear", align_corners=False
)
return logits + prior
|