Consolidate the classification augmentation base and honour the ecosystem knobs - #881
Merged
Merged
Conversation
The training RandomResizedCrop area range was hardcoded to (0.5, 1.0) and the eval resize/center-crop ratio was a per-family class attribute with no user override. - TrainConfig.scale: RandomResizedCrop area range. Accepts a float lower bound (ecosystem spelling) or an explicit (min, max). - TrainConfig.crop_pct / ValidationConfig.crop_pct: eval resize ratio. None keeps the family's native value, which is what export records, so an override is a deliberate train/val-only divergence. - Both land on the train CLI, crop_pct also on the val CLI, in both grammars, validated up front. - Registered in the augmentation spec so detection families warn that they ignore them instead of accepting them silently. Defaults are unchanged.
- forward crop_pct into the classification epoch-validation config. It was only passed to the augmented train transform, which ignores it, so train(crop_pct=...) changed nothing and best.pt was selected against the family default. - route the ViT / CLIP / SigLIP2 validator overrides through a shared _resolve_crop_pct so those families honor the value instead of silently keeping their pinned ratio. An explicit crop_pct opts SigLIP2 out of square_resize, which never center crops. - validate crop_pct in val_cmd so a bad value is a config_type_error at the boundary, not an io_error during dataset setup. - warn when a non-classification model is given crop_pct.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Opened by an agent on the maintainer's behalf. Builds on #879 (branched from it); once #879 merges this diff shrinks to the last commit.
Consolidates the classification augmentation pipeline so it has the same base as the detection recipes, and closes the remaining gaps from #870 and #878.
What changed
libreyolo/data/augment/classify.py, next to the detection recipes. The transform builder, collate and batch mixer moved there;classify_dataset.pynow only holds datasets and re-exports the old names, so every existing import path still works.ClassifyAugKnobs.from_config(config)reads and validatesscale,flip_prob,flipud,auto_augment,erasing,mixup,cutmixonce. The trainer uses it instead of a hand-writtengetattrlist. Invalid values fail at data setup, before the first epoch.flip_prob(CLI aliasfliplr) andflipuddrive the train crop; previously the flip was a fixed 0.5 andflipudwas silently ignored.flip_prob=0removes the op. Defaults reproduce the previous op list exactly.no_aug_epochsmeans the same thing for every task. The final epochs switch offauto_augment,erasing,mixupandcutmix(crop and flips stay), through the sameon_mosaic_disableandensure_mutation_reaches_workerspath detection uses forclose_mosaic. Classification family configs defaultno_aug_epochsto 0, so this is opt-in.fliplr,flipud,cutmixoptions. Task-aware alias table: on a classification model the CLImixupis the classification batch-MixUp knob (default off), on detection it is stillmixup_prob.auto_augment=noneis accepted as off.augment/spec.py): classification families now declareflip_probandflipudas used, and theno_aug_epochs/mixupnotes match the code. The "ignores these parameters" CLI warning follows.docs/classification_augmentation.md; CHANGELOG entry.What the reviewer should check
libreyolo/cli/commands/train.py:_resolve_train_taskand theparams["mixup"] = 0.0guard. This is what stops the detection default of 1.0 reaching a classifier.libreyolo/training/trainer.py:on_mosaic_disablenow handles both hook names; family overrides (YOLOX, YOLOv7, D-FINE, DEIM) are untouched.tests/unit/test_classification.py::test_transforms_default_off_is_unchangedstill pins the default op list.Verified
tests/unit -k "classif or augment or train or cli or spec or trainer or config or validator or plot": 1998 passed, 100 skipped (CPU, macOS). Newtests/unit/test_classify_augment.py(58 tests) and 12 CLI tests.epochs=2 no_aug_epochs=1 mixup=1.0 auto_augment=randaugment erasing=0.5 flipud=0.5): epoch 0 batches carry soft labels and RandAugment is in the transform; epoch 1 batches carry hard labels and the policy is gone.Not verified
persistent_workers, so the guard is a no-op there.mixup; it needs a follow-up edit.Fixes #870. Closes #878 together with #879.
Code provenance
All code in this PR is original, written for LibreYOLO. The transforms are composed from torchvision's public API (BSD-3-Clause). Knob names follow the de-facto YOLO CLI conventions as documented publicly; no third-party source code was read or adapted.
The PR appears safe to merge; the previous probability-truncation issue is fully fixed and no new actionable failure remains.
Summary
The latest changes fully address the previous MixUp/CutMix probability finding by rejecting combined probabilities above one across API, trainer, and classification CLI paths.
validate_mix_probabilitiesvalidation before batch mixing.mixupcontinues to map tomixup_prob.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Classification training options] --> B{Invocation path} B -->|CLI| C[Resolve classification task] C --> D[Validate mixup + cutmix] B -->|Python API| E[Build TrainConfig] D --> E E --> F[ClassifyAugKnobs.from_config] F --> G[Validate mixup + cutmix] G --> H[build_classify_collate] H --> I[Validate mixup + cutmix] I --> J[ClassifyBatchMixer]Reviews (2) · Last reviewed commit: "Reject mixup + cutmix above 1 instead of..."