tlc.integration.detectron2.register_coco_instances#

A drop-in replacement for detectron2.data.datasets.register_coco_instances

Module Contents#

Functions#

Function

Description

register_coco_instances

Register a COCO dataset in Detectron2’s standard format.

API#

tlc.integration.detectron2.register_coco_instances.register_coco_instances(name: str, metadata: dict, json_file: str, image_root: str | None, revision_url: str = '', project_name: str = '') None#

Register a COCO dataset in Detectron2’s standard format.

This method works as a drop-in replacement for detectron2.data.datasets.register_coco_instances.

References:

The original function reads the json file and uses pycocoapi to construct a list of dicts which are then registered under the key name in detectron’s DatasetCatalog.

These dicts have the following format:

{
    "file_name": "COCO_train2014_000000000009.jpg",
    "height": 480,
    "width": 640,
    "image_id": 9,
    "annotations": [
        {
            "bbox": [97.84, 12.43, 424.93, 407.73],
            "bbox_mode": 1,
            "category_id": 16,
            "iscrowd": 0,
            "segmentation": [[...]]
        },
        ...
    ]
}

This function also registers a list of dicts under the key name in detectron’s DatasetCatalog, but before the data is generated, a TLCTable is resolved. The first time the function is called with a given signature, a 3LC table is created. On subsequent calls, the table replaced with the most recent descendant of the root table. If the resolved table contains a weight column, this value will be sent along in the list of dicts.

Parameters:
  • name – the name that identifies a dataset, e.g. “coco_2014_train”.

  • metadata – extra metadata associated with this dataset.

  • json_file – path to the json instance annotation file.

  • image_root – directory which contains all the images. None if the file_name contains a complete path.

  • revision_url – url to a specific revision of the table. If not provided, the latest revision will be used. If the revision is not a descendant of the initial table, an error will be raised.

Returns:

None