code: def _interpolate_opencv(
      x: torch.Tensor, size: Tuple[int, int], interpolation: str
  ) -> torch.Tensor:
      """
      Down/up samples the input torch tensor x to the given size with given interpolation
      mode.
      Args:
          input (Tensor): the input tensor to be down/up sampled.
          size (Tuple[int, int]): expected output spatial size.
          interpolation: model to perform interpolation, options include `nearest`,
              `linear`, `bilinear`, `bicubic`.
      """
      if not _HAS_CV2:
          raise ImportError(
              "opencv is required to use opencv transforms. Please "
              "install with 'pip install opencv-python'."
          )
  
      _opencv_pytorch_interpolation_map = {
          "nearest": cv2.INTER_NEAREST,
          "linear": cv2.INTER_LINEAR,
          "bilinear": cv2.INTER_LINEAR,
          "bicubic": cv2.INTER_CUBIC,
      }
      assert interpolation in _opencv_pytorch_interpolation_map
      new_h, new_w = size
      img_array_list = [
          img_tensor.squeeze(0).numpy()
          for img_tensor in x.permute(1, 2, 3, 0).split(1, dim=0)
      ]
      resized_img_array_list = [
          cv2.resize(
              img_array,
              (new_w, new_h),  # The input order for OpenCV is w, h.
              interpolation=_opencv_pytorch_interpolation_map[
                  interpolation
              ],
          )
          for img_array in img_array_list
      ]
      img_array = np.concatenate(
          [
              np.expand_dims(img_array, axis=0)
              for img_array in resized_img_array_list
          ],
          axis=0,
      )
      img_tensor = torch.from_numpy(np.ascontiguousarray(img_array))
      img_tensor = img_tensor.permute(3, 0, 1, 2)
      return img_tensor
  
imports: import copy
  import math
  from typing import Tuple
  import numpy
  import torch
label_desc: Use image node_id 2 for calling a global function with example usage: _interpolate_opencv(x, size, interpolation) and returns: img_tensor