MCPcopy Create free account
hub / github.com/UX-Decoder/Semantic-SAM / forward

Method forward

semantic_sam/backbone/swin_new.py:651–678  ·  view source on GitHub ↗

Forward function.

(self, x)

Source from the content-addressed store, hash-verified

649 nn.init.constant_(m.weight, 1.0)
650
651 def forward(self, x):
652 """Forward function."""
653 x = self.patch_embed(x)
654
655 Wh, Ww = x.size(2), x.size(3)
656 if self.ape:
657 # interpolate the position embedding to the corresponding size
658 absolute_pos_embed = F.interpolate(
659 self.absolute_pos_embed, size=(Wh, Ww), mode="bicubic"
660 )
661 x = (x + absolute_pos_embed).flatten(2).transpose(1, 2) # B Wh*Ww C
662 else:
663 x = x.flatten(2).transpose(1, 2)
664 x = self.pos_drop(x)
665
666 outs = {}
667 for i in range(self.num_layers):
668 layer = self.layers[i]
669 x_out, H, W, x, Wh, Ww = layer(x, Wh, Ww)
670
671 if i in self.out_indices:
672 norm_layer = getattr(self, f"norm{i}")
673 x_out = norm_layer(x_out)
674
675 out = x_out.view(-1, H, W, self.num_features[i]).permute(0, 3, 1, 2).contiguous()
676 outs["res{}".format(i + 2)] = out
677
678 return outs
679
680 def train(self, mode=True):
681 """Convert the model into training mode while keep layers freezed."""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected