code: def from_coco(
      anno_file: Optional[str],
      root: Optional[str] = None,
      min_object_area: Optional[Union[int, float]] = 0,
      use_crowd: Optional[bool] = False,
  ):
      """
      Load dataset from coco format annotations. Modified from gluon cv.
      The structure of a default coco 2017 dataset looks like:
      .
      ├── annotations
      |   |── instances_val2017.json
      ├── train2017
      └── val2017
  
  
      Parameters
      ----------
      anno_file
          The path to the annotation file.
      root
          Root of the COCO folder. The default relative root folder (if set to `None`) is `anno_file/../`.
      min_object_area
          Minimum object area to consider.
      use_crowd
          Use crowd or not.
  
      Returns
      -------
      A dataframe with columns "image", "rois", and "image_attr".
      """
      # construct coco object from COCO format
      try_import_pycocotools()
      from pycocotools.coco import COCO
  
      if isinstance(anno_file, Path):
          anno_file = str(anno_file.expanduser().resolve())
      elif isinstance(anno_file, str):
          anno_file = os.path.expanduser(anno_file)
      coco = COCO(anno_file)
  
      # get data root
      if isinstance(root, Path):
          root = str(root.expanduser().resolve())
      elif isinstance(root, str):
          root = os.path.abspath(os.path.expanduser(root))
      elif root is None:
          # try to use the default coco structure
          root = os.path.join(os.path.dirname(anno_file), "..")
          logger.info(
              f"Using default root folder: {root}. Specify `root=...` if you feel it is wrong..."
          )
      else:
          raise ValueError("Unable to parse root: {}".format(root))
  
      # support prediction using data with no annotations
      # note that data with annotation can be used for prediction without any changes
      try:
          num_annotations = len(coco.getAnnIds())
      except (
          KeyError
      ):  # KeyError: 'annotations', there is no annotation entry
          num_annotations = 0
  
      # load entries
      d = {"image": [], "rois": []}
      image_ids = sorted(coco.getImgIds())
      for entry in coco.loadImgs(image_ids):
          if "coco_url" in entry:
              dirname, filename = entry["coco_url"].split("/")[-2:]
              abs_path = os.path.join(root, dirname, filename)
          else:
              abs_path = os.path.join(root, entry["file_name"])
          if not os.path.exists(abs_path):
              logger.warning(
                  f"File skipped since not exists: {abs_path}."
              )
              continue
          rois, _ = _check_load_coco_bbox(
              coco,
              entry,
              min_object_area=min_object_area,
              use_crowd=use_crowd,
          )
          if not rois:
              # discard the rows without valid annotation ONLY when data has annotation
              # add default placeholder to data without annotation for prediction
              if not num_annotations:
                  d["image"].append(abs_path)
                  d["rois"].append(
                      [[-1, -1, -1, -1, 0]]
                  )  # TODO: maybe remove this placeholder
              continue
          d["image"].append(abs_path)
          d["rois"].append(rois)
      df = pd.DataFrame(d)
      df["label"] = df.loc[:, "rois"].copy()
      return df.sort_values("image").reset_index(drop=True)
  
imports: import json
  import logging
  import os
  import warnings
  from pathlib import Path
  from typing import Dict, Iterable, List, Optional, Union
  import defusedxml.ElementTree
  import numpy
  import pandas
  import PIL
  from torchmetrics.detection.mean_ap import MeanAveragePrecision
  from ..constants import BBOX, LABEL, MAP, MAP_50, MAP_75, MAP_LARGE, MAP_MEDIUM, MAP_SMALL, MAR_1, MAR_10, MAR_100, MAR_LARGE, MAR_MEDIUM, MAR_SMALL, MEAN_AVERAGE_PRECISION
  from .download import download, is_url
label_desc: Use image node_id 17 for calling a global function with example usage: from_coco(anno_file, root, min_object_area, use_crowd) and returns: df