Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:APIJSON APIJSON Demo COCO Dataset Generation

From Leeroopedia
Knowledge Sources
Domains Computer_Vision, Data_Pipeline, Dataset
Last Updated 2026-10-14 00:00 GMT

Overview

Data pipeline pattern that transforms structured JSON data (from APIJSON queries) into COCO-format computer vision datasets for tasks including detection, segmentation, pose estimation, and OCR.

Description

COCO Dataset Generation bridges APIJSON's JSON-based data querying and the computer vision training ecosystem. Raw data (image metadata, annotation bounding boxes, polygons, keypoints) stored in database tables is queried via APIJSON, then transformed into the standard COCO JSON format that CV training frameworks (YOLO, Detectron2, MMDetection) consume.

This solves:

  • Format conversion: CV tools expect COCO format; APIJSON returns generic JSON. The generator handles the structural transformation.
  • Multi-task support: A single data source can generate datasets for detection, segmentation, pose keypoints, OCR, and rotated detection — each with task-specific annotation structures.
  • Train/val splitting: The generator supports part parameter for train/val dataset separation.

The COCO format structure includes:

  • info: Dataset metadata (description, version, year, date_created)
  • licenses: License information
  • images: Image entries (id, file_name, width, height)
  • annotations: Per-image annotations (varies by task type)
  • categories: Class definitions (with keypoint definitions for pose tasks)

Usage

Use this principle when:

  • Building a data pipeline from database-stored annotations to CV training datasets.
  • You need to generate COCO-format datasets for multiple CV tasks from one data source.
  • Training data is managed via APIJSON queries and needs to be exported in standard CV format.

Theoretical Basis

COCO Dataset Structure:
{
    "info": { description, version, year, date_created },
    "licenses": [...],
    "images": [
        { id, file_name, width, height }
    ],
    "annotations": [
        // Detection: { id, image_id, category_id, bbox: [x,y,w,h], area, segmentation }
        // Keypoints: { ..., keypoints: [x,y,v, ...], num_keypoints }
        // OCR: { ..., attributes: { transcription, legible } }
    ],
    "categories": [
        { id, name, supercategory }
        // Keypoint categories also have: keypoints, skeleton
    ]
}

Task Types → Annotation Structures:
    DETECTION        → bbox, area
    SEGMENTATION     → bbox, area, segmentation (polygons)
    POSE_KEYPOINTS   → bbox, area, keypoints, num_keypoints
    OCR              → bbox, area, segmentation, attributes
    ROTATED_DETECTION→ bbox, area, segmentation (4-point rotated)

Builder pattern for dataset construction:

DatasetBuilder builder = new DatasetBuilder()
    .withInfo("My Dataset", "1.0", "2025")
    .withCategory(1, "person", "person")
    .withKeypointCategory(1, "person", "person",
        Arrays.asList("nose", "left_eye", "right_eye"),
        Arrays.asList(Arrays.asList(1,2), Arrays.asList(1,3))
    )
    .addImage("00001.jpg", 640, 480, "http://example.com/img.jpg")
    .addAnnotation(detAnn);

CocoDataset dataset = builder.build();
writeToFile(dataset, "output/annotations/instances_det.json");

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment