code: def resample_data(
      z,
      bbox_xywh_src,
      bbox_xywh_dst,
      wout,
      hout,
      mode: str = "nearest",
      padding_mode: str = "zeros",
  ):
      """
      Args:
          z (:obj: `torch.Tensor`): tensor of size (N,C,H,W) with data to be
              resampled
          bbox_xywh_src (:obj: `torch.Tensor`): tensor of size (N,4) containing
              source bounding boxes in format XYWH
          bbox_xywh_dst (:obj: `torch.Tensor`): tensor of size (N,4) containing
              destination bounding boxes in format XYWH
      Return:
          zresampled (:obj: `torch.Tensor`): tensor of size (N, C, Hout, Wout)
              with resampled values of z, where D is the discretization size
      """
      n = bbox_xywh_src.size(0)
      assert n == bbox_xywh_dst.size(0), (
          "The number of "
          "source ROIs for resampling ({}) should be equal to the number "
          "of destination ROIs ({})".format(
              bbox_xywh_src.size(0), bbox_xywh_dst.size(0)
          )
      )
      x0src, y0src, wsrc, hsrc = bbox_xywh_src.unbind(dim=1)
      x0dst, y0dst, wdst, hdst = bbox_xywh_dst.unbind(dim=1)
      x0dst_norm = 2 * (x0dst - x0src) / wsrc - 1
      y0dst_norm = 2 * (y0dst - y0src) / hsrc - 1
      x1dst_norm = 2 * (x0dst + wdst - x0src) / wsrc - 1
      y1dst_norm = 2 * (y0dst + hdst - y0src) / hsrc - 1
      grid_w = (
          torch.arange(wout, device=z.device, dtype=torch.float) / wout
      )
      grid_h = (
          torch.arange(hout, device=z.device, dtype=torch.float) / hout
      )
      grid_w_expanded = grid_w[None, None, :].expand(n, hout, wout)
      grid_h_expanded = grid_h[None, :, None].expand(n, hout, wout)
      dx_expanded = (x1dst_norm - x0dst_norm)[:, None, None].expand(
          n, hout, wout
      )
      dy_expanded = (y1dst_norm - y0dst_norm)[:, None, None].expand(
          n, hout, wout
      )
      x0_expanded = x0dst_norm[:, None, None].expand(n, hout, wout)
      y0_expanded = y0dst_norm[:, None, None].expand(n, hout, wout)
      grid_x = grid_w_expanded * dx_expanded + x0_expanded
      grid_y = grid_h_expanded * dy_expanded + y0_expanded
      grid = torch.stack((grid_x, grid_y), dim=3)
      # resample Z from (N, C, H, W) into (N, C, Hout, Wout)
      zresampled = F.grid_sample(
          z,
          grid,
          mode=mode,
          padding_mode=padding_mode,
          align_corners=True,
      )
      return zresampled
  
imports: from abc import ABC, abstractmethod
  from dataclasses import dataclass
  from typing import Any, Dict, List, Optional, Tuple
  import torch
  from torch.nn import functional
  from detectron2.structures import BoxMode, Instances
  from densepose import DensePoseDataRelative
label_desc: Use image node_id 2 for calling a global function with example usage: resample_data(z, bbox_xywh_src, bbox_xywh_dst, wout, hout, mode, padding_mode) and returns: zresampled