U
    ˜PÓh•  ã                   @  sŠ   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	m
Z
 d dlmZ dddgZG d	d„ deƒZG d
d„ deƒZG dd„ deƒZdS )é    )Úannotations)ÚSequenceN)ÚActÚNormÚ
split_args)Ú	RegressorÚ
ClassifierÚDiscriminatorÚCriticc                      sL   e Zd ZdZddejejdddfddddddd	d
dddœ
‡ fdd„Z‡  Z	S )r   a«  
    Defines a classification network from Regressor by specifying the output shape as a single dimensional tensor
    with size equal to the number of classes to predict. The final activation function can also be specified, eg.
    softmax or sigmoid.

    Args:
        in_shape: tuple of integers stating the dimension of the input tensor (minus batch dimension)
        classes: integer stating the dimension of the final output tensor
        channels: tuple of integers stating the output channels of each convolutional layer
        strides: tuple of integers stating the stride (downscale factor) of each convolutional layer
        kernel_size: integer or tuple of integers stating size of convolutional kernels
        num_res_units: integer stating number of convolutions in residual units, 0 means no residual units
        act: name or type defining activation layers
        norm: name or type defining normalization layers
        dropout: optional float value in range [0, 1] stating dropout probability for layers, None for no dropout
        bias: boolean stating if convolution layers should have a bias component
        last_act: name defining the last activation layer
    é   é   NTúSequence[int]ÚintúSequence[int] | intúfloat | NoneÚboolz
str | NoneÚNone)
Úin_shapeÚclassesÚchannelsÚstridesÚkernel_sizeÚnum_res_unitsÚdropoutÚbiasÚlast_actÚreturnc                   sT   t ƒ  ||f|||||||	|
¡
 |d k	rPt|ƒ\}}t| }| j d|f |Ž¡ d S )NZlastact)ÚsuperÚ__init__r   r   ÚfinalÚ
add_module)Úselfr   r   r   r   r   r   ÚactÚnormr   r   r   Zlast_act_nameZlast_act_argsZlast_act_type©Ú	__class__© úS/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/networks/nets/classifier.pyr   -   s
     zClassifier.__init__)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚPRELUr   ÚINSTANCEr   Ú__classcell__r&   r&   r$   r'   r      s   ôc                
      sJ   e Zd ZdZddejejddejfdddddd	d
ddœ‡ fdd„Z	‡  Z
S )r	   a<  
    Defines a discriminator network from Classifier with a single output value and sigmoid activation by default. This
    is meant for use with GANs or other applications requiring a generic discriminator network.

    Args:
        in_shape: tuple of integers stating the dimension of the input tensor (minus batch dimension)
        channels: tuple of integers stating the output channels of each convolutional layer
        strides: tuple of integers stating the stride (downscale factor) of each convolutional layer
        kernel_size: integer or tuple of integers stating size of convolutional kernels
        num_res_units: integer stating number of convolutions in residual units, 0 means no residual units
        act: name or type defining activation layers
        norm: name or type defining normalization layers
        dropout: optional float value in range [0, 1] stating dropout probability for layers, None for no dropout
        bias: boolean stating if convolution layers should have a bias component
        last_act: name defining the last activation layer
    r   r   ç      Ð?Tr   r   r   r   r   r   ©r   r   r   r   r   r   r   r   c                   s$   t ƒ  |d||||||||	|
¡ d S ©Né   ©r   r   )r!   r   r   r   r   r   r"   r#   r   r   r   r$   r&   r'   r   V   s    zDiscriminator.__init__)r(   r)   r*   r+   r   r,   r   r-   ÚSIGMOIDr   r.   r&   r&   r$   r'   r	   D   s   õc                
      sd   e Zd ZdZddejejddfdddddd	d
ddœ‡ fdd„Zddœdd„Z	dddœdd„Z
‡  ZS )r
   a?  
    Defines a critic network from Classifier with a single output value and no final activation. The final layer is
    `nn.Flatten` instead of `nn.Linear`, the final result is computed as the mean over the first dimension. This is
    meant to be used with Wasserstein GANs.

    Args:
        in_shape: tuple of integers stating the dimension of the input tensor (minus batch dimension)
        channels: tuple of integers stating the output channels of each convolutional layer
        strides: tuple of integers stating the stride (downscale factor) of each convolutional layer
        kernel_size: integer or tuple of integers stating size of convolutional kernels
        num_res_units: integer stating number of convolutions in residual units, 0 means no residual units
        act: name or type defining activation layers
        norm: name or type defining normalization layers
        dropout: optional float value in range [0, 1] stating dropout probability for layers, None for no dropout
        bias: boolean stating if convolution layers should have a bias component
    r   r   r/   Tr   r   r   r   r   r   r0   c
           
        s$   t ƒ  |d||||||||	d ¡ d S r1   r3   )
r!   r   r   r   r   r   r"   r#   r   r   r$   r&   r'   r   x   s    zCritic.__init__)r   c                 C  s   t  ¡ S )N)ÚnnÚFlatten)r!   r   r&   r&   r'   Ú_get_final_layer†   s    zCritic._get_final_layerztorch.Tensor)Úxr   c                 C  s2   |   |¡}|  |¡}| d¡}| |jd df¡S )Nr2   r   éÿÿÿÿ)Únetr   ÚmeanÚviewÚshape)r!   r8   r&   r&   r'   Úforward‰   s    


zCritic.forward)r(   r)   r*   r+   r   r,   r   r-   r   r7   r>   r.   r&   r&   r$   r'   r
   f   s   ö")Ú
__future__r   Úcollections.abcr   ÚtorchÚtorch.nnr5   Úmonai.networks.layers.factoriesr   r   r   Zmonai.networks.nets.regressorr   Ú__all__r   r	   r
   r&   r&   r&   r'   Ú<module>   s   
+"