Skip to contents

yolo_dataset_audit() conducts a deep structural, syntactic, and geometric health check on any YOLO dataset (Detection, Instance Segmentation, or Image Classification). It detects duplicate file stems across extensions (stem collisions, e.g. foo.jpg and foo.png colliding on foo.txt), orphaned images/labels, corrupt files, invalid coordinates (< 0 or > 1), negative bounding box dimensions, malformed polygons, class index out-of-bounds, and severe class imbalance.

With repair = TRUE, it automatically repairs the dataset in-place:

  • Relocates misplaced label files when images are moved across splits (e.g. from train to val) to preserve annotations.

  • Renames colliding images and review previews uniquely (foo_jpg.jpg, foo_png.png) and links existing .txt annotations to the best-matching file based on modification timestamps.

  • Clamps out-of-bounds coordinates to [0, 1].

  • Prunes zero-area bounding boxes.

  • Creates empty .txt background labels for unannotated images.

  • Removes orphaned .txt label files.

The returned object wraps the audited dataset seamlessly so it can be chained directly with the pipe operator |> into yolo_train() or yolo_dataset_augment().

Usage

yolo_dataset_audit(
  data,
  repair = FALSE,
  min_images = 10L,
  check_leakage = TRUE,
  leak_threshold = 4L,
  verbose = TRUE
)

Arguments

data

A yolo_dataset object, yolo_dataset_cls object, or directory path.

repair

Logical. If TRUE, automatically fixes detected issues in-place. Defaults to FALSE.

min_images

Integer threshold for warning if a class has few samples. Defaults to 10L.

check_leakage

Logical. Whether to check for near-duplicate / leaky images across splits using perceptual hashing. Defaults to TRUE.

leak_threshold

Integer Hamming distance threshold for flagging near-duplicate images across splits. Defaults to 4L.

verbose

Logical. Whether to display progress and diagnostic alerts. Defaults to TRUE.

Value

An object of class c("yolo_dataset_audit", "yolo_dataset", "list") containing:

  • dir: Root directory of the dataset.

  • is_healthy: Logical indicator of dataset health.

  • issues_found: Total count of issues detected.

  • issues_repaired: Count of issues successfully fixed (when repair = TRUE).

  • details: data.frame with file-by-file diagnostic records.

  • dataset: Underlying yolo_dataset or yolo_dataset_cls object.

Author

Tiago Olivoto tiagoolivoto@gmail.com

Examples

if (FALSE) { # interactive()
library(pliman)

# Audit a YOLO dataset and automatically fix issues
ds_clean <- yolo_dataset_audit("dataset_cafe", repair = TRUE)

# Pipe directly into training!
ds_clean |> yolo_train(model = "yolo26n-seg", epochs = 50)
}