Skip to contents

yolo_dataset_dedup() computes ultrarrápido 64-bit Perceptual Difference Hashes (dHash) using native OpenMP C++ to identify near-duplicate images within and across YOLO dataset splits.

Crucially, it detects Cross-Split Data Leakage (where near-identical frames or drone photos leak between train/ and val/ or test/), which artificially inflates validation metrics (mAP).

Usage

yolo_dataset_dedup(
  data,
  threshold = 4L,
  action = c("report", "quarantine", "remove"),
  check_leakage = TRUE,
  target_split = c("val", "test", "train", "both"),
  quarantine_dir = NULL,
  num_threads = 0L,
  verbose = TRUE
)

yolo_dataset_deduplicate(
  data,
  threshold = 4L,
  action = c("report", "quarantine", "remove"),
  check_leakage = TRUE,
  target_split = c("val", "test", "train", "both"),
  quarantine_dir = NULL,
  num_threads = 0L,
  verbose = TRUE
)

Arguments

data

A yolo_dataset object or directory path.

threshold

Integer (0-64). Maximum Hamming distance to consider two images as near-duplicates (default: 4L, corresponding to \(\ge 93.8\%\) perceptual visual similarity). Distance 0 denotes exact duplicates.

action

Action to execute: "report" (default, displays analysis without altering files), "quarantine" (moves leaking or duplicate images and labels to a separate directory), or "remove" (deletes duplicate/leaking files from the target split).

check_leakage

Logical. Whether to inspect and flag cross-split leakage (train vs val/test). Defaults to TRUE.

target_split

Character specifying which split to act upon when action = "quarantine" or "remove": "val" (default, cleans validation leaks preserving train), "test", "train", or "both".

quarantine_dir

Optional directory path for quarantined files. Defaults to <dataset>/quarantine.

num_threads

Integer. Number of OpenMP threads for C++ execution (default: 0L, auto-detect all CPU cores).

verbose

Logical. Whether to show progress messages (default: TRUE).

Value

An invisible list containing leaks (data frame of cross-split leaks), duplicates (data frame of in-split duplicates), and hashes (named character vector of 64-bit hexadecimal hashes).

Examples

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

# 1. Inspect dataset for duplicates and cross-split leakage
res <- yolo_dataset_dedup("my_dataset")

# 2. Quarantine near-duplicate validation images leaking from train
yolo_dataset_dedup("my_dataset", action = "quarantine")
}