class_docstr: Implements a text detection dataset
  
  >>> from doctr.datasets import DetectionDataset
  >>> train_set = DetectionDataset(img_folder="/path/to/images",
  >>>                              label_path="/path/to/labels.json")
  >>> img, target = train_set[0]
  
  Args:
  ----
      img_folder: folder with all the images of the dataset
      label_path: path to the annotations of each image
      use_polygons: whether polygons should be considered as rotated bounding box (instead of straight ones)
      **kwargs: keyword arguments from `AbstractDataset`.
docstr: Format polygons into an array
  
  Args:
  ----
      polygons: the bounding boxes
      use_polygons: whether polygons should be considered as rotated bounding box (instead of straight ones)
      np_dtype: dtype of array
  
  Returns:
  -------
      geoms: bounding boxes as np array
      polygons_classes: list of classes for each bounding box
code: def format_polygons(
      self,
      polygons: Union[List, Dict],
      use_polygons: bool,
      np_dtype: Type,
  ) -> Tuple[np.ndarray, List[str]]:
      """Format polygons into an array
  
      Args:
      ----
          polygons: the bounding boxes
          use_polygons: whether polygons should be considered as rotated bounding box (instead of straight ones)
          np_dtype: dtype of array
  
      Returns:
      -------
          geoms: bounding boxes as np array
          polygons_classes: list of classes for each bounding box
      """
      if isinstance(polygons, list):
          self._class_names += [CLASS_NAME]
          polygons_classes = [CLASS_NAME for _ in polygons]
          _polygons: np.ndarray = np.asarray(polygons, dtype=np_dtype)
      elif isinstance(polygons, dict):
          self._class_names += list(polygons.keys())
          polygons_classes = [k for k, v in polygons.items() for _ in v]
          _polygons = np.concatenate(
              [
                  np.asarray(poly, dtype=np_dtype)
                  for poly in polygons.values()
                  if poly
              ],
              axis=0,
          )
      else:
          raise TypeError(
              f"polygons should be a dictionary or list, it was {type(polygons)}"
          )
      geoms = (
          _polygons
          if use_polygons
          else np.concatenate(
              (_polygons.min(axis=1), _polygons.max(axis=1)), axis=1
          )
      )
      return geoms, polygons_classes
  
file_path: doctr/doctr/datasets/detection.py
imports: import json
  import os
  from typing import Any, Dict, List, Tuple, Type, Union
  import numpy
  from doctr.file_utils import CLASS_NAME
  from .datasets import AbstractDataset
  from .utils import pre_transform_multiclass
label_desc: Use image node_id 2 for calling the DetectionDataset obj's underlying member method code with example usage: obj.format_polygons(polygons, use_polygons, np_dtype) and returns: geoms,  polygons_classes