code: def resample_patch_embed(
      patch_embed,
      new_size: List[int],
      interpolation: str = "bicubic",
      antialias: bool = True,
      verbose: bool = False,
  ):
      """Resample the weights of the patch embedding kernel to target resolution.
      We resample the patch embedding kernel by approximately inverting the effect
      of patch resizing.
  
      Code based on:
        https://github.com/google-research/big_vision/blob/b00544b81f8694488d5f36295aeb7972f3755ffe/big_vision/models/proj/flexi/vit.py
  
      With this resizing, we can for example load a B/8 filter into a B/16 model
      and, on 2x larger input image, the result will match.
  
      Args:
          patch_embed: original parameter to be resized.
          new_size (tuple(int, int): target shape (height, width)-only.
          interpolation (str): interpolation for resize
          antialias (bool): use anti-aliasing filter in resize
          verbose (bool): log operation
      Returns:
          Resized patch embedding kernel.
      """
      import numpy as np
  
      try:
          import functorch
  
          vmap = functorch.vmap
      except ImportError:
          if hasattr(torch, "vmap"):
              vmap = torch.vmap
          else:
              assert (
                  False
              ), "functorch or a version of torch with vmap is required for FlexiViT resizing."
  
      assert len(patch_embed.shape) == 4, "Four dimensions expected"
      assert len(new_size) == 2, "New shape should only be hw"
      old_size = patch_embed.shape[-2:]
      if tuple(old_size) == tuple(new_size):
          return patch_embed
  
      if verbose:
          _logger.info(
              f"Resize patch embedding {patch_embed.shape} to {new_size}, w/ {interpolation} interpolation."
          )
  
      def resize(x_np, _new_size):
          x_tf = torch.Tensor(x_np)[None, None, ...]
          x_upsampled = F.interpolate(
              x_tf,
              size=_new_size,
              mode=interpolation,
              antialias=antialias,
          )[0, 0, ...].numpy()
          return x_upsampled
  
      def get_resize_mat(_old_size, _new_size):
          mat = []
          for i in range(np.prod(_old_size)):
              basis_vec = np.zeros(_old_size)
              basis_vec[np.unravel_index(i, _old_size)] = 1.0
              mat.append(resize(basis_vec, _new_size).reshape(-1))
          return np.stack(mat).T
  
      resize_mat = get_resize_mat(old_size, new_size)
      resize_mat_pinv = torch.tensor(
          np.linalg.pinv(resize_mat.T), device=patch_embed.device
      )
  
      def resample_kernel(kernel):
          resampled_kernel = resize_mat_pinv @ kernel.reshape(-1)
          return resampled_kernel.reshape(new_size)
  
      v_resample_kernel = vmap(vmap(resample_kernel, 0, 0), 1, 1)
      orig_dtype = patch_embed.dtype
      patch_embed = patch_embed.float()
      patch_embed = v_resample_kernel(patch_embed)
      patch_embed = patch_embed.to(orig_dtype)
      return patch_embed
  
file_path: pytorch-image-models/timm/layers/patch_embed.py
imports: import logging
  from typing import Callable, List, Optional, Tuple, Union
  import torch
  from torch import nn
  import torch.nn.functional
  from .format import Format, nchw_to
  from .helpers import to_2tuple
  from .trace_utils import _assert
label_desc: Use image node_id 1 for calling a global function with example usage: resample_patch_embed(patch_embed, new_size, interpolation, antialias, verbose) and returns: patch_embed, patch_embed, x_upsampled, np, resampled_kernel