o , i•ã@sˆddlmZddlmZddlZddlmZddlmZm Z m Z ddl m Z gd¢Z Gdd„de ƒZGd d „d eƒZGd d „d eƒZdS) é)Ú annotations)ÚSequenceN)ÚActÚNormÚ split_args)Ú Regressor)Ú ClassifierÚ DiscriminatorÚCriticcs6eZdZdZddejejdddfd‡fdd„ Z‡Z S)ra« Defines a classification network from Regressor by specifying the output shape as a single dimensional tensor with size equal to the number of classes to predict. The final activation function can also be specified, eg. softmax or sigmoid. Args: in_shape: tuple of integers stating the dimension of the input tensor (minus batch dimension) classes: integer stating the dimension of the final output tensor 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 last_act: name defining the last activation layer ééNTÚin_shapeú Sequence[int]ÚclassesÚintÚchannelsÚstridesÚ kernel_sizeúSequence[int] | intÚ num_res_unitsÚdropoutú float | NoneÚbiasÚboolÚlast_actú str | NoneÚreturnÚNonec  s\tƒ ||f||||||| | ¡ | dur,t| ƒ\} } t| }|j d|di| ¤Ž¡dSdS)NZlastact©)ÚsuperÚ__init__rrÚfinalÚ add_module)Úselfr rrrrrÚactÚnormrrrZ last_act_nameZ last_act_argsZ last_act_type©Ú __class__rú`/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/networks/nets/classifier.pyr -s  üzClassifier.__init__)r rrrrrrrrrrrrrrrrrrr) Ú__name__Ú __module__Ú __qualname__Ú__doc__rÚPRELUrÚINSTANCEr Ú __classcell__rrr&r(rsôrcs8eZdZdZddejejddejfd‡fdd„ Z ‡Z S)r a< Defines a discriminator network from Classifier with a single output value and sigmoid activation by default. This is meant for use with GANs or other applications requiring a generic discriminator network. Args: in_shape: tuple of integers stating the dimension of the input 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 last_act: name defining the last activation layer r r çÐ?Tr rrrrrrrrrrrrrc s$tƒ |d|||||||| | ¡ dS©Né©rr ) r#r rrrrr$r%rrrr&rr(r Vs$ zDiscriminator.__init__©r rrrrrrrrrrrrrrr) r)r*r+r,rr-rr.ZSIGMOIDr r/rrr&r(r Dsõr csHeZdZdZddejejddfd‡fdd„ Zddd„Z ddd„Z ‡Z S)r a? Defines a critic network from Classifier with a single output value and no final activation. The final layer is `nn.Flatten` instead of `nn.Linear`, the final result is computed as the mean over the first dimension. This is meant to be used with Wasserstein GANs. Args: in_shape: tuple of integers stating the dimension of the input 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 r r r0Tr rrrrrrrrrrrrrc s$tƒ |d|||||||| d¡ dSr1r3) r#r rrrrr$r%rrr&rr(r xs$ zCritic.__init__cCst ¡S)N)ÚnnÚFlatten)r#r rrr(Ú_get_final_layer†szCritic._get_final_layerÚxú torch.TensorcCs2| |¡}| |¡}| d¡}| |jddf¡S)Nr2réÿÿÿÿ)Únetr!ÚmeanÚviewÚshape)r#r8rrr(Úforward‰s   zCritic.forwardr4)r r)r8r9rr9) r)r*r+r,rr-rr.r r7r?r/rrr&r(r fsö r )Ú __future__rÚcollections.abcrÚtorchÚtorch.nnr5Úmonai.networks.layers.factoriesrrrZmonai.networks.nets.regressorrÚ__all__rr r rrrr(Ús   +"