code: def bbox_flip(
      bboxes: Tensor,
      img_shape: Tuple[int],
      direction: str = "horizontal",
  ) -> Tensor:
      """Flip bboxes horizontally or vertically.
  
      Args:
          bboxes (Tensor): Shape (..., 4*k)
          img_shape (Tuple[int]): Image shape.
          direction (str): Flip direction, options are "horizontal", "vertical",
              "diagonal". Default: "horizontal"
  
      Returns:
          Tensor: Flipped bboxes.
      """
      assert bboxes.shape[-1] % 4 == 0
      assert direction in ["horizontal", "vertical", "diagonal"]
      flipped = bboxes.clone()
      if direction == "horizontal":
          flipped[..., 0::4] = img_shape[1] - bboxes[..., 2::4]
          flipped[..., 2::4] = img_shape[1] - bboxes[..., 0::4]
      elif direction == "vertical":
          flipped[..., 1::4] = img_shape[0] - bboxes[..., 3::4]
          flipped[..., 3::4] = img_shape[0] - bboxes[..., 1::4]
      else:
          flipped[..., 0::4] = img_shape[1] - bboxes[..., 2::4]
          flipped[..., 1::4] = img_shape[0] - bboxes[..., 3::4]
          flipped[..., 2::4] = img_shape[1] - bboxes[..., 0::4]
          flipped[..., 3::4] = img_shape[0] - bboxes[..., 1::4]
      return flipped
  
imports: from typing import List, Optional, Sequence, Tuple, Union
  import numpy
  import torch
  from torch import Tensor
  from mmdet.structures.bbox import BaseBoxes
label_desc: Use image node_id 2 for calling a global function with example usage: bbox_flip(bboxes, img_shape, direction) and returns: flipped