Skip to content

Refactor Object Detection Transforms#835

Merged
yutong-xiang-97 merged 3 commits into
mainfrom
yutong-trn-2271-refactor-ltdetr-object-detection-transforms
Jul 7, 2026
Merged

Refactor Object Detection Transforms#835
yutong-xiang-97 merged 3 commits into
mainfrom
yutong-trn-2271-refactor-ltdetr-object-detection-transforms

Conversation

@yutong-xiang-97

@yutong-xiang-97 yutong-xiang-97 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What has changed and why?

Refactored the LT-DETR object detection transform implementation into a shared ltdetr_transforms package with separate components for step-aware control, object detection, and utility modules. Updates all the relevant task model call sites to use the new structure while preserving the existing object detection behavior.

The new structure is split as follows:

  • ltdetr_transforms/components.py contains the reusable runtime pieces for LT-DETR-style transforms: step activation tracking, dataloader reinitialization checks, cached sample transform construction, and mosaic activation handling.
  • ltdetr_transforms/object_detection.py contains the object-detection transform and collate-function implementation, including input/output types, transform args contract, bbox normalization, degenerate-box filtering, mixup/copyblend/scale-jitter handling, and batch transform wiring.
  • ltdetr_transforms/utils.py contains helper functions for image-size resolution, activation schedules, albumentations transform ordering, bbox conversion/filtering, and normalization.

The LT-DETR task-model transform modules now define task-specific defaults close to the task models, while reusing the object-detection transform/collate implementation and the shared components.

Also refactored the unit test accordingly.

How has it been tested?

Parity verified by AI.

Did you update CHANGELOG.md?

  • Yes
  • Not needed (internal change)

Did you update the documentation?

  • Yes
  • Not needed (internal change without effects for user)

@yutong-xiang-97 yutong-xiang-97 changed the title Refactor object detection transforms Refactor Object Detection Transforms Jul 3, 2026
@yutong-xiang-97
yutong-xiang-97 marked this pull request as ready for review July 3, 2026 16:02
@yutong-xiang-97

Copy link
Copy Markdown
Contributor Author

/review

@liopeer liopeer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in terms of hierarchy we need to discuss, because some hierarchy decisions are difficult to follow (e.g. PicoDetTransform inheriting from LTDETRTransform). We also now have imo to many levels of inheritance (we have the base transform, then LT-DETR transform and the specialized ones on top. One level is okay, but two are imo too much. Instead of inheriting anything from the first level, that first level should be completely abstract (protocols or ABCs).

Comment thread src/lightly_train/_transforms/ltdetr_transforms/base.py Outdated
Comment thread src/lightly_train/_commands/benchmark_task.py
@yutong-xiang-97
yutong-xiang-97 requested a review from liopeer July 7, 2026 11:54
@yutong-xiang-97

yutong-xiang-97 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Instead of using three-level inheritance with the shared logic as the intermediate child (refused bequest issue of refactoring), the common step-aware control logic is moved into reusable components in components.py (favor composition over inheritance).

The new structure is split as follows:

  • ltdetr_transforms/components.py contains the reusable runtime pieces for LT-DETR-style transforms: step activation tracking, dataloader reinitialization checks, cached sample transform construction, and mosaic activation handling.
  • ltdetr_transforms/object_detection.py contains the object-detection transform and collate-function implementation, including input/output types, transform args contract, bbox normalization, degenerate-box filtering, mixup/copyblend/scale-jitter handling, and batch transform wiring.
  • ltdetr_transforms/utils.py contains helper functions for image-size resolution, activation schedules, albumentations transform ordering, bbox conversion/filtering, and normalization.

The commit also fixes oriented object detection after removing the old LT-DETR base module.

Note that PicoDet still inherits from the LT-DETR object detection transform stack, which is confusing and should be cleaned up in a follow-up PR.

@liopeer liopeer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already quite a bit clearer. Would encourage to fix the inconsistencies in a follow-up, but would first focus on actually implementing the instance segmentation stuff.

Comment thread src/lightly_train/_commands/benchmark_task.py
Comment thread src/lightly_train/_transforms/ltdetr_transforms/components.py Outdated
Comment thread src/lightly_train/_data/object_detection_dataset.py
Comment thread src/lightly_train/_transforms/object_detection_transform.py
@yutong-xiang-97
yutong-xiang-97 force-pushed the yutong-trn-2271-refactor-ltdetr-object-detection-transforms branch from 51848b5 to 4bef13d Compare July 7, 2026 15:05
@yutong-xiang-97
yutong-xiang-97 merged commit ce49a8e into main Jul 7, 2026
13 checks passed
@yutong-xiang-97
yutong-xiang-97 deleted the yutong-trn-2271-refactor-ltdetr-object-detection-transforms branch July 7, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants