MCPcopy Create free account
hub / github.com/aigc3d/LHM / build_norm_layer

Function build_norm_layer

engine/BiRefNet/models/modules/utils.py:15–33  ·  view source on GitHub ↗
(
    dim, norm_layer, in_format="channels_last", out_format="channels_last", eps=1e-6
)

Source from the content-addressed store, hash-verified

13
14
15def 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
36class to_channels_first(nn.Module):

Callers 15

__init__Method · 0.90
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
_make_one_branchMethod · 0.85
_make_fuse_layersMethod · 0.85
__init__Method · 0.85
_make_layerMethod · 0.85
_make_fuse_layersMethod · 0.85

Calls 2

to_channels_firstClass · 0.85
to_channels_lastClass · 0.85

Tested by

no test coverage detected