U Ph"@sddlmZddlmZddlZddlmZddlmZm Z ddl m Z ddl m Z ddgZd d d d d d dd ddddd ddddd ddddd dddfZGdddejZGdddejZdS)) annotations)SequenceN)ADN Convolution) ChannelPad)ChannelMatching HighResBlock HighResNetconv_0)name n_features kernel_sizeZres_1r r )r rkernelsrepeatZres_2 Zres_3@conv_1Pconv_2)r rc sdeZdZdddddifdddifdejfd d d d d d d d ddd fdd ZdddddZZS)rrrbatchaffineTreluinplaceFintz Sequence[int]zSequence[int] | intz tuple | strboolChannelMatching | strNone) spatial_dims in_channels out_channelsrdilation norm_type acti_typebiaschannel_matchingreturnc  stt|||| d|_t} ||} } |D]<} | td| |||d| t|| | | ||dd| } q2tj | |_ dS)aT Args: spatial_dims: number of spatial dimensions of the input image. in_channels: number of input channels. out_channels: number of output channels. kernels: each integer k in `kernels` corresponds to a convolution layer with kernel size k. dilation: spacing between kernel elements. norm_type: feature normalization type and arguments. Defaults to ``("batch", {"affine": True})``. acti_type: {``"relu"``, ``"prelu"``, ``"relu6"``} Non-linear activation using ReLU or PReLU. Defaults to ``"relu"``. bias: whether to have a bias term in convolution blocks. Defaults to False. According to `Performance Tuning Guide `_, if a conv layer is directly followed by a batch norm layer, bias should be False. channel_matching: {``"pad"``, ``"project"``} Specifies handling residual branch and conv branch channel mismatches. Defaults to ``"pad"``. - ``"pad"``: with zero padding. - ``"project"``: with a trainable conv with kernel size one. Raises: ValueError: When ``channel_matching=pad`` and ``in_channels > out_channels``. Incompatible values. )r!r"r#modeNA)orderingr"actnormnorm_dimT)r!r"r#rr$r' conv_onlyN) super__init__rchn_padnn ModuleListappendrr Sequentiallayers)selfr!r"r#rr$r%r&r'r(r8_in_chns _out_chnsr __class__S/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/networks/nets/highresnet.pyr2(s4$   zHighResBlock.__init__ torch.Tensorxr)cCs||}|t||SN)r8torch as_tensorr3)r9rBZx_convr>r>r?forwardgs zHighResBlock.forward)__name__ __module__ __qualname__rPADr2rF __classcell__r>r>r<r?r&s  &?c sneZdZdZddddddifdddifd d eejf d d d d d d ddddd fdd ZdddddZZ S)r a Reimplementation of highres3dnet based on Li et al., "On the compactness, efficiency, and representation of 3D convolutional networks: Brain parcellation as a pretext task", IPMI '17 Adapted from: https://github.com/NifTK/NiftyNet/blob/v0.6.0/niftynet/network/highres3dnet.py https://github.com/fepegar/highresnet Args: spatial_dims: number of spatial dimensions of the input image. in_channels: number of input channels. out_channels: number of output channels. norm_type: feature normalization type and arguments. Defaults to ``("batch", {"affine": True})``. acti_type: activation type and arguments. Defaults to ``("relu", {"inplace": True})``. dropout_prob: probability of the feature map to be zeroed (only applies to the penultimate conv layer). bias: whether to have a bias term in convolution blocks. Defaults to False. According to `Performance Tuning Guide `_, if a conv layer is directly followed by a batch norm layer, bias should be False. layer_params: specifying key parameters of each layer/block. channel_matching: {``"pad"``, ``"project"``} Specifies handling residual branch and conv branch channel mismatches. Defaults to ``"pad"``. - ``"pad"``: with zero padding. - ``"project"``: with a trainable conv with kernel size one. r rrrTrrgFrz str | tupleztuple | str | float | NonerzSequence[dict]rr ) r!r"r#r%r& dropout_probr' layer_paramsr(r)c s.tt} |d} || d} } | t|| | | dd|||dt|ddD]X\}} | | d} } d|}t| d D],}| t|| | | d ||||| d | } qqZ|d} | | d} } | t|| | | dd ||||d |d} | } | t|| || dd ||||d tj | |_ dS)Nrrrr+)r!r"r#r adn_orderingr-r.r'rrr) r!r"r#rr$r%r&r'r(ZNAD) r!r"r#rrNr-r.r'dropout) r1r2r4r5r6r enumeraterangerr7blocks)r9r!r"r#r%r&rLr'rMr(rUparamsr:r;idxZ _dilation_r<r>r?r2s  zHighResNet.__init__r@rAcCst||SrC)rDrErU)r9rBr>r>r?rFszHighResNet.forward) rGrHrI__doc__DEFAULT_LAYER_PARAMS_3DrrJr2rFrKr>r>r<r?r ls   &V) __future__rcollections.abcrrDtorch.nnr4Zmonai.networks.blocksrrZ"monai.networks.layers.simplelayersr monai.utilsr__all__rZModulerr r>r>r>r? s           F