Upsamples data by `scale_factor`. Supported modes are: - "deconv": uses a transposed convolution. - "deconvgroup": uses a transposed group convolution. - "nontrainable": uses :py:class:`torch.nn.Upsample`. - "pixelshuffle": uses :py:class:`monai.networks.blo
| 24 | |
| 25 | |
| 26 | class UpSample(nn.Sequential): |
| 27 | """ |
| 28 | Upsamples data by `scale_factor`. |
| 29 | Supported modes are: |
| 30 | |
| 31 | - "deconv": uses a transposed convolution. |
| 32 | - "deconvgroup": uses a transposed group convolution. |
| 33 | - "nontrainable": uses :py:class:`torch.nn.Upsample`. |
| 34 | - "pixelshuffle": uses :py:class:`monai.networks.blocks.SubpixelUpsample`. |
| 35 | |
| 36 | This operation will cause non-deterministic when ``mode`` is ``UpsampleMode.NONTRAINABLE``. |
| 37 | Please check the link below for more details: |
| 38 | https://pytorch.org/docs/stable/generated/torch.use_deterministic_algorithms.html#torch.use_deterministic_algorithms |
| 39 | This module can optionally take a pre-convolution |
| 40 | (often used to map the number of features from `in_channels` to `out_channels`). |
| 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. |
no outgoing calls
searching dependent graphs…