
Comprehensive YOLO Dataset Health Audit and Auto-Repair
Source:R/utils_yolo_dataset.R
yolo_dataset_audit.Rdyolo_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.txtannotations to the best-matching file based on modification timestamps.Clamps out-of-bounds coordinates to
[0, 1].Prunes zero-area bounding boxes.
Creates empty
.txtbackground labels for unannotated images.Removes orphaned
.txtlabel 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_datasetobject,yolo_dataset_clsobject, or directory path.- repair
Logical. If
TRUE, automatically fixes detected issues in-place. Defaults toFALSE.- 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 (whenrepair = TRUE).details:data.framewith file-by-file diagnostic records.dataset: Underlyingyolo_datasetoryolo_dataset_clsobject.
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)
}