class_docstr: https://discuss.pytorch.org/t/is-there-anyway-to-do-gaussian-filtering-for-an-image-2d-3d-in-pytorch/12351/10
  Apply gaussian smoothing on a tensor (1d, 2d, 3d).
  Filtering is performed seperately for each channel in the input using a depthwise convolution.
  Arguments:
      channels (int, sequence): Number of channels of the input tensors.
          Output will have this number of channels as well.
      kernel_size (int, sequence): Size of the gaussian kernel.
      sigma (float, sequence): Standard deviation of the gaussian kernel.
      dim (int, optional): The number of dimensions of the data. Default value is 2 (spatial).
class_docstr_tok: ["https",":","\/\/discuss.pytorch.org\/t\/is-there-anyway-to-do-gaussian-filtering-for-an-image-2d-3d-in-pytorch\/12351\/10","Apply","gaussian","smoothing","on","a","tensor","(","1d",",","2d",",","3d",")",".","Filtering","is","performed","seperately","for","each","channel","in","the","input","using","a","depthwise","convolution",".","Arguments",":","channels","(","int",",","sequence",")",":","Number","of","channels","of","the","input","tensors",".","Output","will","have","this","number","of","channels","as","well",".","kernel_size","(","int",",","sequence",")",":","Size","of","the","gaussian","kernel",".","sigma","(","float",",","sequence",")",":","Standard","deviation","of","the","gaussian","kernel",".","dim","(","int",",","optional",")",":","The","number","of","dimensions","of","the","data",".","Default","value","is","2","(","spatial",")","."]
code: def __init__(self, channels, kernel_size, sigma, padding=0, dim=2):
      super(GaussianSmoothing, self).__init__()
      if isinstance(kernel_size, numbers.Number):
          kernel_size = [kernel_size] * dim
      if isinstance(sigma, numbers.Number):
          sigma = [sigma] * dim
  
      # The gaussian kernel is the product of the gaussian function of each dimension.
      kernel = 1.0
      meshgrids = torch.meshgrid(
          [
              torch.arange(size, dtype=torch.float32)
              for size in kernel_size
          ]
      )
      for size, std, grid in zip(kernel_size, sigma, meshgrids):
          mean = (size - 1) / 2.0
          kernel *= torch.exp(-(((grid - mean) / std) ** 2) / 2) / (
              std * (2 * math.pi) ** 0.5
          )
      # Make sure sum of values in gaussian kernel equals 1.
      kernel = kernel / torch.sum(kernel)
      # Reshape to depthwise convolutional weight.
      kernel = kernel.view(1, 1, *kernel.size())
      kernel = torch.repeat_interleave(kernel, channels, 0)
  
      self.register_buffer("weight", kernel)
      self.groups = channels
      self.padding = padding
  
      if dim == 1:
          self.conv = F.conv1d
      elif dim == 2:
          self.conv = F.conv2d
      elif dim == 3:
          self.conv = F.conv3d
      else:
          raise RuntimeError(
              "Only 1, 2 and 3 dimensions are supported. Received {}.".format(
                  dim
              )
          )
  
imports: import math
  import torch
  import numbers
  import torch.nn
  import torch.nn.functional
label_desc: Use image node_id 1 to create a new GaussianSmoothing object from inherited base classes: nn with example: obj = GaussianSmoothing(channels, kernel_size, sigma, padding, dim)