class_docstr: Vision Transformer with support for patch input
      
class_docstr_tok: ["Vision","Transformer","with","support","for","patch","input"]
code: def init_weight(self):
      pretrained = self.pretrained
  
      if pretrained:
          if "http" in pretrained:  # URL
              path = paddle.utils.download.get_weights_path_from_url(
                  pretrained
              )
          else:  # model in local path
              path = pretrained
  
          load_state_dict = paddle.load(path)
          model_state_dict = self.state_dict()
          pos_embed_name = "pos_embed"
  
          if pos_embed_name in load_state_dict.keys():
              load_pos_embed = paddle.to_tensor(
                  load_state_dict[pos_embed_name], dtype="float32"
              )
              if self.pos_embed.shape != load_pos_embed.shape:
                  pos_size = int(math.sqrt(load_pos_embed.shape[1] - 1))
                  model_state_dict[
                      pos_embed_name
                  ] = self.resize_pos_embed(
                      load_pos_embed,
                      (pos_size, pos_size),
                      (self.pos_h, self.pos_w),
                  )
  
                  # self.set_state_dict(model_state_dict)
                  load_state_dict[pos_embed_name] = model_state_dict[
                      pos_embed_name
                  ]
  
                  print(
                      "Load pos_embed and resize it from {} to {} .".format(
                          load_pos_embed.shape, self.pos_embed.shape
                      )
                  )
  
          self.set_state_dict(load_state_dict)
          print("Load load_state_dict....")
  
imports: import math
  import paddle
  import paddle.nn
  import paddle.nn.functional
  import numpy
  from paddle.nn.initializer import Constant
  from ppdet.modeling.shape_spec import ShapeSpec
  from ppdet.core.workspace import register, serializable
  from .transformer_utils import zeros_, DropPath, Identity
label_desc: Use image node_id 2 for calling the VisionTransformer obj's underlying member method code with example usage: obj.init_weight() without return types