parameters: (y_true, y_pred, mode='giou', dtype=tf.float32)
docstring: Inersection over Union (IoU) and generalized IoU coefficients for bounding boxes.
      
      iou_box_coef(y_true, y_pred, mode='giou', dtype=tf.float32)
      
      ----------
      Rezatofighi, H., Tsoi, N., Gwak, J., Sadeghian, A., Reid, I. and Savarese, S., 2019. 
      Generalized intersection over union: A metric and a loss for bounding box regression. 
      In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (pp. 658-666).
      
      ----------
      Input
          y_true: the target bounding box. 
          y_pred: the predicted bounding box.
          
          Elements of a bounding box should be organized as: [y_min, x_min, y_max, x_max].
  
          mode: 'iou' for IoU coeff (i.e., Jaccard index);
                'giou' for generalized IoU coeff.
          
          dtype: the data type of input tensors.
                 Default is tf.float32.
docstring_summary: Inersection over Union (IoU) and generalized IoU coefficients for bounding boxes.
      
      iou_box_coef(y_true, y_pred, mode='giou', dtype=tf.float32)
      
      ----------
      Rezatofighi, H., Tsoi, N., Gwak, J., Sadeghian, A., Reid, I. and Savarese, S., 2019. 
      Generalized intersection over union: A metric and a loss for bounding box regression. 
      In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (pp. 658-666).
      
      ----------
      Input
          y_true: the target bounding box. 
          y_pred: the predicted bounding box.
          
          Elements of a bounding box should be organized as: [y_min, x_min, y_max, x_max].
docstring_tokens: Inersection over Union ( IoU ) and generalized IoU coefficients for bounding boxes . iou_box_coef ( y_true y_pred mode = giou dtype = tf . float32 ) ---------- Rezatofighi H . Tsoi N . Gwak J . Sadeghian A . Reid I . and Savarese S . 2019 . Generalized intersection over union : A metric and a loss for bounding box regression . In Proceedings of the IEEE / CVF Conference on Computer Vision and Pattern Recognition ( pp . 658 - 666 ) . ---------- Input y_true : the target bounding box . y_pred : the predicted bounding box . Elements of a bounding box should be organized as : [ y_min x_min y_max x_max ] .
function: def iou_box_coef(y_true, y_pred, mode='giou', dtype=tf.float32):
      
      """
      Inersection over Union (IoU) and generalized IoU coefficients for bounding boxes.
      
      iou_box_coef(y_true, y_pred, mode='giou', dtype=tf.float32)
      
      ----------
      Rezatofighi, H., Tsoi, N., Gwak, J., Sadeghian, A., Reid, I. and Savarese, S., 2019. 
      Generalized intersection over union: A metric and a loss for bounding box regression. 
      In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (pp. 658-666).
      
      ----------
      Input
          y_true: the target bounding box. 
          y_pred: the predicted bounding box.
          
          Elements of a bounding box should be organized as: [y_min, x_min, y_max, x_max].
  
          mode: 'iou' for IoU coeff (i.e., Jaccard index);
                'giou' for generalized IoU coeff.
          
          dtype: the data type of input tensors.
                 Default is tf.float32.
  
      """
      
      zero = tf.convert_to_tensor(0.0, dtype)
      
      # subtrack bounding box coords
      ymin_true, xmin_true, ymax_true, xmax_true = tf.unstack(y_true, 4, axis=-1)
      ymin_pred, xmin_pred, ymax_pred, xmax_pred = tf.unstack(y_pred, 4, axis=-1)
      
      # true area
      w_true = tf.maximum(zero, xmax_true - xmin_true)
      h_true = tf.maximum(zero, ymax_true - ymin_true)
      area_true = w_true * h_true
      
      # pred area
      w_pred = tf.maximum(zero, xmax_pred - xmin_pred)
      h_pred = tf.maximum(zero, ymax_pred - ymin_pred)
      area_pred = w_pred * h_pred
      
      # intersections
      intersect_ymin = tf.maximum(ymin_true, ymin_pred)
      intersect_xmin = tf.maximum(xmin_true, xmin_pred)
      intersect_ymax = tf.minimum(ymax_true, ymax_pred)
      intersect_xmax = tf.minimum(xmax_true, xmax_pred)
      
      w_intersect = tf.maximum(zero, intersect_xmax - intersect_xmin)
      h_intersect = tf.maximum(zero, intersect_ymax - intersect_ymin)
      area_intersect = w_intersect * h_intersect
      
      # IoU
      area_union = area_true + area_pred - area_intersect
      iou = tf.math.divide_no_nan(area_intersect, area_union)
      
      if mode == "iou":
          
          return iou
      
      else:
          
          # encolsed coords
          enclose_ymin = tf.minimum(ymin_true, ymin_pred)
          enclose_xmin = tf.minimum(xmin_true, xmin_pred)
          enclose_ymax = tf.maximum(ymax_true, ymax_pred)
          enclose_xmax = tf.maximum(xmax_true, xmax_pred)
          
          # enclosed area
          w_enclose = tf.maximum(zero, enclose_xmax - enclose_xmin)
          h_enclose = tf.maximum(zero, enclose_ymax - enclose_ymin)
          area_enclose = w_enclose * h_enclose
          
          # generalized IoU
          giou = iou - tf.math.divide_no_nan((area_enclose - area_union), area_enclose)
  
          return giou
function_tokens: def iou_box_coef ( y_true , y_pred , mode = 'giou' , dtype = tf . float32 ) : zero = tf . convert_to_tensor ( 0.0 , dtype ) # subtrack bounding box coords ymin_true , xmin_true , ymax_true , xmax_true = tf . unstack ( y_true , 4 , axis = - 1 ) ymin_pred , xmin_pred , ymax_pred , xmax_pred = tf . unstack ( y_pred , 4 , axis = - 1 ) # true area w_true = tf . maximum ( zero , xmax_true - xmin_true ) h_true = tf . maximum ( zero , ymax_true - ymin_true ) area_true = w_true * h_true # pred area w_pred = tf . maximum ( zero , xmax_pred - xmin_pred ) h_pred = tf . maximum ( zero , ymax_pred - ymin_pred ) area_pred = w_pred * h_pred # intersections intersect_ymin = tf . maximum ( ymin_true , ymin_pred ) intersect_xmin = tf . maximum ( xmin_true , xmin_pred ) intersect_ymax = tf . minimum ( ymax_true , ymax_pred ) intersect_xmax = tf . minimum ( xmax_true , xmax_pred ) w_intersect = tf . maximum ( zero , intersect_xmax - intersect_xmin ) h_intersect = tf . maximum ( zero , intersect_ymax - intersect_ymin ) area_intersect = w_intersect * h_intersect # IoU area_union = area_true + area_pred - area_intersect iou = tf . math . divide_no_nan ( area_intersect , area_union ) if mode == "iou" : return iou else : # encolsed coords enclose_ymin = tf . minimum ( ymin_true , ymin_pred ) enclose_xmin = tf . minimum ( xmin_true , xmin_pred ) enclose_ymax = tf . maximum ( ymax_true , ymax_pred ) enclose_xmax = tf . maximum ( xmax_true , xmax_pred ) # enclosed area w_enclose = tf . maximum ( zero , enclose_xmax - enclose_xmin ) h_enclose = tf . maximum ( zero , enclose_ymax - enclose_ymin ) area_enclose = w_enclose * h_enclose # generalized IoU giou = iou - tf . math . divide_no_nan ( ( area_enclose - area_union ) , area_enclose ) return giou