o
    )i                     @  sz   d dl mZ d dlmZ d dlZd dlmZ d dlmZm	Z	 d dl
mZmZ ddgZG dd dejZG d	d deZdS )
    )annotations)SequenceN)ConvolutionResidualUnit)ActNorm
DenseBlockConvDenseBlockc                      s*   e Zd ZdZd fddZdd Z  ZS )	r   a\  
    A DenseBlock is a sequence of layers where each layer's outputs are concatenated with their inputs. This has the
    effect of accumulating outputs from previous layers as inputs to later ones and as the final output of the block.

    Args:
        layers: sequence of nn.Module objects to define the individual layers of the dense block
    layersSequence[nn.Module]c                   s2   t    t|D ]\}}| d| | q	d S )Nr
   )super__init__	enumerate
add_module)selfr
   il	__class__ b/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/networks/blocks/denseblock.pyr   "   s   
zDenseBlock.__init__c                 C  s*   |   D ]}||}t||gd}q|S )N   )childrentorchcat)r   xr   resultr   r   r   forward'   s   zDenseBlock.forward)r
   r   )__name__
__module____qualname____doc__r   r   __classcell__r   r   r   r   r      s    c                      s@   e Zd ZdZddddejejddfd fddZdd Z	  Z
S )r	   a  
    This dense block is defined as a sequence of `Convolution` or `ResidualUnit` blocks. The `_get_layer` method returns
    an object for each layer and can be overridden to change the composition of the block.

    Args:
        spatial_dims: number of spatial dimensions.
        in_channels: number of input channels.
        channels: output channels for each layer.
        dilations: dilation value for each layer.
        kernel_size: convolution kernel size. Defaults to 3.
        num_res_units: 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.
        bias: whether to have a bias term. Defaults to True.
    N   r   NDATspatial_dimsintin_channelschannelsSequence[int]	dilationsSequence[int] | Nonekernel_sizeSequence[int] | intnum_res_unitsadn_orderingstracttuple | str | Nonenormdropouttuple | str | float | Nonebiasboolc                   s   || _ || _|| _|| _|| _|	| _|
| _|| _|}|d ur |ndgt| }g }t|t|kr5t	dt
||D ]\}}| |||}|| ||7 }q:t | d S )Nr   z/Length of `channels` and `dilations` must match)r%   r,   r.   r/   r1   r3   r4   r6   len
ValueErrorzip
_get_layerappendr   r   )r   r%   r'   r(   r*   r,   r.   r/   r1   r3   r4   r6   Z
l_channelsr
   cdlayerr   r   r   r   B   s$   

zConvDenseBlock.__init__c                 C  sb   | j dkrt| j||d| j| j | j| j| j| j|| jdS t	| j||d| j| j| j| j|| jd
S )Nr   r   )r%   r'   out_channelsstridesr,   subunitsr/   r1   r3   r4   dilationr6   )
r%   r'   r@   rA   r,   r1   r3   r4   rC   r6   )
r.   r   r%   r,   r/   r1   r3   r4   r6   r   )r   r'   r@   rC   r   r   r   r;   g   s6   
zConvDenseBlock._get_layer)r%   r&   r'   r&   r(   r)   r*   r+   r,   r-   r.   r&   r/   r0   r1   r2   r3   r2   r4   r5   r6   r7   )r   r   r    r!   r   PRELUr   INSTANCEr   r;   r"   r   r   r   r   r	   /   s    %)
__future__r   typingr   r   torch.nnnnZmonai.networks.blocksr   r   monai.networks.layers.factoriesr   r   Z__ALL__
Sequentialr   r	   r   r   r   r   <module>   s   