lightly-train
lightly-train copied to clipboard
feat: incorporate ECViT backbones into DINOv3 LTDETR
Summary
Incorporates the EdgeCrafter ECViT backbones into the DINOv3 LTDETR object detection task model, exposing four new model names under the edgecrafter/ package prefix:
edgecrafter/ecvitt-ltdetredgecrafter/ecvittplus-ltdetredgecrafter/ecvits-ltdetredgecrafter/ecvitsplus-ltdetr
Each is a drop-in replacement for the DINOv3 ViT LTDETR backbones — only the model argument changes:
lightly_train.train_object_detection(
out="out/my_experiment",
model="edgecrafter/ecvitt-ltdetr", # only change vs. dinov3/*-ltdetr
data={...},
)
Stacking
This PR stacks on #772 (gabriel-trn-2143-port-ecvit-to-lightlytrain), which moved the ECViT backbone port into src/lightly_train/_models/ecvit/. #772 must be merged first. The base branch for this PR is gabriel-trn-2143-port-ecvit-to-lightlytrain, not main.
Design
- Incorporation strategy: extended the existing
DINOv3LTDETRObjectDetectiontask model to dispatch onpackage_helpers.parse_model_name(model_name). Accepts both"dinov3"and"edgecrafter"packages. No new task model class. - No new encoder/decoder configs. The ECViT wrapper emits
(P3, P4, P5)at strides 8/16/32 with per-level channel counts equal toproj_dim(192 forecvitt, 256 for the other three). These match the existing DINOv3 ViT-shapedHybridEncoder/RTDETRTransformerv2/DFINETransformerconfigs byproj_dim, so the configs are reused:ecvitt→_DINOv3LTDETRObjectDetectionViTTConfig(in_channels 192)ecvittplus/ecvits/ecvitsplus→_DINOv3LTDETRObjectDetectionViTTPlusConfig(in_channels 256)
use_sta=False. ECViT already fuses its own pyramid internally; noSpatialPriorModulev2is instantiated. The wrapper is a pass-through:forward(x) → ECViTWrapper(x).- No
mask_tokenfreeze. ECViT has nomask_token; the DINOv3 ViT branch'sbackbone.mask_token.requires_grad = Falseline is skipped. - Fixed
patch_size=16. ECViT-NN uses aConvPyramidPatchEmbedthat only supportspatch_size=16. The train/val transform's image size andscale_jitter.divisible_byare resolved to match (multiples of 32). - Fixed
_expected_input_channels=3. Multi-channel input is intentionally not supported for ECViT on this first cut. The constructor ignoresbackbone_args["in_chans"]andimage_normalize-driven channel counts on theedgecrafterbranch. - Pretrained weights. Loaded via
ECVIT_PRETRAINED_URLSthrough the newEdgeCrafterPackage.get_model, which downloads toEnv.LIGHTLY_TRAIN_MODEL_CACHE_DIRand loads intoECViTWrapper.backbonevia the existing_load_backbone_weightspath. No hash check on first cut (matches the DINOv3 TODO).
Out of scope (intentional)
- No documentation changes in this PR. The
edgecrafter/package page (docs/source/pretrain_distill/models/edgecrafter.md), the toctree/bullet entry indocs/source/pretrain_distill/models/index.md, and the "LTDETR EdgeCrafter (ECViT) Models" subsection indocs/source/object_detection.mdare deferred to a separate docs-only follow-up PR stacked on top of this one. - No
*-ltdetr-cocorows in the docs table — we have no COCO-fine-tuned ECViT weights yet. - No mAP numbers in the docs table.
- No Quick Start snippet for ECViT in
object_detection.md(the DINOv3 snippet applies verbatim; only themodelargument changes). - No multi-channel support for ECViT (always 3 input channels).
- No new
_HybridEncoder*/_RTDETRTransformerv2*/_DFINETransformer*configs — the existing DINOv3 ViT-shaped configs are reused. - No new ECViT-specific backbone-wrapper config (
_RTDETRBackboneWrapperViTT*Config) — those are STA-specific and we haveuse_sta=False.
Related
- Parent PR: #772 (
gabriel-trn-2143-port-ecvit-to-lightlytrain) — moves the ECViT backbone port intosrc/lightly_train/_models/ecvit/. Must be merged first. - Upstream: EdgeCrafter (capsule2077/edgecrafter).
- Task model:
DINOv3LTDETRObjectDetection(the class name is unchanged; ECViT is dispatched internally).
/review