Kfold split
Overview
Splits a dataset into K folds and hands one fold at a time to the train and predict nodes wired after it, in a loop, so every labelled image is predicted by a model that never saw it. After the last fold it saves those held-out predictions as a report that Kfold label check reads to find labels worth a second look.
It works with any detector whose train node has the inputs Train dataset, Validation dataset, Model and Destination model and whose predict node has Dataset, Destination dataset and Model, such as Train YOLO and Predict YOLO. Copies of one image always sit in the same fold, so a model is never tested on a copy of an image it trained on.
Prerequisites
How it works
Checks the wiring of the loop and refuses to run when a held-out image could reach training, naming the node and the setting to change. It also refuses while the train or predict node has a run in progress.
Starts a new K-fold run when there is none, the last one finished and this node itself is started (started by the predict node after a finished run, it returns that run and Done stays yes), or the dataset, folds, validation share, seed or copies reports changed. Otherwise it continues the current run: the fold handed out last counts as done once the predict node has a completed run on it with the model the train node made from that fold.
On a new run, reads every image with its labels and tags, groups copies, and assigns every image of a labelled split to a fold, spreading splits and tag values over the folds. The folds are saved in the report.
Hands out the next fold as new versions of the train, validation and held-out datasets. The validation images come from the training folds, in whole copy groups, so the held-out fold never picks a checkpoint. With the first fold it also copies the train node’s starting model into a scratch model, the Fold models output, which the train node files every fold’s model under.
Inputs
Dataset to split, with its labels. Every image of a split that holds at least one object is held out by exactly one fold, an image’s split tag only keeps the folds balanced. The dataset is read when a run starts, so images added later join the next run. Key: SRC_DATASET.
Reports of Find copies and Similar pairs. Images they put in one group stay in the same fold, so a model is never tested on a copy of an image it trained on. Leave empty to group by nothing, which makes the held-out predictions look better than they are when the dataset has copies. Values come from SRC_DATASET. Key: COPY_REPORT_IDS.
Number of folds. Each model trains on the other K-1 folds, so a larger K gives models closer to one trained on everything, at the cost of K trainings. Minimum: 3. Maximum: 10. Step: 1. Key: K.
Share of each fold’s training images set aside as its validation dataset, taken from the K-1 training folds in whole copy groups. The held-out fold is never the validation dataset, so it cannot influence which checkpoint a train node keeps. Minimum: 1. Maximum: 50. Step: 1. Key: VAL_SHARE.
Most images each fold’s model trains on, empty or 0 means no limit. It bounds training time on big datasets. The training images are drawn from the K-1 training folds in whole copy groups, keeping the split shares, and the draw depends on the seed. Images left out of training are not wasted - every image is still predicted by a model that did not see it. The held-out fold is never cut, and the validation share is taken of this number, so validation stays small too. Minimum: 0. Maximum: 100000000. Step: 1. Key: MAX_TRAIN_IMAGES.
Seed of the fold assignment, of the validation pick and of the training cap. The same dataset, settings and seed give the same folds. Change it to start a new run with the same settings. Minimum: 0. Maximum: 1000000. Step: 1. Key: SEED.
Outputs
Training images of the current fold - the other K-1 folds without the validation share - with their labels. Wire it into the Train dataset of the train node. Key: TRAIN_DATASET.
Validation images of the current fold, taken from the training folds. Wire it into the Validation dataset of the train node. Key: VAL_DATASET.
Images of the current fold, which its model never trains or validates on. Wire it into the Dataset of the predict node. Key: HOLDOUT_DATASET.
Dataset every fold’s predict node writes into, so after the last fold every image holds the prediction of the model that never saw it. Wire it into the Destination dataset of the predict node. Shown as an artifact. Key: OOF_DATASET.
Model the train node registers each fold’s model under, instead of the model it fine-tunes. It is created with the run, starts with a copy of the train node’s starting version, and is deleted with all fold models once the held-out predictions are saved. Wire it into the Destination model of the train node. Key: FOLD_MODEL.
The folds of every image (folds.parquet), kfold_meta.json and progress from the first fold on, and after the last fold the held-out predictions (oof.parquet) that Kfold label check reads. Shown as an artifact. Key: REPORT_ID.
The fold handed to the train node, for example “Fold 2 of 4”, or “4 of 4 folds done”. Shown on the node as a badge. Key: FOLD.
no while folds remain, yes after the last one. Wire it into the Condition that decides whether the train node runs again. Key: DONE.
Internal state of the current K-fold run. Hidden from the flow editor. Key: RUN.
Models and configuration
Wire the loop as in the flow below. The train and predict nodes must run only after the Condition and the train node respectively, which detach: true with after sets; the node checks this and says what to change.

Recommended settings
These settings were chosen on a dense dataset (8,629 images, 457,000 boxes, 10 classes) by checking how many deliberately damaged labels the held-out predictions bring to the top of the Kfold label check lists, and for a run that fits a 12 GB GPU.
Train RF-DETR with RF-DETR Small brings more wrong-class and spurious-box findings to the top of the lists and keeps a shorter “Box badly placed” list, at about twice the training time. At 896 use batch 4 to stay within 12 GB. Replace the train and predict nodes with:
Any detector family can replace the YOLO pair. The train node must start every fold from the same weights. Any pick works, Latest included: the version it names at the first fold is recorded, and a later fold refuses to start if it names another. Its Destination model must be this node’s Fold models output, so the fold models land in a scratch model that is deleted after the last fold, not in the model you fine-tune. Set the predict node’s confidence threshold low, 0.01, because Kfold label check finds missing labels from low-scoring boxes.
The Condition is Condition with the check set to a yes/no value that is false.
Limitations and troubleshooting
What does the node check before it hands out a fold?
- One train node reads this node’s Train dataset, and its Validation dataset is this node’s Validation dataset.
- One predict node reads the Held-out dataset, writes into the Held-out predictions dataset, uses the model of that train node, runs after the train node only, and leads back to this node.
- A Condition after this node checks Done is false, and the train node runs after it only.
- The train node starts every fold from the same weights, from a model you picked, and its Destination model is this node’s Fold models output.
A fold failed. How do I continue?
Run the train node or this node again with the same settings; when only the predict node failed, run the predict node again. The loop continues with the same fold; the folds already predicted are kept. A prediction counts only when its model was trained on the fold’s training images: predicting after the fold’s training failed uses the previous fold’s model, so this node hands the same fold out again. To start over with unchanged settings, change the Seed.
Can I run the train or predict node again after the run finished?
Yes. Started on their own they lead back to this node, which returns the finished run (Done is yes) and the Condition takes its otherwise branch, so Kfold label check runs again on the same report. Starting this node itself, or a node before it that makes its dataset, begins a new K-fold run.
What happens when I change a setting during a run?
Changing the dataset, folds, validation share, seed or copies reports starts a new run. The unfinished run is left as it is.
Why does the dataset need images in a labelled split?
A split with no object at all is left out, and an image of a split that has objects is held out by exactly one fold. Videos are not folded.
Why is there one dataset per fold version?
The train, validation and held-out datasets are hidden helpers that get a new version for every fold. Only the latest version is referenced; the report holds the plan that rebuilds the others.
JSON config
Machine-readable node interface for automation and advanced usage.