MCPcopy Create free account
hub / github.com/PeizeSun/SparseR-CNN / load_crowdhuman_json

Function load_crowdhuman_json

detectron2/data/datasets/crowdhuman.py:28–198  ·  view source on GitHub ↗

Load a json file with COCO's instances annotation format. Currently supports instance detection, instance segmentation, and person keypoints annotations. Args: json_file (str): full path to the json file in COCO instances annotation format. image_root (str or path-l

(json_file, image_root, dataset_name=None, extra_annotation_keys=None)

Source from the content-addressed store, hash-verified

26
27
28def load_crowdhuman_json(json_file, image_root, dataset_name=None, extra_annotation_keys=None):
29 """
30 Load a json file with COCO's instances annotation format.
31 Currently supports instance detection, instance segmentation,
32 and person keypoints annotations.
33
34 Args:
35 json_file (str): full path to the json file in COCO instances annotation format.
36 image_root (str or path-like): the directory where the images in this json file exists.
37 dataset_name (str): the name of the dataset (e.g., coco_2017_train).
38 If provided, this function will also put "thing_classes" into
39 the metadata associated with this dataset.
40 extra_annotation_keys (list[str]): list of per-annotation keys that should also be
41 loaded into the dataset dict (besides "iscrowd", "bbox", "keypoints",
42 "category_id", "segmentation"). The values for these keys will be returned as-is.
43 For example, the densepose annotations are loaded in this way.
44
45 Returns:
46 list[dict]: a list of dicts in Detectron2 standard dataset dicts format. (See
47 `Using Custom Datasets </tutorials/datasets.html>`_ )
48
49 Notes:
50 1. This function does not read the image files.
51 The results do not have the "image" field.
52 """
53 from pycocotools.coco import COCO
54
55 timer = Timer()
56 json_file = PathManager.get_local_path(json_file)
57 with contextlib.redirect_stdout(io.StringIO()):
58 coco_api = COCO(json_file)
59 if timer.seconds() > 1:
60 logger.info("Loading {} takes {:.2f} seconds.".format(json_file, timer.seconds()))
61
62 id_map = None
63 if dataset_name is not None:
64 meta = MetadataCatalog.get(dataset_name)
65 cat_ids = sorted(coco_api.getCatIds())
66 cats = coco_api.loadCats(cat_ids)
67 # The categories in a custom json file may not be sorted.
68 thing_classes = [c["name"] for c in sorted(cats, key=lambda x: x["id"])]
69 meta.thing_classes = thing_classes
70
71 # In COCO, certain category ids are artificially removed,
72 # and by convention they are always ignored.
73 # We deal with COCO's id issue and translate
74 # the category ids to contiguous ids in [0, 80).
75
76 # It works by looking at the "categories" field in the json, therefore
77 # if users' own json also have incontiguous ids, we'll
78 # apply this mapping as well but print a warning.
79 if not (min(cat_ids) == 1 and max(cat_ids) == len(cat_ids)):
80 if "coco" not in dataset_name:
81 logger.warning(
82 """
83Category ids in annotations are not in [1, #categories]! We'll apply a mapping for you.
84"""
85 )

Callers 3

mot.pyFile · 0.85
crowdhuman.pyFile · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected