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

Method forward

semantic_sam/backbone/focal.py:166–195  ·  view source on GitHub ↗

Forward function. Args: x: Input feature, tensor size (B, H*W, C). H, W: Spatial resolution of the input feature.

(self, x)

Source from the content-addressed store, hash-verified

164 self.gamma_2 = nn.Parameter(layerscale_value * torch.ones((dim)), requires_grad=True)
165
166 def forward(self, x):
167 """ Forward function.
168
169 Args:
170 x: Input feature, tensor size (B, H*W, C).
171 H, W: Spatial resolution of the input feature.
172 """
173 B, L, C = x.shape
174 H, W = self.H, self.W
175 assert L == H * W, "input feature has wrong size"
176
177 shortcut = x
178 if not self.use_postln:
179 x = self.norm1(x)
180 x = x.view(B, H, W, C)
181
182 # FM
183 x = self.modulation(x).view(B, H * W, C)
184 if self.use_postln:
185 x = self.norm1(x)
186
187 # FFN
188 x = shortcut + self.drop_path(self.gamma_1 * x)
189
190 if self.use_postln:
191 x = x + self.drop_path(self.gamma_2 * self.norm2(self.mlp(x)))
192 else:
193 x = x + self.drop_path(self.gamma_2 * self.mlp(self.norm2(x)))
194
195 return x
196
197class BasicLayer(nn.Module):
198 """ A basic focal modulation layer for one stage.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected