code: def init_weights(net, init_type="normal", gain=0.02):
      def init_func(m):
          classname = m.__class__.__name__
          if hasattr(m, "weight") and (
              classname.find("Conv") != -1
              or classname.find("Linear") != -1
          ):
              if init_type == "normal":
                  init.normal_(m.weight.data, 0.0, gain)
              elif init_type == "xavier":
                  init.xavier_normal_(m.weight.data, gain=gain)
              elif init_type == "kaiming":
                  init.kaiming_normal_(
                      m.weight.data, a=0, mode="fan_in"
                  )
              elif init_type == "orthogonal":
                  init.orthogonal_(m.weight.data, gain=gain)
              else:
                  raise NotImplementedError(
                      "initialization method [%s] is not implemented"
                      % init_type
                  )
              if hasattr(m, "bias") and m.bias is not None:
                  init.constant_(m.bias.data, 0.0)
          elif classname.find("BatchNorm2d") != -1:
              init.normal_(m.weight.data, 1.0, gain)
              init.constant_(m.bias.data, 0.0)
  
      print("initialize network with %s" % init_type)
      net.apply(init_func)
  
imports: import torch
  from torch.nn import init
label_desc: Use image node_id 1 for calling a global function with example usage: init_weights(net, init_type, gain) without return types