tlc.core.export.exporters.coco

Exporter for the COCO format.

Module Contents

Classes

Class

Description

COCOExporter

Exporter for the COCO format.

Functions

Function

Description

parse_include_segmentation_arg

API

parse_include_segmentation_arg(
include_segmentation: bool | str | None,
) bool | None
class COCOExporter

Bases: tlc.core.export.exporter.Exporter

Exporter for the COCO format.

Tables which are originally instances of the TableFromCoco class will be compatible with this exporter.

supported_format = coco
priority = 3
classmethod can_export(
table: Table,
output_url: Url,
) bool

Check if the table can be exported to the COCO format.

Can not be 100% accurate, as we don’t know if the user has supplied additional arguments, such as annotation_column_name, or image_column_name.

classmethod serialize(
table: Table,
output_url: Url,
weight_threshold: float = 0.0,
image_folder: Url | str = '',
absolute_image_paths: bool = False,
include_segmentation: bool | None = None,
annotation_column_name: str | None = None,
image_column_name: str | None = None,
indent: int = 4,
**kwargs: Any,
) str

Serialize a table to the COCO format.

Default behavior is to write a COCO file with image paths relative to the (output) annotations file. Written paths can be further configured with the absolute_image_paths and image_folder argument.

Note that for a coco file to be valid, the image paths should be absolute or relative w.r.t. the annotations file itself.

Parameters:
  • table – The table to serialize

  • output_url – The output URL

  • weight_threshold – The weight threshold

  • image_folder – Make image paths relative to a specific folder. Note that this may produce an annotations file that needs special handling. This option is mutually exclusive with absolute_image_paths.

  • absolute_image_paths – Make image paths absolute. If this is set to True, the image_folder cannot be set.

  • include_segmentation – Whether to include segmentation in the exported COCO file. If this flag is True, segmentation poly-lines will be generated directly from the bounding box annotations. If this flag is False, no segmentations are written. If this flag is None, segmentation info will be copied directly from the input Table.

  • annotation_column_name – Optional column name to use for annotations instead of the defaults (bbs, segmentations, or keypoints_2d). The content of the column determines the annotation mode (bounding boxes, segmentations, or keypoints) based on its structure.

  • image_column_name – Optional column name to use for image URLs. Defaults to image.

  • indent – The number of spaces to use for indentation in the output.

  • kwargs – Any additional arguments

Returns:

The serialized table