U Ph-@sddlmZddlmZddlZddlZddlmZddl m Z ddl m Z m Z ddlmZGdddejZGd d d ejZdS) ) annotations)SequenceN)ADN) same_paddingstride_minus_kernel_padding)ConvcsJeZdZdZdd d d d d d d d ddd d dddddddfdd ZZS) Convolutiona Constructs a convolution with normalization, optional dropout, and optional activation layers:: -- (Conv|ConvTrans) -- (Norm -- Dropout -- Acti) -- if ``conv_only`` set to ``True``:: -- (Conv|ConvTrans) -- For example: .. code-block:: python from monai.networks.blocks import Convolution conv = Convolution( spatial_dims=3, in_channels=1, out_channels=1, adn_ordering="ADN", act=("prelu", {"init": 0.2}), dropout=0.1, norm=("layer", {"normalized_shape": (10, 10, 10)}), ) print(conv) output:: Convolution( (conv): Conv3d(1, 1, kernel_size=(3, 3, 3), stride=(1, 1, 1), padding=(1, 1, 1)) (adn): ADN( (A): PReLU(num_parameters=1) (D): Dropout(p=0.1, inplace=False) (N): LayerNorm((10, 10, 10), eps=1e-05, elementwise_affine=True) ) ) Args: spatial_dims: number of spatial dimensions. in_channels: number of input channels. out_channels: number of output channels. strides: convolution stride. Defaults to 1. kernel_size: convolution kernel size. Defaults to 3. adn_ordering: a string representing the ordering of activation, normalization, and dropout. Defaults to "NDA". act: activation type and arguments. Defaults to PReLU. norm: feature normalization type and arguments. Defaults to instance norm. dropout: dropout ratio. Defaults to no dropout. dropout_dim: determine the spatial dimensions of dropout. Defaults to 1. - When dropout_dim = 1, randomly zeroes some of the elements for each channel. - When dropout_dim = 2, Randomly zeroes out entire channels (a channel is a 2D feature map). - When dropout_dim = 3, Randomly zeroes out entire channels (a channel is a 3D feature map). The value of dropout_dim should be no larger than the value of `spatial_dims`. dilation: dilation rate. Defaults to 1. groups: controls the connections between inputs and outputs. Defaults to 1. bias: whether to have a bias term. Defaults to True. conv_only: whether to use the convolutional layer only. Defaults to False. is_transposed: if True uses ConvTrans instead of Conv. Defaults to False. padding: controls the amount of implicit zero-paddings on both sides for padding number of points for each dimension. Defaults to None. output_padding: controls the additional size added to one side of the output shape. Defaults to None. See also: :py:class:`monai.networks.layers.Conv` :py:class:`monai.networks.blocks.ADN` NDAPRELUINSTANCENTFintSequence[int] | intstrtuple | str | Nonetuple | str | float | None int | NoneboolSequence[int] | int | NoneNone) spatial_dims in_channels out_channelsstrides kernel_size adn_orderingactnormdropout dropout_dimdilationgroupsbias conv_only is_transposedpaddingoutput_paddingreturnc st||_||_||_||_|dkr4t|| }t|r@tjntj |jf}|r|dkrdt d|}|||||||| | | d }n||||||| | | d}| d||rdS|dkr|dkr| dkrdS| dt |||||j| | ddS)Nr )rstrider&r'r"r#r!)rr)r&r!r"r#convZadn)orderingrrrnorm_dimrr ) super__init__rrrr%rr CONVTRANSCONVr add_moduler)selfrrrrrrrrrr r!r"r#r$r%r&r' conv_typer* __class__W/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/networks/blocks/convolutions.pyr.bsb     zConvolution.__init__)r r r r r Nr r r TFFNN)__name__ __module__ __qualname____doc__r. __classcell__r6r6r4r7rs MrcsVeZdZdZdd d d d d d d ddddd dddddfdd ZdddddZZS) ResidualUnita Residual module with multiple convolutions and a residual connection. For example: .. code-block:: python from monai.networks.blocks import ResidualUnit convs = ResidualUnit( spatial_dims=3, in_channels=1, out_channels=1, adn_ordering="AN", act=("prelu", {"init": 0.2}), norm=("layer", {"normalized_shape": (10, 10, 10)}), ) print(convs) output:: ResidualUnit( (conv): Sequential( (unit0): Convolution( (conv): Conv3d(1, 1, kernel_size=(3, 3, 3), stride=(1, 1, 1), padding=(1, 1, 1)) (adn): ADN( (A): PReLU(num_parameters=1) (N): LayerNorm((10, 10, 10), eps=1e-05, elementwise_affine=True) ) ) (unit1): Convolution( (conv): Conv3d(1, 1, kernel_size=(3, 3, 3), stride=(1, 1, 1), padding=(1, 1, 1)) (adn): ADN( (A): PReLU(num_parameters=1) (N): LayerNorm((10, 10, 10), eps=1e-05, elementwise_affine=True) ) ) ) (residual): Identity() ) Args: spatial_dims: number of spatial dimensions. in_channels: number of input channels. out_channels: number of output channels. strides: convolution stride. Defaults to 1. kernel_size: convolution kernel size. Defaults to 3. subunits: number of convolutions. Defaults to 2. adn_ordering: a string representing the ordering of activation, normalization, and dropout. Defaults to "NDA". act: activation type and arguments. Defaults to PReLU. norm: feature normalization type and arguments. Defaults to instance norm. dropout: dropout ratio. Defaults to no dropout. dropout_dim: determine the dimensions of dropout. Defaults to 1. - When dropout_dim = 1, randomly zeroes some of the elements for each channel. - When dropout_dim = 2, Randomly zero out entire channels (a channel is a 2D feature map). - When dropout_dim = 3, Randomly zero out entire channels (a channel is a 3D feature map). The value of dropout_dim should be no larger than the value of `dimensions`. dilation: dilation rate. Defaults to 1. bias: whether to have a bias term. Defaults to True. last_conv_only: for the last subunit, whether to use the convolutional layer only. Defaults to False. padding: controls the amount of implicit zero-paddings on both sides for padding number of points for each dimension. Defaults to None. See also: :py:class:`monai.networks.blocks.Convolution` r r r r r NTFrrrrrrrrr)rrrrrsubunitsrrrrr r!r#last_conv_onlyr&r(cst||_||_||_t|_t|_ |s>t || }|}|}t d|}t |D]X}|oj||dk}t |j||||||| | | | | ||d}|jd|d||}d}qXt|dks||kr|}|}t|dkrd}d}ttj|jf}||||||| d|_ dS)Nr ) rrrrrrr r!r#r$r&unitdr)r#)r-r.rrrnn Sequentialr*Identityresidualrmaxrangerr1npprodrr0)r2rrrrrr?rrrrr r!r#r@r&Z schannelsZsstridessur$rAZ rkernel_sizeZrpaddingr3r4r6r7r.sP      zResidualUnit.__init__z torch.Tensor)xr(cCs||}||}||S)N)rFr*)r2rLrescxr6r6r7forward;s  zResidualUnit.forward) r r r>r r r Nr r TFN)r8r9r:r;r.rOr<r6r6r4r7r=sN2Cr=) __future__rcollections.abcrnumpyrItorchtorch.nnrCZmonai.networks.blocksrmonai.networks.layers.convutilsrrmonai.networks.layers.factoriesrrDrModuler=r6r6r6r7 s