o , iR@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 RegressorcsReZdZdZddejejddfd#fdd Zd$ddZ d%ddZ 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)) NTin_shape Sequence[int] out_shapechannelsstrides kernel_sizeSequence[int] | int num_res_unitsintdropout float | NonebiasboolreturnNonec  s"tt|^|_|_t|j|_t||_t||_t||_ t ||j|_ ||_ ||_ ||_| |_| |_t|_|j} t|} tj|jtd|_t|j |_tt|j|jD](\} \}}|| ||| 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'rrZechannelpaddingicslayer __class___/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/networks/nets/regressor.pyr"<s.       zRegressor.__init__r# out_channelsis_lastResidualUnit | Convolutionc Csf|jdkrt|j||j||||j|j|j|j|jd }|St||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_onlyrDr#r?rrr&r'rr) rrr%rr&r'rrr)r5r#r?rr@r:r=r=r>r1hs8  zRegressor._get_layercCs2ttt|tt|j}tt|SN)r(Linearrr+prodrr)Flatten)r5rlinearr=r=r>r3s"zRegressor._get_final_layerx torch.TensorcCs"||}||}||}|SrF)r*r4r.)r5rKr=r=r>forwards   zRegressor.forward)rrrrrrrrrrrrrrrrrr) r#rr?rrrr@rrrA)rr)rKrLrrL) __name__ __module__ __qualname____doc__rPRELUr INSTANCEr"r1r3rM __classcell__r=r=r;r>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