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

Class DownSample

monai/networks/blocks/downsample.py:69–223  ·  view source on GitHub ↗

Downsamples data by `scale_factor`. Supported modes are: - "conv": uses a strided convolution for learnable downsampling. - "convgroup": uses a grouped strided convolution for efficient feature reduction. - "nontrainable": uses :py:class:`torch.nn.Upsample` with inverse scale

Source from the content-addressed store, hash-verified

67
68
69class DownSample(nn.Sequential):
70 """
71 Downsamples data by `scale_factor`.
72
73 Supported modes are:
74
75 - "conv": uses a strided convolution for learnable downsampling.
76 - "convgroup": uses a grouped strided convolution for efficient feature reduction.
77 - "nontrainable": uses :py:class:`torch.nn.Upsample` with inverse scale factor.
78 - "pixelunshuffle": uses :py:class:`monai.networks.blocks.PixelUnshuffle` for channel-space rearrangement.
79
80 This operation will cause non-deterministic behavior when ``mode`` is ``DownsampleMode.NONTRAINABLE``.
81 Please check the link below for more details:
82 https://pytorch.org/docs/stable/generated/torch.use_deterministic_algorithms.html#torch.use_deterministic_algorithms
83
84 This module can optionally take a pre-convolution
85 (often used to map the number of features from `in_channels` to `out_channels`).
86 """
87
88 def __init__(
89 self,
90 spatial_dims: int,
91 in_channels: int | None = None,
92 out_channels: int | None = None,
93 scale_factor: Sequence[float] | float = 2,
94 kernel_size: Sequence[float] | float | None = None,
95 mode: DownsampleMode | str = DownsampleMode.CONV,
96 pre_conv: nn.Module | str | None = "default",
97 post_conv: nn.Module | None = None,
98 bias: bool = True,
99 ) -> None:
100 """
101 Downsamples data by `scale_factor`.
102 Supported modes are:
103
104 - DownsampleMode.CONV: uses a strided convolution for learnable downsampling.
105 - DownsampleMode.CONVGROUP: uses a grouped strided convolution for efficient feature reduction.
106 - DownsampleMode.MAXPOOL: uses maxpooling for non-learnable downsampling.
107 - DownsampleMode.AVGPOOL: uses average pooling for non-learnable downsampling.
108 - DownsampleMode.PIXELUNSHUFFLE: uses :py:class:`monai.networks.blocks.SubpixelDownsample`.
109
110 This operation will cause non-deterministic behavior when ``mode`` is ``DownsampleMode.NONTRAINABLE``.
111 Please check the link below for more details:
112 https://pytorch.org/docs/stable/generated/torch.use_deterministic_algorithms.html#torch.use_deterministic_algorithms
113
114 This module can optionally take a pre-convolution and post-convolution
115 (often used to map the number of features from `in_channels` to `out_channels`).
116
117 Args:
118 spatial_dims: number of spatial dimensions of the input image.
119 in_channels: number of channels of the input image.
120 out_channels: number of channels of the output image. Defaults to `in_channels`.
121 scale_factor: multiplier for spatial size reduction. Has to match input size if it is a tuple. Defaults to 2.
122 kernel_size: kernel size used during convolutions. Defaults to `scale_factor`.
123 mode: {``DownsampleMode.CONV``, ``DownsampleMode.CONVGROUP``, ``DownsampleMode.MAXPOOL``, ``DownsampleMode.AVGPOOL``,
124 ``DownsampleMode.PIXELUNSHUFFLE``}. Defaults to ``DownsampleMode.CONV``.
125 pre_conv: a conv block applied before downsampling. Defaults to "default".
126 When ``conv_block`` is ``"default"``, one reserved conv layer will be utilized.

Callers 6

__init__Method · 0.90
test_shapeMethod · 0.90
test_pre_post_convMethod · 0.90
test_invalid_modeMethod · 0.90
test_missing_channelsMethod · 0.90

Calls

no outgoing calls

Tested by 5

test_shapeMethod · 0.72
test_pre_post_convMethod · 0.72
test_invalid_modeMethod · 0.72
test_missing_channelsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…