o , i"@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 rcsHeZdZdddddifdddifdejfd fdd Zd!ddZZS)"rrrbatchaffineTreluinplaceF spatial_dimsint in_channels out_channelsr Sequence[int]dilationSequence[int] | int norm_type tuple | str acti_typebiasboolchannel_matchingChannelMatching | strreturnNonec  stt|||| d|_t} ||} } |D]} | td| |||d| t|| | | ||dd| } qtj | |_ 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. )rrr modeNA)orderingractnormnorm_dimT)rrr rr"r' conv_onlyN) super__init__rchn_padnn ModuleListappendrr Sequentiallayers)selfrrr rr"r$r&r'r)r;_in_chns _out_chnsr __class__`/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/networks/nets/highresnet.pyr5(s. $  zHighResBlock.__init__x torch.TensorcCs||}|t||SN)r;torch as_tensorr6)r<rCZx_convrArArBforwardgs zHighResBlock.forward)rrrrr rrr!r"r#r$r%r&r%r'r(r)r*r+r,rCrDr+rD)__name__ __module__ __qualname__rPADr5rH __classcell__rArAr?rBr&s  ?c sReZdZdZddddddifdddifd d eejf d"fdd Zd#d d!ZZ 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 rrrTrrgFrrrr r$ str | tupler& dropout_probtuple | str | float | Noner'r( layer_paramsSequence[dict]r)r*r+r,c s.tt} |d} || d} } | t|| | | dd|||dt|ddD],\}} | | d} } d|}t| d D]}| t|| | | d ||||| d | } qBq-|d} | | d} } | t|| | | dd ||||d |d} | } | t|| || dd ||||d tj | |_ dS)Nrrrr.)rrr r adn_orderingr0r1r'rrr) rrr rr"r$r&r'r)ZNAD) rrr rrTr0r1r'dropout) r4r5r7r8r9r enumeraterangerr:blocks)r<rrr r$r&rPr'rRr)r[paramsr=r>idxZ _dilation_r?rArBr5s  zHighResNet.__init__rCrDcCst||SrE)rFrGr[)r<rCrArArBrHszHighResNet.forward)rrrrr rr$rOr&rOrPrQr'r(rRrSr)r*r+r,rI) rJrKrL__doc__DEFAULT_LAYER_PARAMS_3DrrMr5rHrNrArAr?rBr ls   V) __future__rcollections.abcrrFtorch.nnr7monai.networks.blocksrr"monai.networks.layers.simplelayersr monai.utilsr__all__r`Modulerr rArArArBs"          F