Datumaro Dataset Management Framework

repository·develop·Indexed 20 days ago

https://github.com/open-edge-platform/datumaro

A comprehensive framework and CLI tool for managing computer vision datasets. Datumaro enables users to ingest, transform, and analyze data across various formats including COCO, VOC, CVAT, YOLO, and Cityscapes. It provides capabilities for merging, filtering, splitting, and converting datasets, as well as quality checking and statistics generation. The framework includes an experimental module for type-safe, declarative dataset management using Polars DataFrames.

Tokens
91.8K
Snippets
311
Records
385
Agent score
71%

What's inside Datumaro

  1. Overview of Datumaro Dataset Management Framework

    develop

    Datumaro is a framework and CLI tool designed to build, transform, and analyze datasets. It acts as a central hub for various dataset formats, allowing you to convert between them, merge multiple sources, and prepare data for model training, annotation tools, or publication.

    Core Workflow:

    1. Ingest: Read datasets from formats like COCO, VOC, CVAT, YOLO, etc.
    2. Transform: Build, filter, convert, or split datasets.
    3. Output: Export to annotation tools, model training formats, or generate statistics and publications.
  2. Overview of Datumaro features

    develop

    Datumaro is a framework and CLI tool designed for building, transforming, and analyzing datasets. It serves as a dataset storage and a debugging tool for computer vision workflows.

    Core capabilities include:

    • Dataset Management: Creating, maintaining, and version-controlling annotations and images. This includes editing, joining, splitting, and exporting datasets across various formats.
    • Dataset Building: Merging multiple datasets, filtering by custom criteria (e.g., removing specific classes, filtering by image orientation, or removing small bounding boxes), and performing annotation conversions (e.g., polygons to masks).
    • Dataset Splitting: Creating train, val, and test subsets using either random splits or task-specific splits that preserve label and attribute distributions (e.g., ensuring unique IDs in re-identification tasks).
    • Quality & Analysis: Checking for errors, comparing datasets with model inference results, validating annotations based on task type, and calculating dataset statistics (e.g., image mean/std, annotation distributions).
  3. What is the DatumaroBinary format?

    develop

    DatumaroBinary is Datumaro's native data format. It functions identically to the standard Datumaro format, but uses a binary format for annotation files instead of JSON.

    Key advantages include:

    1. Efficient storage cost: Because it is schemaless and stores data in binary form, it significantly reduces annotation file size. For example, compared to COCO (JSON), DatumaroBinary can reduce size by ~64.3%, and compared to the standard Datumaro (JSON) format, it reduces size by ~28.8%.
    2. Multi-processing support: Annotation data is stored as sharded blobs, allowing for high-performance import and export using multiple CPU cores.
  4. Manage Dataset categories and annotations

    develop

    Annotations in Datumaro (like Label, Mask, or Polygon) require context to be interpreted correctly. This context is stored in dataset.categories(), which maps an AnnotationType to a Categories class (e.g., LabelCategories, MaskCategories).

    Key Concepts:

    • LabelCategories: The 'main' type of categories. All other annotation types typically use label indices from this object.
    • Subsets: A dataset can contain multiple subsets (e.g., train, val, test), accessible via dataset.subsets().
  5. How the Datumaro Experimental Module works

    develop

    The module is built around several core abstractions that work together to manage structured data:

    • Sample: A dataclass-like definition representing a single data point.
    • Dataset: A typed container that holds multiple samples following a consistent schema.
    • Schema: The formal structure of the dataset, automatically derived from your Sample definitions.
    • Field: Type descriptors that define how specific data (like images or bounding boxes) is stored and converted.
    • Converter: Logic used to transform data between different field representations.
    • Transform: Lazy operations applied to data during retrieval.

    Note: Datasets that have undergone transformations (via convert_to_schema() or transform()) are immutable.

  6. Extend Dataset Formats with custom Extractors, Importers, and Converters

    develop

    Datumaro uses specific components to handle dataset I/O, which can be extended via plugins:

    • Extractors: Produce a list of dataset items corresponding to the dataset.
    • Importers: Load a dataset from a data source location.
    • Converters: Produce a dataset of a specific format from dataset items.

    To add custom functionality, place your Extractor, Importer, or Converter implementation scripts into a plugin directory.

  7. Pascal VOC directory structure requirements

    develop

    A valid Pascal VOC dataset for Datumaro should follow this structure:

    └─ Dataset/
       ├── dataset_meta.json # Optional: list of non-Pascal labels
       ├── labelmap.txt     # Optional: list of non-Pascal labels
       ├── Annotations/
       │   ├── ann1.xml     # Pascal VOC format annotation files
       │   └── ...
       ├── JPEGImages/
       │   ├── img1.jpg     # Image files
       │   └── ...
       ├── SegmentationClass/ # Semantic segmentation masks
       │   ├── img1.png
       │   └── ...
       ├── SegmentationObject/ # Instance segmentation masks
       │   ├── img1.png
       │   └── ...
       └── ImageSets/
            ├── Main/       # Detection/Classification subsets
            │   ├── test.txt
            │   └── train.txt
            ├── Layout/     # Person layout subsets
            ├── Action/     # Action classification subsets
            └── Segmentation/ # Segmentation subsets

    Note: ImageSets must contain at least one of Main, Layout, Action, or Segmentation directories. The .txt files inside these directories should contain image names without extensions.

  8. Check annotation groups for completeness with `--groups`

    develop

    The --groups (or -g) option allows you to verify that specific sets of labels exist together as a group in the merged dataset. This is useful for ensuring that complex objects (like a human body) have all their constituent parts (like head, hand, foot) present.

    • Labels in the list must be present in the same group.
    • Adding a ? after a label name (e.g., hand?) makes that specific part optional within the group check.

    Example: Checking for a person group with optional hands and feet:

    datum merge dataset1/ dataset2/ -m intersect -g 'person,hand?,foot?'
  9. Dataset Building and Transformation Capabilities

    develop

    Datumaro provides several tools for manipulating datasets:

    Merging and Filtering

    • Merging: Combine multiple datasets into a single unified dataset.
    • Filtering: Remove data based on custom criteria, such as:
      • Removing polygons of a specific class.
      • Removing images without annotations for a specific class.
      • Removing occluded annotations.
      • Keeping only vertically-oriented images.
      • Removing small-area bounding boxes.

    Conversions and Label Management

    • Annotation Conversion: Convert between formats like polygons and instance masks (and vice-versa).
    • Mask Manipulation: Apply custom colormaps to mask annotations.
    • Label Management: Rename or remove dataset labels.

    Dataset Splitting

    Split datasets into train, val, and test subsets using:

    • Random split.
    • Task-specific splits: Maintains initial label and attribute distributions.
      • Classification: Based on labels.
      • Detection: Based on bounding boxes (bboxes).
      • Re-identification: Based on labels, ensuring the same IDs do not appear in both training and test splits.
  10. Cityscapes format specification and directory structure

    develop

    The Cityscapes format supports Masks as annotation types. It includes an optional is_crowd (boolean) attribute; if False, the annotation id field encodes the instance ID.

    Expected Directory Structure

    A valid Cityscapes dataset directory should follow this structure:

    └─ Dataset/
        ├── dataset_meta.json # optional: list of non-Cityscapes labels
        ├── label_colors.txt # optional: list of non-Cityscapes labels in other format
        ├── leftImg8bit/
        │   ├── <split: train,val, ...>
        │   │   ├── {city1}/
        │   │   │   ├── {city1}_{seq}_{frame}_leftImg8bit.png
        │   │   └── ...
        └── gtFine/
            ├── <split: train,val, ...>
            │   ├── {city1}/
            │   │   ├── {city1}_{seq}_{frame}_gtFine_color.png
            │   │   ├── {city1}_{seq}_{frame}_gtFine_instanceIds.png
            │   │   ├── {city1}_{seq}_{frame}_gtFine_labelIds.png
            │   └── ...

    Annotated File Types

    • *_leftImg8bit.png: Left images in 8-bit LDR format.
    • *_color.png: Class labels encoded by color.
    • *_labelIds.png: Class labels encoded by index.
    • *_instanceIds.png: Class and instance labels encoded by an instance ID. The integer part of ID / 1000 provides the class ID, and the remainder is the instance ID.
  11. MMDetection COCO format specification

    develop

    The MMDetection COCO format is a variation of the standard COCO format used by the MMDetection training framework. The primary difference is that image directories are separated into subsets.

    A valid MMDetection COCO dataset directory must follow this structure:

    └─ Dataset/
        ├── <subset_name>/
        │   ├── <image_name1.ext>
        │   ├── <image_name2.ext>
        │   └── ...
        ├── <subset_name>/
        │   ├── <image_name1.ext>
        │   ├── <image_name2.ext>
        │   └── ...
        └── annotations/
            ├── instances_<subset_name>.json
            └── ...