code: def icnr_init(
      tensor: torch.Tensor,
      upscale_factor=2,
      initializer=nn.init.kaiming_normal,
  ):
      """Fill the input Tensor or Variable with values according to the method
      described in "Checkerboard artifact free sub-pixel convolution"
      - Andrew Aitken et al. (2017), this inizialization should be used in the
      last convolutional layer before a PixelShuffle operation
      Args:
          tensor: an n-dimensional torch.Tensor or autograd.Variable
          upscale_factor: factor to increase spatial resolution by
          initializer: inizializer to be used for sub_kernel inizialization
      Examples:
          >>> upscale = 8
          >>> num_classes = 10
          >>> previous_layer_features = Variable(torch.Tensor(8, 64, 32, 32))
          >>> conv_shuffle = Conv2d(64, num_classes * (upscale ** 2), 3, padding=1, bias=0)
          >>> ps = PixelShuffle(upscale)
          >>> kernel = ICNR(conv_shuffle.weight, scale_factor=upscale)
          >>> conv_shuffle.weight.data.copy_(kernel)
          >>> output = ps(conv_shuffle(previous_layer_features))
          >>> print(output.shape)
          torch.Size([8, 10, 256, 256])
      .. _Checkerboard artifact free sub-pixel convolution:
          https://arxiv.org/abs/1707.02937
      """
      new_shape = [int(tensor.shape[0] / (upscale_factor**2))] + list(
          tensor.shape[1:]
      )
      subkernel = torch.zeros(new_shape)
      subkernel = initializer(subkernel)
      subkernel = subkernel.transpose(0, 1)
  
      subkernel = subkernel.contiguous().view(
          subkernel.shape[0], subkernel.shape[1], -1
      )
  
      kernel = subkernel.repeat(1, 1, upscale_factor**2)
  
      transposed_shape = (
          [tensor.shape[1]] + [tensor.shape[0]] + list(tensor.shape[2:])
      )
      kernel = kernel.contiguous().view(transposed_shape)
  
      kernel = kernel.transpose(0, 1)
      return kernel
  
imports: from enum import Enum
  from math import hypot
  from typing import Optional, List, Tuple, Union, Type
  import torch
  from torch import nn, Tensor
label_desc: Use image node_id 2 for calling a global function with example usage: icnr_init(tensor, upscale_factor, initializer) and returns: kernel