"""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