Spaces:
Sleeping
Sleeping
File size: 1,525 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 31 32 33 34 35 36 37 38 39 40 41 | """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
|