(
dim, norm_layer, in_format="channels_last", out_format="channels_last", eps=1e-6
)
| 13 | |
| 14 | |
| 15 | def build_norm_layer( |
| 16 | dim, norm_layer, in_format="channels_last", out_format="channels_last", eps=1e-6 |
| 17 | ): |
| 18 | layers = [] |
| 19 | if norm_layer == "BN": |
| 20 | if in_format == "channels_last": |
| 21 | layers.append(to_channels_first()) |
| 22 | layers.append(nn.BatchNorm2d(dim)) |
| 23 | if out_format == "channels_last": |
| 24 | layers.append(to_channels_last()) |
| 25 | elif norm_layer == "LN": |
| 26 | if in_format == "channels_first": |
| 27 | layers.append(to_channels_last()) |
| 28 | layers.append(nn.LayerNorm(dim, eps=eps)) |
| 29 | if out_format == "channels_first": |
| 30 | layers.append(to_channels_first()) |
| 31 | else: |
| 32 | raise NotImplementedError(f"build_norm_layer does not support {norm_layer}") |
| 33 | return nn.Sequential(*layers) |
| 34 | |
| 35 | |
| 36 | class to_channels_first(nn.Module): |
no test coverage detected