Train Kfold YOLO
Overview
Splits the labelled images of a dataset into K folds and trains K YOLO detectors. Each detector trains on K-1 folds with the original labels and then predicts the fold it did not see, so every image gets predictions from a detector that never trained on it. These held-out (“out of fold”) predictions are the input of Kfold label check, which compares them with the labels to find suspicious labels and to measure how hard the dataset is to learn.
Images that are copies of one another are kept in the same fold, so no detector is tested on a picture it has seen in another form. Without that, the held-out predictions of a dataset with copies look better than they are.
The trained models are not kept: nothing is registered as a model and the checkpoints are deleted when a fold finishes. The report is updated after every fold, and its REPORT_ID output is set when the first fold starts. If a fold fails, the node fails; the folds that finished stay in the report. There is no resume.
Prerequisites
How it works
Loads the weights of Model and exports the dataset in YOLO format with its original labels, keeps one box of every object labelled twice (same class, IoU above 0.9), and reads the class list from the export. The class order of the export is the class order of oof.parquet.
Reads the copy groups of the connected reports: pixel copies (copy_groups.parquet, group id), file-name groups of Find copies (name group) and near copies of Similar pairs (duplicate_groups.parquet).
Merges the groups, then assigns whole groups to folds, heaviest first, to the fold with the least load among the images of the same split and the same value of the first tag that has 2 to 50 values. If the largest merged group holds more than a 2K-th of the images, the near-copy edges and then the file-name edges are dropped; pixel copies are never dropped. Above Largest number of images, whole groups are sampled, stratified by split, and the other images get no held-out predictions.
For each fold, trains a copy of the model (its network rebuilt for the dataset’s classes) on the images of the other folds for a fixed number of epochs, with validation off and the last weights kept, so a held-out image never influences the model that predicts it. Then predicts the held-out images at score 0.01 and above, at most 300 boxes per image, and adds them to oof.parquet.
Inputs
Dataset to train on, with its original labels. Every labelled image is held out by exactly one model. The split of an image is read from its split tag and only used to keep the folds balanced. Key: DATASET.
Reports of Find copies and Similar pairs. Images they put in one group are kept 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 DATASET. Key: COPY_REPORT_IDS.
Turn off to skip training. The node then completes with a report saying it was off. Key: ENABLED.
Detection model every fold starts from, trained in this workspace or installed from the zoo. YOLO26 small at image size 1024 finds the dataset’s problems about as well as medium or large and fits an 8 GB GPU with room to spare. Each fold trains a copy of it on the other folds, no version is registered. Key: MODEL.
Number of folds. Each model trains on the other K-1 folds, so a larger K means a model closer to one trained on everything, and more training time. Minimum: 3. Maximum: 10. Step: 1. Key: K.
Training epochs of every fold. The last weights are used, with no validation, so a held-out image never influences the model that predicts it. Minimum: 1. Maximum: 300. Step: 1. Key: EPOCHS.
Above this many labelled images, whole groups of images are sampled (stratified by split) and the rest get no held-out predictions. The report says how many were left out. Minimum: 20. Maximum: 100000. Step: 100. Key: MAX_IMAGES.
Training and prediction image size in pixels. Minimum: 32. Maximum: 2048. Step: 32. Key: IMAGE_SIZE.
auto is 4 for YOLO26 small, 2 for YOLO26 medium and large and 4 for any other model, sized for an 8 GB GPU at image size 1024, on a CUDA out-of-memory error the batch is halved, down to 2, and the fold restarts. Or a whole number. Key: BATCH.
Outputs
Held-out predictions (oof.parquet), the fold of every image (folds.parquet), kfold_meta.json, per-fold progress, and findings.json. Updated after every fold while the node runs. Shown as an artifact. Key: REPORT_ID.
How many folds finished, for example “4 folds”. Shown on the node as a badge. Key: FOLDS_TRAINED.
Report
The report holds index.md (the settings, a table with the state, timing and GPU peak of every fold, and how images were grouped), and the files Kfold label check reads:
oof.parquet: one row per held-out box. Columnsasset_id,fold,cls(position in the class list),x1,y1,x2,y2(pixels of the original image) andscore. Grows by one fold at a time.folds.parquet:asset_id, split, fold, groupfor every image in the folds.kfold_meta.json:k,classes(names in the order ofcls), the model, epochs, image size and batch used, which grouping sources were used and what the guard dropped, how many images were left out, notes on the inputs (among them how many duplicate boxes were left out of training), the timing and GPU peak of each fold, and the Ultralytics version.fold_progress.json: the state of each fold while the node runs.findings.json: one observation,kfold.trained, with the number of images that have held-out predictions and the number of labelled images.
The report asset carries the tag kind: kfold_oof_v1.
JSON config
Machine-readable node interface for automation and advanced usage.