text: import torch
  import numpy as np
  import torch.nn.functional as F
  import torch.nn as nn
  
  def get_pad(in_,  ksize, stride, atrous=1):
      out_ = np.ceil(float(in_)/stride)
      return int(((out_ - 1) * stride + atrous*(ksize-1) + 1 - in_)/2)
  
  class ConvWithActivation(torch.nn.Module):
      """
      SN convolution for spetral normalization conv
      """
      def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, activation=torch.nn.LeakyReLU(0.2, inplace=True)):
          super(ConvWithActivation, self).__init__()
          self.conv2d = torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias)
          self.conv2d = torch.nn.utils.spectral_norm(self.conv2d)
          self.activation = activation
          for m in self.modules():
              if isinstance(m, nn.Conv2d):
                  nn.init.kaiming_normal_(m.weight)
      def forward(self, input):
          x = self.conv2d(input)
          if self.activation is not None:
              return self.activation(x)
          else:
              return x
  
  class DeConvWithActivation(torch.nn.Module):
      """
      SN convolution for spetral normalization conv
      """
      def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, activation=torch.nn.LeakyReLU(0.2, inplace=True)):
          super(DeConvWithActivation, self).__init__()
          self.conv2d = torch.nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride, padding, dilation, groups, bias)
          self.conv2d = torch.nn.utils.spectral_norm(self.conv2d)
          self.activation = activation
          for m in self.modules():
              if isinstance(m, nn.ConvTranspose2d):
                  nn.init.kaiming_normal_(m.weight)
      def forward(self, input):
          x = self.conv2d(input)
          if self.activation is not None:
              return self.activation(x)
          else:
              return x