Spaces:
Sleeping
Sleeping
Download src/models/wide.py from farrell236/OCT_Segmentation_a1: direct link, hf CLI and curl.
- Browser
- Download file 1.53 kB
-
https://huggingface.co/spaces/farrell236/OCT_Segmentation_a1/resolve/main/src/models/wide.py
- Command line
-
hf download hf://spaces/farrell236/OCT_Segmentation_a1/src/models/wide.py
-
curl -L -o wide.py https://huggingface.co/spaces/farrell236/OCT_Segmentation_a1/resolve/main/src/models/wide.py
1.53 kB
| """Own C3 body plus zero-initialized distant OCT inputs; no metadata features.""" | |
| import torch | |
| from torch import nn | |
| from torch.nn import functional as F | |
| from src.models.context import ContextBoundaryNet | |
| class WideBoundaryNet(ContextBoundaryNet): | |
| def __init__(self, n_boundaries, base, prior_height): | |
| super().__init__(n_boundaries, base, prior_height) | |
| self.outer_conv = nn.Conv2d(2, base, 3, padding=1, bias=False) | |
| nn.init.zeros_(self.outer_conv.weight) | |
| def forward(self, image): | |
| if image.ndim != 4 or image.shape[1] != 5: | |
| raise ValueError("Five OCT input views required") | |
| local = image[:, 1:4].contiguous() | |
| outer = image[:, [0, 4]].contiguous() | |
| first = self.down[0].net | |
| x = first[0](local) + self.outer_conv(outer) | |
| for layer in list(first)[1:]: | |
| x = layer(x) | |
| skips = [x] | |
| for layer in self.down[1:]: | |
| x = layer(F.avg_pool2d(x, 2)) | |
| skips.append(x) | |
| for index, layer in enumerate(self.up): | |
| skip = skips[-2 - index] | |
| x = F.interpolate( | |
| x, size=skip.shape[-2:], mode="bilinear", align_corners=False | |
| ) | |
| x = layer(torch.cat([x, skip], 1)) | |
| logits = self.head(x) | |
| 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 | |