lightly-train icon indicating copy to clipboard operation
lightly-train copied to clipboard

feat: incorporate ECViT backbones into DINOv3 LTDETR

Open gabrielfruet opened this issue 5 months ago • 1 comments

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-ltdetr
  • edgecrafter/ecvittplus-ltdetr
  • edgecrafter/ecvits-ltdetr
  • edgecrafter/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 DINOv3LTDETRObjectDetection task model to dispatch on package_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 to proj_dim (192 for ecvitt, 256 for the other three). These match the existing DINOv3 ViT-shaped HybridEncoder / RTDETRTransformerv2 / DFINETransformer configs by proj_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; no SpatialPriorModulev2 is instantiated. The wrapper is a pass-through: forward(x) → ECViTWrapper(x).
  • No mask_token freeze. ECViT has no mask_token; the DINOv3 ViT branch's backbone.mask_token.requires_grad = False line is skipped.
  • Fixed patch_size=16. ECViT-NN uses a ConvPyramidPatchEmbed that only supports patch_size=16. The train/val transform's image size and scale_jitter.divisible_by are 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 ignores backbone_args["in_chans"] and image_normalize-driven channel counts on the edgecrafter branch.
  • Pretrained weights. Loaded via ECVIT_PRETRAINED_URLS through the new EdgeCrafterPackage.get_model, which downloads to Env.LIGHTLY_TRAIN_MODEL_CACHE_DIR and loads into ECViTWrapper.backbone via the existing _load_backbone_weights path. 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 in docs/source/pretrain_distill/models/index.md, and the "LTDETR EdgeCrafter (ECViT) Models" subsection in docs/source/object_detection.md are deferred to a separate docs-only follow-up PR stacked on top of this one.
  • No *-ltdetr-coco rows 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 the model argument 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 have use_sta=False.

Related

  • Parent PR: #772 (gabriel-trn-2143-port-ecvit-to-lightlytrain) — moves the ECViT backbone port into src/lightly_train/_models/ecvit/. Must be merged first.
  • Upstream: EdgeCrafter (capsule2077/edgecrafter).
  • Task model: DINOv3LTDETRObjectDetection (the class name is unchanged; ECViT is dispatched internally).

gabrielfruet avatar Jun 12 '26 14:06 gabrielfruet

/review

gabrielfruet avatar Jun 15 '26 13:06 gabrielfruet