Spaces:
Sleeping
Sleeping
Download src/models/context.py from farrell236/OCT_Segmentation_a1: direct link, hf CLI and curl.
- Browser
- Download file 992 Bytes
-
https://huggingface.co/spaces/farrell236/OCT_Segmentation_a1/resolve/main/src/models/context.py
- Command line
-
hf download hf://spaces/farrell236/OCT_Segmentation_a1/src/models/context.py
-
curl -L -o context.py https://huggingface.co/spaces/farrell236/OCT_Segmentation_a1/resolve/main/src/models/context.py
992 Bytes
| """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 | |