in seamseg/modules/fpn.py [0:0]
def forward(self, xs):
"""Feature Pyramid Network module
Parameters
----------
xs : sequence of torch.Tensor
The input feature maps, tensors with shapes N x C_i x H_i x W_i
Returns
-------
ys : sequence of torch.Tensor
The output feature maps, tensors with shapes N x K x H_i x W_i
"""
ys = []
interp_params = {"mode": self.interpolation}
if self.interpolation == "bilinear":
interp_params["align_corners"] = False
# Build pyramid
for x_i, lateral_i in zip(xs[::-1], self.lateral[::-1]):
x_i = lateral_i(x_i)
if len(ys) > 0:
x_i = x_i + functional.interpolate(ys[0], size=x_i.shape[-2:], **interp_params)
ys.insert(0, x_i)
# Compute outputs
ys = [output_i(y_i) for y_i, output_i in zip(ys, self.output)]
# Compute extra outputs if necessary
if hasattr(self, "extra"):
y = xs[-1]
for extra_i in self.extra:
y = extra_i(y)
ys.append(y)
return ys