MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / get_norm_layer

Function get_norm_layer

monai/networks/layers/utils.py:22–50  ·  view source on GitHub ↗

Create a normalization layer instance. For example, to create normalization layers: .. code-block:: python from monai.networks.layers import get_norm_layer g_layer = get_norm_layer(name=("group", {"num_groups": 1})) n_layer = get_norm_layer(name="instance", s

(name: tuple | str, spatial_dims: int | None = 1, channels: int | None = 1)

Source from the content-addressed store, hash-verified

20
21
22def get_norm_layer(name: tuple | str, spatial_dims: int | None = 1, channels: int | None = 1):
23 """
24 Create a normalization layer instance.
25
26 For example, to create normalization layers:
27
28 .. code-block:: python
29
30 from monai.networks.layers import get_norm_layer
31
32 g_layer = get_norm_layer(name=("group", {"num_groups": 1}))
33 n_layer = get_norm_layer(name="instance", spatial_dims=2)
34
35 Args:
36 name: a normalization type string or a tuple of type string and parameters.
37 spatial_dims: number of spatial dimensions of the input.
38 channels: number of features/channels when the normalization layer requires this parameter
39 but it is not specified in the norm parameters.
40 """
41 if name == "":
42 return torch.nn.Identity()
43 norm_name, norm_args = split_args(name)
44 norm_type = Norm[norm_name, spatial_dims]
45 kw_args = dict(norm_args)
46 if has_option(norm_type, "num_features") and "num_features" not in kw_args:
47 kw_args["num_features"] = channels
48 if has_option(norm_type, "num_channels") and "num_channels" not in kw_args:
49 kw_args["num_channels"] = channels
50 return norm_type(**kw_args)
51
52
53def get_act_layer(name: tuple | str):

Callers 15

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
_make_final_convMethod · 0.90
_prepare_vae_modulesMethod · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
_make_layerMethod · 0.90

Calls 2

split_argsFunction · 0.90
has_optionFunction · 0.90

Tested by 2

test_norm_layerMethod · 0.72
test_suggestedMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…