Dataset formats for training

Mayaku reads two dataset formats:

Mayaku reads the files you have directly. There is no conversion step and no cache to build.

COCO JSON

A split is a pair: an annotation JSON file and the image directory its file_name entries are relative to.

Python
train(
    train_annotations="data/train/_annotations.coco.json",
    train_images="data/train",
    val_annotations="data/valid/_annotations.coco.json",
    val_images="data/valid",
    weights="mayaku-n-det",
)

The JSON file and the images do not have to share a directory. Each image path is os.path.join(images, file_name).

Fields Mayaku reads

JSON
{
  "images": [
    {"id": 1, "file_name": "img_0001.jpg", "height": 480, "width": 640}
  ],
  "annotations": [
    {
      "id": 10,
      "image_id": 1,
      "category_id": 1,
      "bbox": [100.0, 120.0, 50.0, 80.0],
      "iscrowd": 0,
      "segmentation": [[100, 120, 150, 120, 150, 200, 100, 200]],
      "keypoints": [110, 130, 2, 140, 130, 2, 125, 195, 1],
      "num_keypoints": 3
    }
  ],
  "categories": [
    {"id": 1, "name": "widget", "keypoints": ["left_top", "right_top", "bottom"]}
  ]
}
Field Required Used for
images[].id, file_name, height, width Always Image lookup. height and width choose the input size before any image is read, so they must match the files.
annotations[].image_id, category_id, bbox Always Boxes. bbox is [x, y, width, height] in pixels, from the top-left corner.
annotations[].iscrowd Optional 1 marks a crowd region. It is not trained on. Missing means 0.
annotations[].segmentation Segmentation, oriented boxes Polygons ([[x1, y1, x2, y2, ...], ...]) or an RLE dict.
annotations[].id, keypoints, num_keypoints Keypoints keypoints is [x1, y1, v1, x2, y2, v2, ...].
categories[].id, name Always Classes.
categories[].keypoints Keypoints, optional Keypoint names. They give the left/right pairs that are swapped when an image is flipped.

Mayaku ignores every other field (area, info, licenses, skeleton, supercategory and so on).

Classes

What is skipped

Images are read with OpenCV, so any format OpenCV decodes works: JPEG, PNG, BMP, WebP, TIFF and others.

Instance segmentation masks

Set by each annotation's segmentation:

An annotation without a segmentation still trains its box, but has no mask to learn from. See Instance segmentation.

Keypoints

See Keypoint detection.

Oriented boxes

Oriented-box models learn from each object's polygon in segmentation. The training target is the smallest rotated rectangle around the polygon. An object without a polygon trains as its axis-aligned bbox at angle 0. See Oriented boxes.

Class folders

Text only
data/
├── train/
│   ├── cat/
│   │   ├── 0001.jpg
│   │   └── ...
│   └── dog/
│       └── ...
└── val/
    ├── cat/
    └── dog/

This is the layout torchvision.datasets.ImageFolder reads. See Image classification.

Health check

mayaku.health_check scans one COCO split the way training reads it and returns a plain dict:

Python
import mayaku

report = mayaku.health_check("data/train/_annotations.coco.json", "data/train")
Python
{
    "images": 1200,
    "boxes": 8450,
    "classes": 3,
    "canvas": [672, 896],               # the input size training would use (H, W)
    "boxes_per_image": 7.04,
    "object_size": {"small": 0.41, "medium": 0.47, "large": 0.12},
    "aspect_ratio": {"p10": 0.48, "median": 1.02, "p90": 2.1},   # box width / height
    "class_imbalance": 6.3,             # most / least common class, by images containing it
    "class_counts": {"bolt": 1100, "nut": 950, "washer": 175},   # images containing each class
    "warnings": ["12 images with no annotations"],
}

The health check reads boxes only. It does not inspect masks or keypoints, and it does not read class-folder datasets.