o ( iF@s`ddlmZddlZddlmZddlmmZddlm Z ddl m Z Gdddej Z dS)) annotationsN) Convolution)get_norm_layercs8eZdZdZ     ddfdd ZdddZZS)SPADEa Spatially Adaptive Normalization (SPADE) block, allowing for normalization of activations conditioned on a semantic map. This block is used in SPADE-based image-to-image translation models, as described in Semantic Image Synthesis with Spatially-Adaptive Normalization (https://arxiv.org/abs/1903.07291). Args: label_nc: number of semantic labels norm_nc: number of output channels kernel_size: kernel size spatial_dims: number of spatial dimensions hidden_channels: number of channels in the intermediate gamma and beta layers norm: type of base normalisation used before applying the SPADE normalisation norm_params: parameters for the base normalisation @INSTANCENlabel_ncintnorm_nc kernel_size spatial_dimshidden_channelsnorm str | tuple norm_params dict | NonereturnNonecs|t|dur i}t|dkr||f}t|||d|_t||||ddd|_t||||dd|_t||||dd|_dS)Nr)rchannels LEAKYRELU)r in_channels out_channelsr ract)rrrr r) super__init__lenrparam_free_normr mlp_shared mlp_gammamlp_beta)selfr r r rrrr __class__b/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/networks/blocks/spade_norm.pyr&s8   zSPADE.__init__x torch.TensorsegmapcCs\||}tj||dddd}||}||}||}|d||}|S)aF Args: x: input tensor with shape (B, C, [spatial-dimensions]) where C is the number of semantic channels. segmap: input segmentation map (B, C, [spatial-dimensions]) where C is the number of semantic channels. The map will be interpolated to the dimension of x internally. rNnearest)sizemode)r contiguousF interpolater+rr r!)r"r'r) normalizedZactvgammabetaoutr%r%r&forwardNs    z SPADE.forward)rrrr N)r r r r r r rr rr rrrrrr)r'r(r)r(rr()__name__ __module__ __qualname____doc__rr5 __classcell__r%r%r#r&rs(r) __future__rtorchtorch.nnnntorch.nn.functional functionalr/Zmonai.networks.blocksrmonai.networks.layers.utilsrModulerr%r%r%r&s