warn and disable training resize-and-crop branch when aug_config={}#1037
warn and disable training resize-and-crop branch when aug_config={}#1037omkar-334 wants to merge 16 commits into
aug_config={}#1037Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (77%) is below the target coverage (95%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #1037 +/- ##
=======================================
Coverage 77% 77%
=======================================
Files 102 102
Lines 9104 9111 +7
=======================================
+ Hits 7037 7044 +7
Misses 2067 2067 🚀 New features to boost your workflow:
|
Borda
left a comment
There was a problem hiding this comment.
I see your point, but I'm not much in favor of adding a new argument. I would rather have aug_config=None to preserve actual structural behavior and None being the default, but enable forced reset with pasing aug_config={}.
Do you mean if |
Yes 🦝, but if you have another suggestion, happy to hear it... |
|
I originally thought of that approach itself, but there are 2 things we should consider
what do you think? |
We may move these multi-scale resize+crop to predefined augmentation, but need to check how to enforce/select which would use the receptive field size... so maybe really have these in predefined pipelines and in the model just add scaling to the model size as mandatory to not break the pre-processing
we can add some warning for people passing {}, which is use choce, not a default cc: @isaacrob |
Address PR review: replace the new do_random_crop argument with
aug_config-driven behavior, so no public knob is added.
- aug_config=None (default) and non-empty configs keep the training
resize-and-crop branch; aug_config={} drops it, with a warning.
- Remove the do_random_crop config field and the make_coco_transforms
parameters; add _resolve_do_random_crop() to derive the value from
aug_config.
- _build_train_resize_config keeps its internal do_random_crop param.
- Update tests and the aug_config docstring.
|
@Borda I removed the
|
do_random_crop option to disable training resize-and-crop branchaug_config={}
aug_config={}aug_config={}
I still see it... |
There was a problem hiding this comment.
Pull request overview
This PR adjusts the COCO training transform pipeline so that passing aug_config={} not only disables augmentation stage transforms, but also disables the resize → (random) crop → resize branch in the training resize stage (with an explicit warning), addressing cases where cropping can remove objects/defects from frame.
Changes:
- Added
do_random_crop: bool = Trueto_build_train_resize_config(...)and made it return only the direct-resize branch when disabled. - Introduced
_resolve_do_random_crop(aug_config)and used it inmake_coco_transforms*to disable the crop branch (and warn) whenaug_config == {}. - Added unit tests to validate the crop-branch removal and the forwarding of the derived decision.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/rfdetr/datasets/coco.py |
Adds do_random_crop support to the resize config builder and disables the crop branch when aug_config={} (with warning). |
src/rfdetr/datasets/aug_config.py |
Updates the aug_config={} example comment to reflect the new behavior. |
tests/datasets/test_coco.py |
Adds tests for _resolve_do_random_crop behavior, warning emission, and forwarding into _build_train_resize_config. |
tests/datasets/test_coco_resize_config.py |
Adds a test ensuring the crop transforms are absent when do_random_crop=False. |
I removed the public-facing parameter. We still need an internal flag for enabling this right... should i rename it? |
4277360 to
f7d85a6
Compare
| if aug_config == {}: | ||
| logger.warning( | ||
| "aug_config={} disables the training resize-and-crop branch in addition to all " | ||
| "augmentations; images will not be randomly cropped. Pass aug_config=None to keep " | ||
| "the default resize pipeline." | ||
| ) |
|
@Borda what do you think about the changes i made |
a bit busy with next release, but will check when I have a moment... 🦝 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
src/rfdetr/datasets/coco.py:478
- With
aug_config={},_crop_branch_enabledlogs a warning andAlbumentationsWrapper.from_config(resolved_aug_config)will also emit the existing "Empty augmentation config provided" warning (becauseresolved_aug_configis{}). Consider skipping thefrom_configcall (or otherwise suppressing that warning) when the resolved augmentation config is empty, so users only get the intentional new warning.
if image_set == "train":
resolved_aug_config = aug_config if aug_config is not None else AUG_CONFIG
include_crop_branch = _crop_branch_enabled(aug_config)
resize_wrappers = AlbumentationsWrapper.from_config(
_build_train_resize_config(scales, square=False, max_size=1333, include_crop_branch=include_crop_branch)
)
pipeline = [*resize_wrappers]
if not gpu_postprocess:
aug_wrappers = AlbumentationsWrapper.from_config(resolved_aug_config)
pipeline += [*aug_wrappers]
src/rfdetr/datasets/coco.py:566
- Same as
make_coco_transforms: withaug_config={},_crop_branch_enabledlogs a warning andAlbumentationsWrapper.from_config(resolved_aug_config)will also warn that the augmentation config is empty. Consider skipping thefrom_configcall whenresolved_aug_configis empty to avoid duplicate warnings.
if image_set == "train":
resolved_aug_config = aug_config if aug_config is not None else AUG_CONFIG
include_crop_branch = _crop_branch_enabled(aug_config)
resize_wrappers = AlbumentationsWrapper.from_config(
_build_train_resize_config(scales, square=True, include_crop_branch=include_crop_branch)
)
pipeline = [*resize_wrappers]
if not gpu_postprocess:
aug_wrappers = AlbumentationsWrapper.from_config(resolved_aug_config)
pipeline += [*aug_wrappers]
| if image_set == "train": | ||
| resolved_aug_config = aug_config if aug_config is not None else AUG_CONFIG | ||
| include_crop_branch = _crop_branch_enabled(aug_config) | ||
| resize_wrappers = AlbumentationsWrapper.from_config( | ||
| _build_train_resize_config(scales, square=False, max_size=1333) | ||
| _build_train_resize_config(scales, square=False, max_size=1333, include_crop_branch=include_crop_branch) | ||
| ) |
Is the internal param/arg needed? |
Co-authored-by: Codex <codex@openai.com>
| model.train(dataset_dir="path/to/dataset", aug_config={}) | ||
| ``` | ||
|
|
||
| Passing `{}` also drops the training resize-and-crop branch, so images are resized |
| def _build_train_resize_config( | ||
| scales: List[int], | ||
| *, | ||
| square: bool, | ||
| max_size: Optional[int] = None, | ||
| disable_augmentations: bool = False, | ||
| ) -> List[Dict[str, Any]]: |
- Add `scale_jitter: bool = True` to `TrainConfig` — independent control for the resize→crop→resize branch (Option B) in the training pipeline; `aug_config` now governs the augmentation stack only
- Rename `disable_augmentations` → `disable_scale_jitter` in `_build_train_resize_config`; remove `_augmentations_disabled()` helper that coupled the two concerns
- Propagate `scale_jitter` through `build_coco`, `build_roboflow_from_coco`, `o365.py`, `yolo.py` (fixes previously unreachable O365 crop-disable path)
- Replace `TestAugConfigDisablesCrop` with `TestScaleJitter`; add square-variant forwarding test and regression asserting `aug_config={}` no longer affects the crop branch
- Delete `src/rfdetr/datasets/aug_config.py` (file renamed to `aug_configs.py` earlier); fix residual `aug_config` import paths in kornia_transforms, module_data, tests, notebooks
- Update docs (advanced.md, augmentations.md) to document `scale_jitter=False` as the independent crop-branch control
---
Co-authored-by: Claude Code <noreply@anthropic.com>
Title: warn and disable training resize-and-crop branch when
aug_config={}What does this PR do?
Setting
aug_config={}does not stop the default random resize-and-crop applied to training images. This is structurally correct but counter-intuitive:aug_configand the resize/crop logic live in two separate stages of the training pipeline, andaug_configonly controls one of them.In
make_coco_transforms(src/rfdetr/datasets/coco.py), the training pipeline composes two stages:_build_train_resize_config(...). It hard-codes aOneOfbetween:SmallestMaxSize([400, 500, 600]), thenRandomCrop/RandomSizedCrop, then resize to the target scale.aug_config(color jitter, flips, rotations, etc.).aug_config={}zeroes out stage 2 only. Stage 1 still runs, and theRandomCrop/RandomSizedCropinside Option B is what clips whole objects out of frame in the reported defect-detection setup.How this PR fixes it
aug_configbecomes the single knob that also governs the stage 1 crop branch. No new argument or config field is added.aug_configNone(default)AUG_CONFIGpreset{}Noneis unchanged from current behavior. The only behavior change is{}: it already meant "no augmentations", and it now also drops the resize-and-crop branch so training uses direct resize only. A warning is logged on{}so the change is not silent.Implementation:
_crop_branch_enabled(aug_config)mapsaug_configto a boolean and owns the{}warning._build_train_resize_config(..., include_crop_branch: bool)stays a pure config builder. Wheninclude_crop_branch=Falseit returns Option A only, dropping the resize, crop, resize branch.make_coco_transformsandmake_coco_transforms_square_div_64deriveinclude_crop_branchfromaug_configvia_crop_branch_enabledand forward it.Fixes #1034
Usage
Type of Change
Testing
Test details:
tests/datasets/test_coco.py::TestAugConfigDisablesCroptest_crop_branch_enabled(parametrized overNone/{}/ non-empty) checks_crop_branch_enabledmapsaug_configto the right decision.test_empty_aug_config_warnschecksaug_config={}logs a warning.test_make_coco_transforms_forwards_crop_decisionchecksmake_coco_transformsforwards the derived value to_build_train_resize_config.tests/datasets/test_coco_resize_config.py::TestBuildTrainResizeConfigCropBranch::test_include_crop_branch_false_drops_crop_branch(parametrized over square / non-square) checksRandomCrop/RandomSizedCropare absent wheninclude_crop_branch=False.Existing characterization tests in
TestBuildTrainResizeConfigStructurecover the default kept-branch case.Checklist