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)
| 20 | |
| 21 | |
| 22 | def 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 | |
| 53 | def get_act_layer(name: tuple | str): |
searching dependent graphs…