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

Class SubpixelUpsample

monai/networks/blocks/upsample.py:192–293  ·  view source on GitHub ↗

Upsample via using a subpixel CNN. This module supports 1D, 2D and 3D input images. The module is consisted with two parts. First of all, a convolutional layer is employed to increase the number of channels into: ``in_channels * (scale_factor ** dimensions)``. Secondly, a pixel shuf

Source from the content-addressed store, hash-verified

190
191
192class SubpixelUpsample(nn.Module):
193 """
194 Upsample via using a subpixel CNN. This module supports 1D, 2D and 3D input images.
195 The module is consisted with two parts. First of all, a convolutional layer is employed
196 to increase the number of channels into: ``in_channels * (scale_factor ** dimensions)``.
197 Secondly, a pixel shuffle manipulation is utilized to aggregates the feature maps from
198 low resolution space and build the super resolution space.
199 The first part of the module is not fixed, a sequential layers can be used to replace the
200 default single layer.
201
202 See: Shi et al., 2016, "Real-Time Single Image and Video Super-Resolution
203 Using an Efficient Sub-Pixel Convolutional Neural Network."
204
205 See: Aitken et al., 2017, "Checkerboard artifact free sub-pixel convolution".
206
207 The idea comes from:
208 https://arxiv.org/abs/1609.05158
209
210 The pixel shuffle mechanism refers to:
211 https://pytorch.org/docs/stable/generated/torch.nn.PixelShuffle.html#torch.nn.PixelShuffle.
212 and:
213 https://github.com/pytorch/pytorch/pull/6340.
214
215 """
216
217 def __init__(
218 self,
219 spatial_dims: int,
220 in_channels: int | None,
221 out_channels: int | None = None,
222 scale_factor: int = 2,
223 conv_block: nn.Module | str | None = "default",
224 apply_pad_pool: bool = True,
225 bias: bool = True,
226 ) -> None:
227 """
228 Args:
229 spatial_dims: number of spatial dimensions of the input image.
230 in_channels: number of channels of the input image.
231 out_channels: optional number of channels of the output image.
232 scale_factor: multiplier for spatial size. Defaults to 2.
233 conv_block: a conv block to extract feature maps before upsampling. Defaults to None.
234
235 - When ``conv_block`` is ``"default"``, one reserved conv layer will be utilized.
236 - When ``conv_block`` is an ``nn.module``,
237 please ensure the output number of channels is divisible ``(scale_factor ** dimensions)``.
238
239 apply_pad_pool: if True the upsampled tensor is padded then average pooling is applied with a kernel the
240 size of `scale_factor` with a stride of 1. This implements the nearest neighbour resize convolution
241 component of subpixel convolutions described in Aitken et al.
242 bias: whether to have a bias term in the default conv_block. Defaults to True.
243
244 """
245 super().__init__()
246
247 if scale_factor <= 0:
248 raise ValueError(f"The `scale_factor` multiplier must be an integer greater than 0, got {scale_factor}.")
249

Callers 5

test_subpixel_shapeMethod · 0.90
test_scriptMethod · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by 4

test_subpixel_shapeMethod · 0.72
test_scriptMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…