code: def main(weights_path: str, model_name: str, model: tf.keras.Model):
      var_dict = {v.name.split(":")[0]: v for v in model.weights}
  
      weights_dict = torch.load(weights_path, map_location="cpu")[
          "model"
      ]
      w_dict = {}
      for k, v in weights_dict.items():
          if "patch_embed" in k:
              k = k.replace(".", "/")
              if "proj" in k:
                  k = k.replace("proj/weight", "proj/kernel")
                  if len(v.shape) > 1:
                      # conv weights
                      v = np.transpose(v.numpy(), (2, 3, 1, 0)).astype(
                          np.float32
                      )
                      w_dict[k] = v
                  else:
                      # bias
                      w_dict[k] = v
              elif "norm" in k:
                  k = k.replace("weight", "gamma").replace(
                      "bias", "beta"
                  )
                  w_dict[k] = v
          elif "layers" in k:
              k = k.replace("layers", "layer")
              split_k = k.split(".")
              layer_id = split_k[0] + split_k[1]
              if "block" in k:
                  split_k[2] = "block"
                  black_id = split_k[2] + split_k[3]
                  k = "/".join([layer_id, black_id, *split_k[4:]])
                  if "attn" in k or "mlp" in k:
                      k = k.replace("weight", "kernel")
                      if "kernel" in k:
                          v = np.transpose(v.numpy(), (1, 0)).astype(
                              np.float32
                          )
                  elif "norm" in k:
                      k = k.replace("weight", "gamma").replace(
                          "bias", "beta"
                      )
                  w_dict[k] = v
              elif "downsample" in k:
                  k = "/".join([layer_id, *split_k[2:]])
                  if "reduction" in k:
                      k = k.replace("weight", "kernel")
                      if "kernel" in k:
                          v = np.transpose(v.numpy(), (1, 0)).astype(
                              np.float32
                          )
                  elif "norm" in k:
                      k = k.replace("weight", "gamma").replace(
                          "bias", "beta"
                      )
                  w_dict[k] = v
          elif "norm" in k:
              k = (
                  k.replace(".", "/")
                  .replace("weight", "gamma")
                  .replace("bias", "beta")
              )
              w_dict[k] = v
          elif "head" in k:
              k = k.replace(".", "/")
              k = k.replace("weight", "kernel")
              if "kernel" in k:
                  v = np.transpose(v.numpy(), (1, 0)).astype(np.float32)
              w_dict[k] = v
  
      for key, var in var_dict.items():
          if key in w_dict:
              if w_dict[key].shape != var.shape:
                  msg = "shape mismatch: {}".format(key)
                  print(msg)
              else:
                  var.assign(w_dict[key], read_value=False)
          else:
              msg = "Not found {} in {}".format(key, weights_path)
              print(msg)
  
      model.save_weights("./{}.h5".format(model_name))
  
label_desc: Use image node_id 1 for calling a global function with example usage: main(weights_path, model_name, model) without return types