U ˜PÓh•ã@sŠddlmZddlmZddlZddlmZddlmZm Z m Z ddl m Z dddgZ Gd d„de ƒZGd d„deƒZGd d„deƒZdS) é)Ú annotations)ÚSequenceN)ÚActÚNormÚ split_args)Ú RegressorÚ ClassifierÚ DiscriminatorÚCriticc sLeZdZdZddejejdddfddddddd d d d d œ ‡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ú Sequence[int]ÚintúSequence[int] | intú float | NoneÚboolz str | NoneÚNone) Úin_shapeÚclassesÚchannelsÚstridesÚ kernel_sizeÚ num_res_unitsÚdropoutÚbiasÚlast_actÚreturnc  sTtƒ ||f||||||| | ¡ | dk rPt| ƒ\} } t| }|j d|f| Ž¡dS)NZlastact)ÚsuperÚ__init__rrÚfinalÚ add_module)ÚselfrrrrrrÚactÚnormrrrZ last_act_nameZ last_act_argsZ last_act_type©Ú __class__©úS/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/networks/nets/classifier.pyr-s   zClassifier.__init__) Ú__name__Ú __module__Ú __qualname__Ú__doc__rÚPRELUrÚINSTANCErÚ __classcell__r&r&r$r'rsôc sJeZdZdZddejejddejfdddddd d d d œ‡fd d„ 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 rrrrr©rrrrrrrrc s$tƒ |d|||||||| | ¡ dS©Né©rr) r!rrrrrr"r#rrrr$r&r'rVs zDiscriminator.__init__) r(r)r*r+rr,rr-ÚSIGMOIDrr.r&r&r$r'r Dsõc sdeZdZdZddejejddfdddddd d d d œ‡fd d„ Zddœdd„Z dddœdd„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 r/Tr rrrrrr0c s$tƒ |d|||||||| d¡ dSr1r3) r!rrrrrr"r#rrr$r&r'rxs zCritic.__init__)rcCst ¡S)N)ÚnnÚFlatten)r!rr&r&r'Ú_get_final_layer†szCritic._get_final_layerz torch.Tensor)ÚxrcCs2| |¡}| |¡}| d¡}| |jddf¡S)Nr2réÿÿÿÿ)ÚnetrÚmeanÚviewÚshape)r!r8r&r&r'Úforward‰s   zCritic.forward) r(r)r*r+rr,rr-rr7r>r.r&r&r$r'r fsö")Ú __future__rÚcollections.abcrÚtorchÚtorch.nnr5Úmonai.networks.layers.factoriesrrrZmonai.networks.nets.regressorrÚ__all__rr r r&r&r&r'Ú s     +"