o
    ,iR                     @  s   d dl mZ d dlmZ d dl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lmZmZ d dlmZ d dlmZmZ d	gZG d
d	 d	ejZdS )    )annotations)SequenceN)ConvolutionResidualUnit)calculate_out_shapesame_padding)ActNorm)Reshape)ensure_tupleensure_tuple_rep	Regressorc                      sR   e Zd ZdZddejejddfd# fddZd$ddZ	d%ddZ
d&d!d"Z  ZS )'r   a  
    This defines a network for relating large-sized input tensors to small output tensors, ie. regressing large
    values to a prediction. An output of a single dimension can be used as value regression or multi-label
    classification prediction, an output of a single value can be used as a discriminator or critic prediction.

    The network is constructed as a sequence of layers, either :py:class:`monai.networks.blocks.Convolution` or
    :py:class:`monai.networks.blocks.ResidualUnit`, with a final fully-connected layer resizing the output from the
    blocks to the final size. Each block is defined with a stride value typically used to downsample the input using
    strided convolutions. In this way each block progressively condenses information from the input into a deep
    representation the final fully-connected layer relates to a final result.

    Args:
        in_shape: tuple of integers stating the dimension of the input tensor (minus batch dimension)
        out_shape: tuple of integers stating the dimension of the final output 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

    Examples::

        # infers a 2-value result (eg. a 2D cartesian coordinate) from a 64x64 image
        net = Regressor((1, 64, 64), (2,), (2, 4, 8), (2, 2, 2))

          NTin_shapeSequence[int]	out_shapechannelsstrideskernel_sizeSequence[int] | intnum_res_unitsintdropoutfloat | NonebiasboolreturnNonec              	     s"  t    t|^| _| _t| j| _t|| _t|| _t|| _	t
|| j| _|| _|| _|| _|	| _|
| _t | _| j}t|}tj| jtd| _t| j	 | _tt| j| jD ](\}\}}| ||||t|d k}|}| jd| | t| j|||| _q\|  |f| j | _!d S )N)dtype   zlayer_%i)"super__init__r   in_channelsr   len
dimensionsr   r   r   r   r   r   actnormr   r   nn
Sequentialnetr   npasarrayr   
final_sizer
   reshape	enumeratezip
_get_layer
add_moduler   _get_final_layerfinal)selfr   r   r   r   r   r   r&   r'   r   r   Zechannelpaddingicslayer	__class__ _/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/networks/nets/regressor.pyr"   <   s.   




zRegressor.__init__r#   out_channelsis_lastResidualUnit | Convolutionc                 C  sf   | j dkrt| j || j|||| j| j| j| j| jd}|S t|| j|||| j| j| j| j| jd
}|S )a\  
        Returns a layer accepting inputs with `in_channels` number of channels and producing outputs of `out_channels`
        number of channels. The `strides` indicates downsampling factor, ie. convolutional stride. If `is_last`
        is True this is the final layer and is not expected to include activation and normalization layers.
        r   )subunitslast_conv_onlyspatial_dimsr#   r?   r   r   r&   r'   r   r   )
	conv_onlyrD   r#   r?   r   r   r&   r'   r   r   )	r   r   r%   r   r&   r'   r   r   r   )r5   r#   r?   r   r@   r:   r=   r=   r>   r1   h   s8   
zRegressor._get_layerc                 C  s2   t tt|tt| j}t t  |S N)r(   Linearr   r+   prodr   r)   Flatten)r5   r   linearr=   r=   r>   r3      s   "zRegressor._get_final_layerxtorch.Tensorc                 C  s"   |  |}| |}| |}|S rF   )r*   r4   r.   )r5   rK   r=   r=   r>   forward   s   


zRegressor.forward)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )
r#   r   r?   r   r   r   r@   r   r   rA   )r   r   )rK   rL   r   rL   )__name__
__module____qualname____doc__r   PRELUr	   INSTANCEr"   r1   r3   rM   __classcell__r=   r=   r;   r>   r      s    $
,
))
__future__r   collections.abcr   numpyr+   torchtorch.nnr(   monai.networks.blocksr   r   monai.networks.layers.convutilsr   r   monai.networks.layers.factoriesr   r	   "monai.networks.layers.simplelayersr
   monai.utilsr   r   __all__Moduler   r=   r=   r=   r>   <module>   s   