o , iD*@sddlmZddlZddlmZddlmZddlmZm Z m Z m Z m Z ddl mZdgZdd d d ZGd ddejZd!d"ddZGdddejZGdddejZGdddejZGdddejZGdddejZdS)#) annotationsN) Convolution)ActConvDropoutNorm split_args)deprecated_argVNetacttuple[str, dict] | strnchanintcCs6|dkr dd|if}t|\}}t|}|di|S)Nprelunum_parameters)rr)r r act_nameact_argsact_typerrZ/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/networks/nets/vnet.pyget_acti_layers   rcs(eZdZd dfd d Zd d ZZS)LUConvF spatial_dimsrr r r biasboolc s4tt|||_t|||ddtj|d|_dS)Nr in_channels out_channels kernel_sizer normr)super__init__r act_functionrrBATCH conv_block)selfrr r r __class__rrr""s   zLUConv.__init__cCs||}||}|SN)r%r#r&xoutrrrforward0s  zLUConv.forwardF)rrr rr r rr__name__ __module__ __qualname__r"r- __classcell__rrr'rr srFrdepthrrcCs0g}t|D] }|t||||qtj|Sr))rangeappendrnn Sequential)rr r4r rlayers_rrr _make_nconv6s  r;c*eZdZ ddfd d Zd d ZZS)InputTransitionFrrrrr r rrc sht||dkrtd|d|d||_||_||_t|||_t|||ddt j |d|_ dS)NrzAout channels should be divisible by in_channels. Got in_channels=z, out_channels=.rr) r!r" ValueErrorrrrrr#rrr$r%)r&rrrr rr'rrr"?s$    zInputTransition.__init__cCsN||}|j|j}|d|dddgd|jd}|t||}|S)N)r%rrrepeatrr#torchadd)r&r+r,Z repeat_numx16rrrr-Ws  "zInputTransition.forwardr. rrrrrrr r rrr/rrr'rr==sr=cs.eZdZ   ddfdd ZddZZS)DownTransitionNFrrrnconvsr r dropout_prob float | None dropout_dimrrc stttj|f}ttj|f} ttj|f} d|} ||| dd|d|_| | |_ t || |_ t || |_ t || ||||_|durM| ||_dSd|_dS)NrA)rstrider)r!r"rCONVrr$rDROPOUT down_convbn1r act_function1 act_function2r;opsdropout) r&rrrIr rJrLr conv_type norm_type dropout_typerr'rrr"as     zDownTransition.__init__cCsP||||}|jdur||}n|}||}|t||}|Sr))rRrQrPrUrTrSrCrD)r&r+downr,rrrr-ys   zDownTransition.forward)NrHF)rrrrrIrr r rJrKrLrrrr/rrr'rrG_s rGcs,eZdZ  ddfd d ZddZZS) UpTransitionN?rHrrrrrIr r rJtuple[float | None, float]rLc stttj|f}ttj|f} ttj|f} |||dddd|_| |d|_ |ddur8| |dnd|_ | |d|_ t ||d|_ t |||_t|||||_dS)NrA)rrMrr@)r!r"r CONVTRANSrr$rrOup_convrQrUdropout2rrRrSr;rT) r&rrrrIr rJrLconv_trans_typerWrXr'rrr"s  zUpTransition.__init__cCsj|jdur ||}n|}||}||||}t||fd}||}|t ||}|S)Nr@) rUr`rRrQr_rCcatrTrSrD)r&r+Zskipxr,ZskipxdoZxcatrrrr-s    zUpTransition.forward)r[rH)rrrrrrrIrr r rJr]rLrr/rrr'rrZs  rZcr<)OutputTransitionFrrrrr r rrc sRtttj|f}t|||_t|||ddtj|d|_ |||dd|_ dS)Nrrr@)r) r!r"rrNrrRrrr$r%conv2)r&rrrr rrVr'rrr"s   zOutputTransition.__init__cCs"||}||}||}|Sr))r%rRrdr*rrrr-s   zOutputTransition.forwardr.rFr/rrr'rrcsrcc sfeZdZdZedddddedddddd d d d d d ifdddd df d fdd ZddZZS)!r a V-Net based on `Fully Convolutional Neural Networks for Volumetric Medical Image Segmentation `_. Adapted from `the official Caffe implementation `_. and `another pytorch implementation `_. The model supports 2D or 3D inputs. Args: spatial_dims: spatial dimension of the input data. Defaults to 3. in_channels: number of input channels for the network. Defaults to 1. The value should meet the condition that ``16 % in_channels == 0``. out_channels: number of output channels for the network. Defaults to 1. act: activation type in the network. Defaults to ``("elu", {"inplace": True})``. dropout_prob_down: dropout ratio for DownTransition blocks. Defaults to 0.5. dropout_prob_up: dropout ratio for UpTransition blocks. Defaults to (0.5, 0.5). dropout_dim: determine the dimensions of dropout. Defaults to (0.5, 0.5). - ``dropout_dim = 1``, randomly zeroes some of the elements for each channel. - ``dropout_dim = 2``, Randomly zeroes out entire channels (a channel is a 2D feature map). - ``dropout_dim = 3``, Randomly zeroes out entire channels (a channel is a 3D feature map). 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. .. deprecated:: 1.2 ``dropout_prob`` is deprecated in favor of ``dropout_prob_down`` and ``dropout_prob_up``. rJz1.2dropout_prob_downz'please use `dropout_prob_down` instead.)namesincenew_name msg_suffixdropout_prob_upz%please use `dropout_prob_up` instead.rHr@eluinplaceTr\)r\r\Frrrrr r rKr]rLrrc st|dvr tdt||d|| d|_t|dd|| d|_t|dd|| d|_t|dd ||| d |_t|d d||| d |_ t |d d d||d |_ t |d d d||d |_ t |d dd||_ t |ddd||_t|d||| d|_dS)N)rArHz spatial_dims can only be 2 or 3.)rr@ rA@rH)rJr)rJ)r!r"AssertionErrorr=in_trrG down_tr32 down_tr64 down_tr128 down_tr256rZup_tr256up_tr128up_tr64up_tr32rcout_tr) r&rrrr rJrerjrLrr'rrr"s z VNet.__init__cCsp||}||}||}||}||}|||}|||}|||}|||}| |}|Sr)) rsrtrurvrwrxryrzr{r|)r&r+Zout16Zout32Zout64Zout128Zout256rrrr- s          z VNet.forward)rrrrrrr r rJrKrerKrjr]rLrrr)r0r1r2__doc__r r"r-r3rrr'rr s, )r)r r r rr.) rrr rr4rr r rr) __future__rrCtorch.nnr7"monai.networks.blocks.convolutionsrmonai.networks.layers.factoriesrrrrr monai.utilsr __all__rModulerr;r=rGrZrcr rrrrs      "%'