Forward function. Args: x: Input feature, tensor size (B, H*W, C). H, W: Spatial resolution of the input feature.
(self, x)
| 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 | |
| 197 | class BasicLayer(nn.Module): |
| 198 | """ A basic focal modulation layer for one stage. |
nothing calls this directly
no outgoing calls
no test coverage detected