code: def polygon_iou(
      polys_1: np.ndarray,
      polys_2: np.ndarray,
      mask_shape: Tuple[int, int],
      use_broadcasting: bool = False,
  ) -> np.ndarray:
      """Computes the IoU between two sets of rotated bounding boxes
  
      Args:
      ----
          polys_1: rotated bounding boxes of shape (N, 4, 2)
          polys_2: rotated bounding boxes of shape (M, 4, 2)
          mask_shape: spatial shape of the intermediate masks
          use_broadcasting: if set to True, leverage broadcasting speedup by consuming more memory
  
      Returns:
      -------
          the IoU matrix of shape (N, M)
      """
      if polys_1.ndim != 3 or polys_2.ndim != 3:
          raise AssertionError(
              "expects boxes to be in format (N, 4, 2)"
          )
  
      iou_mat: np.ndarray = np.zeros(
          (polys_1.shape[0], polys_2.shape[0]), dtype=np.float32
      )
  
      if polys_1.shape[0] > 0 and polys_2.shape[0] > 0:
          if use_broadcasting:
              masks_1 = rbox_to_mask(polys_1, shape=mask_shape)
              masks_2 = rbox_to_mask(polys_2, shape=mask_shape)
              iou_mat = mask_iou(masks_1, masks_2)
          else:
              # Save memory by doing the computation for each pair
              for idx, b1 in enumerate(polys_1):
                  m1 = _rbox_to_mask(b1, mask_shape)
                  for _idx, b2 in enumerate(polys_2):
                      m2 = _rbox_to_mask(b2, mask_shape)
                      iou_mat[idx, _idx] = (
                          np.logical_and(m1, m2).sum()
                          / np.logical_or(m1, m2).sum()
                      )
  
      return iou_mat
  
imports: from typing import Dict, List, Optional, Tuple
  import cv2
  import numpy
  from scipy.optimize import linear_sum_assignment
  from unidecode import unidecode
label_desc: Use image node_id 5 for calling a global function with example usage: polygon_iou(polys_1, polys_2, mask_shape, use_broadcasting) and returns: iou_mat