Skip to contents

yolo_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_dataset object, yolo_dataset_cls object, 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 to FALSE.

verbose

Logical. Whether to show progress. Defaults to TRUE.

Value

A yolo_dataset object pointing to the newly split dataset.

Examples

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

# Re-stratify into 70% train, 20% validation, 10% test with iterative stratification
ds_split <- yolo_dataset_split("dataset_cafe", split = c(0.7, 0.2, 0.1), stratify = TRUE)
}