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

Method __init__

monai/networks/blocks/upsample.py:43–189  ·  view source on GitHub ↗

Args: spatial_dims: number of spatial dimensions of the input image. in_channels: number of channels of the input image. out_channels: number of channels of the output image. Defaults to `in_channels`. scale_factor: multiplier for spatial size

(
        self,
        spatial_dims: int,
        in_channels: int | None = None,
        out_channels: int | None = None,
        scale_factor: Sequence[float] | float = 2,
        kernel_size: Sequence[float] | float | None = None,
        size: tuple[int] | int | None = None,
        mode: UpsampleMode | str = UpsampleMode.DECONV,
        pre_conv: nn.Module | str | None = "default",
        post_conv: nn.Module | None = None,
        interp_mode: str = InterpolateMode.LINEAR,
        align_corners: bool | None = True,
        bias: bool = True,
        apply_pad_pool: bool = True,
    )

Source from the content-addressed store, hash-verified

41 """
42
43 def __init__(
44 self,
45 spatial_dims: int,
46 in_channels: int | None = None,
47 out_channels: int | None = None,
48 scale_factor: Sequence[float] | float = 2,
49 kernel_size: Sequence[float] | float | None = None,
50 size: tuple[int] | int | None = None,
51 mode: UpsampleMode | str = UpsampleMode.DECONV,
52 pre_conv: nn.Module | str | None = "default",
53 post_conv: nn.Module | None = None,
54 interp_mode: str = InterpolateMode.LINEAR,
55 align_corners: bool | None = True,
56 bias: bool = True,
57 apply_pad_pool: bool = True,
58 ) -> None:
59 """
60 Args:
61 spatial_dims: number of spatial dimensions of the input image.
62 in_channels: number of channels of the input image.
63 out_channels: number of channels of the output image. Defaults to `in_channels`.
64 scale_factor: multiplier for spatial size. Has to match input size if it is a tuple. Defaults to 2.
65 kernel_size: kernel size used during transposed convolutions. Defaults to `scale_factor`.
66 size: spatial size of the output image.
67 Only used when ``mode`` is ``UpsampleMode.NONTRAINABLE``.
68 In torch.nn.functional.interpolate, only one of `size` or `scale_factor` should be defined,
69 thus if size is defined, `scale_factor` will not be used.
70 Defaults to None.
71 mode: {``"deconv"``, ``"deconvgroup"``, ``"nontrainable"``, ``"pixelshuffle"``}. Defaults to ``"deconv"``.
72 pre_conv: a conv block applied before upsampling. Defaults to "default".
73 When ``conv_block`` is ``"default"``, one reserved conv layer will be utilized when
74 Only used in the "nontrainable" or "pixelshuffle" mode.
75 post_conv: a conv block applied after upsampling. Defaults to None. Only used in the "nontrainable" mode.
76 interp_mode: {``"nearest"``, ``"linear"``, ``"bilinear"``, ``"bicubic"``, ``"trilinear"``}
77 Only used in the "nontrainable" mode.
78 If ends with ``"linear"`` will use ``spatial dims`` to determine the correct interpolation.
79 This corresponds to linear, bilinear, trilinear for 1D, 2D, and 3D respectively.
80 The interpolation mode. Defaults to ``"linear"``.
81 See also: https://pytorch.org/docs/stable/generated/torch.nn.Upsample.html
82 align_corners: set the align_corners parameter of `torch.nn.Upsample`. Defaults to True.
83 Only used in the "nontrainable" mode.
84 bias: whether to have a bias term in the default preconv and deconv layers. Defaults to True.
85 apply_pad_pool: if True the upsampled tensor is padded then average pooling is applied with a kernel the
86 size of `scale_factor` with a stride of 1. See also: :py:class:`monai.networks.blocks.SubpixelUpsample`.
87 Only used in the "pixelshuffle" mode.
88
89 Raises:
90 ValueError: if ``mode`` is ``"deconv"`` or ``"deconvgroup"`` and ``in_channels`` is not specified.
91 ValueError: if ``mode`` is ``"nontrainable"``, ``pre_conv`` is not set, and
92 ``out_channels != in_channels``.
93
94 """
95 super().__init__()
96 scale_factor_ = ensure_tuple_rep(scale_factor, spatial_dims)
97 up_mode = look_up_option(mode, UpsampleMode)
98
99 if not kernel_size:
100 kernel_size_ = scale_factor_

Callers 1

__init__Method · 0.45

Calls 4

ensure_tuple_repFunction · 0.90
look_up_optionFunction · 0.90
InterpolateModeClass · 0.90
SubpixelUpsampleClass · 0.85

Tested by

no test coverage detected