class_docstr: Flip the image & bbox polygon.
  
  There are 3 flip modes:
  
   - ``prob`` is float, ``direction`` is string: the image will be
       ``direction``ly flipped with probability of ``prob`` .
       E.g., ``prob=0.5``, ``direction='horizontal'``,
       then image will be horizontally flipped with probability of 0.5.
   - ``prob`` is float, ``direction`` is list of string: the image will
       be ``direction[i]``ly flipped with probability of
       ``prob/len(direction)``.
       E.g., ``prob=0.5``, ``direction=['horizontal', 'vertical']``,
       then image will be horizontally flipped with probability of 0.25,
       vertically with probability of 0.25.
   - ``prob`` is list of float, ``direction`` is list of string:
       given ``len(prob) == len(direction)``, the image will
       be ``direction[i]``ly flipped with probability of ``prob[i]``.
       E.g., ``prob=[0.3, 0.5]``, ``direction=['horizontal',
       'vertical']``, then image will be horizontally flipped with
       probability of 0.3, vertically with probability of 0.5.
  
  Required Keys:
      - img
      - gt_bboxes (optional)
      - gt_polygons (optional)
  
  Modified Keys:
      - img
      - gt_bboxes (optional)
      - gt_polygons (optional)
  
  Added Keys:
      - flip
      - flip_direction
  Args:
       prob (float | list[float], optional): The flipping probability.
           Defaults to None.
       direction(str | list[str]): The flipping direction. Options
           If input is a list, the length must equal ``prob``. Each
           element in ``prob`` indicates the flip probability of
           corresponding direction. Defaults to 'horizontal'.
docstr: Flip polygons horizontally, vertically or diagonally.
  
  Args:
      polygons (list[numpy.ndarray): polygons.
      img_shape (tuple[int]): Image shape (height, width)
      direction (str): Flip direction. Options are 'horizontal',
          'vertical' and 'diagonal'.
  Returns:
      list[numpy.ndarray]: Flipped polygons.
docstr_tok: ["Flip","polygons","horizontally",",","vertically","or","diagonally",".","Args",":","polygons","(","list","[","numpy.ndarray",")",":","polygons",".","img_shape","(","tuple","[","int","]",")",":","Image","shape","(","height",",","width",")","direction","(","str",")",":","Flip","direction",".","Options","are","'horizontal","'",",","'vertical","'","and","'diagonal","'",".","Returns",":","list","[","numpy.ndarray","]",":","Flipped","polygons","."]
code: def flip_polygons(
      self,
      polygons: Sequence[np.ndarray],
      img_shape: Tuple[int, int],
      direction: str,
  ) -> Sequence[np.ndarray]:
      """Flip polygons horizontally, vertically or diagonally.
  
      Args:
          polygons (list[numpy.ndarray): polygons.
          img_shape (tuple[int]): Image shape (height, width)
          direction (str): Flip direction. Options are 'horizontal',
              'vertical' and 'diagonal'.
      Returns:
          list[numpy.ndarray]: Flipped polygons.
      """
  
      h, w = img_shape
      flipped_polygons = []
      if direction == "horizontal":
          for polygon in polygons:
              flipped_polygon = polygon.copy()
              flipped_polygon[0::2] = w - polygon[0::2]
              flipped_polygons.append(flipped_polygon)
      elif direction == "vertical":
          for polygon in polygons:
              flipped_polygon = polygon.copy()
              flipped_polygon[1::2] = h - polygon[1::2]
              flipped_polygons.append(flipped_polygon)
      elif direction == "diagonal":
          for polygon in polygons:
              flipped_polygon = polygon.copy()
              flipped_polygon[0::2] = w - polygon[0::2]
              flipped_polygon[1::2] = h - polygon[1::2]
              flipped_polygons.append(flipped_polygon)
      else:
          raise ValueError(
              f"Flipping direction must be 'horizontal', 'vertical', \
                    or 'diagnal', but got '{direction}'"
          )
      return flipped_polygons
  
imports: import math
  import random
  from typing import Dict, List, Sequence, Tuple, Union
  import cv2
  import mmcv
  import numpy
  from mmcv.transforms import RandomFlip
  from mmcv.transforms.base import BaseTransform
  from mmcv.transforms.utils import avoid_cache_randomness, cache_randomness
  from shapely.geometry import Polygon
  from mmocr.registry import TRANSFORMS
  from mmocr.utils import crop_polygon, poly2bbox, poly_intersection
label_desc: Use image node_id 1 for calling the RandomFlip obj's underlying member method code with example usage: obj.flip_polygons(polygons, img_shape, direction) and returns: flipped_polygons