Guide · COCO export

Export word boxes in COCO format

V2 turns canonical page annotations into a conventional COCO object record: page images, pixel-space boxes, word text, categories, and split metadata. The image and box rendition need to be read together when delivery conditions alter geometry.

Pixel-space word detection

Keep the image and its boxes from the same rendition

The V2 COCO export writes exports/coco.json with images, annotations, and categories. Each page image records its document ID, page number, split, image size, and rendition. Each word object carries text, a pixel-space [x, y, width, height] box, area, category, and iscrowd: 0.

COCO and LayoutLM use delivered pages when a run has a delivered rendition. This matters for scan transforms: the source annotation's point coordinates are scaled or transformed into the delivered image before the export is written. The record says which rendition was used.

Short example

Generate a COCO annotation file

Windows PowerShell

& '.\_internal\DocumentGenerator_v2.0_cli.exe' generate --type invoice letter --count 2 --seed 42 --scan-preset photocopy --scan-strength 50 --output output/coco-small --export coco --validate

Linux AppImage

./DocumentGenerator_v2.0.0_Linux-x86_64.AppImage --cli generate --type invoice letter --count 2 --seed 42 --scan-preset photocopy --scan-strength 50 --output output/coco-small --export coco --validate

Linux Flatpak

flatpak run com.docsetgenerator.DocSetGenerator --cli generate --type invoice letter --count 2 --seed 42 --scan-preset photocopy --scan-strength 50 --output output/coco-small --export coco --validate

A small part of the resulting structure looks like:

{
  "images": [
    {
      "id": 1,
      "file_name": "images/<document-id>/delivered/page-001.png",
      "width": 1275,
      "height": 1650,
      "document_id": "<document-id>",
      "page_number": 1,
      "split": "train",
      "image_rendition": "delivered"
    }
  ],
  "annotations": [
    {
      "id": 1,
      "image_id": 1,
      "category_id": 1,
      "bbox": [80.0, 120.0, 94.0, 28.0],
      "area": 2632.0,
      "iscrowd": 0,
      "text": "Invoice"
    }
  ],
  "categories": [{"id": 1, "name": "word"}]
}

The dimensions and coordinates above illustrate the schema. Keep each generated image with its matching JSON. If you edit the boxes, check their alignment against that image.

Categories and semantics

Use categories that came from the annotation

The exporter always has a word category and can add semantic labels present on the canonical words, such as a grounded field label. The category ID is assigned in the final file; consumers should resolve it through categories rather than assuming a numeric ID.

COCO is a pixel-space detection representation. It is not a complete document understanding schema, and it does not carry the full source-to-rendered text mapping or every business field relation. Keep the manifest and canonical annotations with the export when those relationships matter.

Rendition choices

Source and delivered images answer different questions

RenditionUse it to studyPair it with
DeliveredThe exact page appearance and geometry passed to a detector under scan or delivery conditions.Delivered image files, COCO boxes, and the manifest's condition fields.
Source / pristineCanonical authored layout and semantic geometry before delivery changes.Canonical pages and semantic exports such as FUNSD or DocVQA.

Limits

Treat COCO validation as a data check

  • --validate confirms that exported annotations refer to real images and categories. It does not train a detector or report mean average precision.
  • Word-level objects are not a promise of paragraph, table-cell, line, or logo categories for every document type.
  • Changing the delivery condition changes the image/box relationship. Do not reuse source COCO boxes against a delivered scan.
  • Generation covers all 33 types, while parser evaluation admits a narrower PDF matrix. See the OCR test guide before describing a corpus as scoreable.

Use LayoutLM for page-level tokens and normalized boxes, FUNSD-shaped records for key/value roles, and OCR training data for source, split, and corruption design.