
Partition or Re-stratify an Existing YOLO Dataset
Source:R/utils_yolo_dataset.R
yolo_dataset_split.Rdyolo_dataset_split() takes any YOLO dataset (flat or previously partitioned)
and redistributes all images and matching .txt labels into new train/, val/,
and optionally test/ splits. It ensures that pairs are preserved and regenerates
an updated data.yaml.
For object detection and segmentation datasets, setting stratify = TRUE (default)
applies multi-label iterative stratification (Sechidis et al.) to ensure that rare and
minority classes maintain exact representative proportions across all splits, preventing
zero-instance validation splits.
Usage
yolo_dataset_split(
data,
out_dir = "split_yolo_dataset",
split = c(train = 0.7, val = 0.2, test = 0.1),
stratify = TRUE,
seed = 42,
copy = TRUE,
overwrite = FALSE,
verbose = TRUE
)Arguments
- data
A
yolo_datasetobject,yolo_dataset_clsobject, or directory path.- out_dir
Output directory path for the re-split dataset. Defaults to
"split_yolo_dataset".- split
Proportions for partitioning (default:
c(train = 0.70, val = 0.20, test = 0.10)).- stratify
Logical. If
TRUE(default), applies multi-label iterative stratification to ensure balanced class distributions across all splits.- seed
Optional random seed for reproducible shuffling (default: 42).
- copy
Logical. Whether to copy files. Defaults to
TRUE.- overwrite
Logical. Overwrite existing
out_dir. Defaults toFALSE.- verbose
Logical. Whether to show progress. Defaults to
TRUE.