class_docstr: The horizontal box class used in MMDetection by default.
  
  The ``box_dim`` of ``HorizontalBoxes`` is 4, which means the length of
  the last dimension of the data should be 4. Two modes of box data are
  supported in ``HorizontalBoxes``:
  
  - 'xyxy': Each row of data indicates (x1, y1, x2, y2), which are the
    coordinates of the left-top and right-bottom points.
  - 'cxcywh': Each row of data indicates (x, y, w, h), where (x, y) are the
    coordinates of the box centers and (w, h) are the width and height.
  
  ``HorizontalBoxes`` only restores 'xyxy' mode of data. If the the data is
  in 'cxcywh' mode, users need to input ``in_mode='cxcywh'`` and The code
  will convert the 'cxcywh' data to 'xyxy' automatically.
  
  Args:
      data (Tensor or np.ndarray or Sequence): The box data with shape of
          (..., 4).
      dtype (torch.dtype, Optional): data type of boxes. Defaults to None.
      device (str or torch.device, Optional): device of boxes.
          Default to None.
      clone (bool): Whether clone ``boxes`` or not. Defaults to True.
      mode (str, Optional): the mode of boxes. If it is 'cxcywh', the
          `data` will be converted to 'xyxy' mode. Defaults to None.
class_docstr_tok: ["The","horizontal","box","class","used","in","MMDetection","by","default",".","The","``","box_dim","``","of","``","HorizontalBoxes","``","is","4",",","which","means","the","length","of","the","last","dimension","of","the","data","should","be","4",".","Two","modes","of","box","data","are","supported","in","``","HorizontalBoxes","``",":","-","'xyxy","'",":","Each","row","of","data","indicates","(","x1",",","y1",",","x2",",","y2",")",",","which","are","the","coordinates","of","the","left-top","and","right-bottom","points",".","-","'cxcywh","'",":","Each","row","of","data","indicates","(","x",",","y",",","w",",","h",")",",","where","(","x",",","y",")","are","the","coordinates","of","the","box","centers","and","(","w",",","h",")","are","the","width","and","height",".","``","HorizontalBoxes","``","only","restores","'xyxy","'","mode","of","data",".","If","the","the","data","is","in","'cxcywh","'","mode",",","users","need","to","input","``","in_mode='cxcywh","'","``","and","The","code","will","convert","the","'cxcywh","'","data","to","'xyxy","'","automatically",".","Args",":","data","(","Tensor","or","np.ndarray","or","Sequence",")",":","The","box","data","with","shape","of","(","...",",","4",")",".","dtype","(","torch.dtype",",","Optional",")",":","data","type","of","boxes",".","Defaults","to","None",".","device","(","str","or","torch.device",",","Optional",")",":","device","of","boxes",".","Default","to","None",".","clone","(","bool",")",":","Whether","clone","``","boxes","``","or","not",".","Defaults","to","True",".","mode","(","str",",","Optional",")",":","the","mode","of","boxes",".","If","it","is","'cxcywh","'",",","the","`","data","`","will","be","converted","to","'xyxy","'","mode",".","Defaults","to","None","."]
docstr: Create horizontal boxes from instance masks.
  
  Args:
      masks (:obj:`BitmapMasks` or :obj:`PolygonMasks`): BitmapMasks or
          PolygonMasks instance with length of n.
  
  Returns:
      :obj:`HorizontalBoxes`: Converted boxes with shape of (n, 4).
docstr_tok: ["Create","horizontal","boxes","from","instance","masks",".","Args",":","masks","(",":","obj",":","`","BitmapMasks","`","or",":","obj",":","`","PolygonMasks","`",")",":","BitmapMasks","or","PolygonMasks","instance","with","length","of","n.","Returns",":",":","obj",":","`","HorizontalBoxes","`",":","Converted","boxes","with","shape","of","(","n",",","4",")","."]
code: def from_instance_masks(masks: MaskType) -> "HorizontalBoxes":
      """Create horizontal boxes from instance masks.
  
      Args:
          masks (:obj:`BitmapMasks` or :obj:`PolygonMasks`): BitmapMasks or
              PolygonMasks instance with length of n.
  
      Returns:
          :obj:`HorizontalBoxes`: Converted boxes with shape of (n, 4).
      """
      num_masks = len(masks)
      boxes = np.zeros((num_masks, 4), dtype=np.float32)
      if isinstance(masks, BitmapMasks):
          x_any = masks.masks.any(axis=1)
          y_any = masks.masks.any(axis=2)
          for idx in range(num_masks):
              x = np.where(x_any[idx, :])[0]
              y = np.where(y_any[idx, :])[0]
              if len(x) > 0 and len(y) > 0:
                  # use +1 for x_max and y_max so that the right and bottom
                  # boundary of instance masks are fully included by the box
                  boxes[idx, :] = np.array(
                      [x[0], y[0], x[-1] + 1, y[-1] + 1],
                      dtype=np.float32,
                  )
      elif isinstance(masks, PolygonMasks):
          for idx, poly_per_obj in enumerate(masks.masks):
              # simply use a number that is big enough for comparison with
              # coordinates
              xy_min = np.array(
                  [masks.width * 2, masks.height * 2], dtype=np.float32
              )
              xy_max = np.zeros(2, dtype=np.float32)
              for p in poly_per_obj:
                  xy = np.array(p).reshape(-1, 2).astype(np.float32)
                  xy_min = np.minimum(xy_min, np.min(xy, axis=0))
                  xy_max = np.maximum(xy_max, np.max(xy, axis=0))
              boxes[idx, :2] = xy_min
              boxes[idx, 2:] = xy_max
      else:
          raise TypeError(
              "`masks` must be `BitmapMasks`  or `PolygonMasks`, "
              f"but got {type(masks)}."
          )
      return HorizontalBoxes(boxes)
  
imports: from typing import Optional, Tuple, TypeVar, Union
  import cv2
  import numpy
  import torch
  from torch import BoolTensor, Tensor
  from mmdet.structures.mask.structures import BitmapMasks, PolygonMasks
  from .base_boxes import BaseBoxes
  from .bbox_overlaps import bbox_overlaps
  from .box_type import register_box
label_desc: Use image node_id 22 for calling the HorizontalBoxes obj's underlying member method code with example usage: obj.from_instance_masks(masks) and returns: HorizontalBoxes