U PhR@sddlmZddlmZddlZddlZddlmZddl m Z m Z ddl m Z mZddlmZmZddlmZddlmZmZd gZGd d d ejZdS) ) annotations)SequenceN) Convolution ResidualUnit)calculate_out_shape same_padding)ActNorm)Reshape) ensure_tupleensure_tuple_rep Regressorc s|eZdZdZddejejddfddddddd d d d fd d Zdddd ddddZ ddddZ dddddZ 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)) NTz Sequence[int]zSequence[int] | intintz float | NoneboolNone) in_shape out_shapechannelsstrides kernel_size num_res_unitsdropoutbiasreturnc  s"tt|^|_|_t|j|_t||_t||_t||_ t ||j|_ ||_ ||_ ||_| |_| |_t|_|j} t|} tj|jtd|_t|j |_tt|j|jD]P\} \}}|| ||| t|dk}|} |jd| |t|j||| |_q| | f|j|_!dS)N)dtypezlayer_%i)"super__init__r in_channelsrlen dimensionsrrrr rractnormrrnn Sequentialnetrnpasarrayr final_sizer reshape enumeratezip _get_layer add_moduler_get_final_layerfinal)selfrrrrrrr#r$rrechannelpaddingicslayer __class__R/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/networks/nets/regressor.pyr<s.       zRegressor.__init__zResidualUnit | Convolution)r out_channelsris_lastrc Csd|jdkr8t|j||j||||j|j|j|j|jd }n(t||j||||j|j|j|j|jd }|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) subunitslast_conv_only spatial_dimsr r=rrr#r$rr) conv_onlyrAr r=rrr#r$rr) rrr"rr#r$rrr)r2r r=rr>r8r;r;r<r.hs6  zRegressor._get_layer)rcCs2ttt|tt|j}tt|SN)r%Linearrr(prodrr&Flatten)r2rlinearr;r;r<r0s"zRegressor._get_final_layerz torch.Tensor)xrcCs"||}||}||}|SrC)r'r1r+)r2rHr;r;r<forwards   zRegressor.forward) __name__ __module__ __qualname____doc__rPRELUr INSTANCErr.r0rI __classcell__r;r;r9r<r s$$,)) __future__rcollections.abcrnumpyr(torchtorch.nnr%monai.networks.blocksrrmonai.networks.layers.convutilsrrmonai.networks.layers.factoriesrr "monai.networks.layers.simplelayersr monai.utilsr r __all__Moduler r;r;r;r< s