Skip to content

Add multi-scale feature support to all backbone packages #925

Description

@liopeer

Description

Dense prediction tasks such as semantic segmentation and object detection need normalized intermediate feature maps from multiple backbone layers or stages. Multi-scale features can also be useful during pretraining and distillation, for example to define objectives or transfer representations at more than one level of the network, e.g. wanted in #628 .

LightlyTrain already defines a public interface for this:

DINOv2 and DINOv3 provide reference implementations:

We would like to extend this interface to the remaining model packages, starting with TIMM. The current TIMMModelWrapper already uses TIMM's forward_intermediates where available, which should provide a useful starting point.

EdgeCrafter is partially supported: ECViTModelWrapper.forward() already returns a three-level feature pyramid, but its wrapper and package do not yet implement the public multi-scale protocols.

Contributions can address one package at a time; there is no need to implement the whole checklist in a single PR. If you would like to work on one, please leave a comment so work is not duplicated.

Expected behavior

For each package:

  • Make the package implement MultiScaleFeaturePackage.
  • Make its wrapper implement forward_multiscale_features() and the applicable metadata methods.
  • Return normalized NCHW feature tensors in the same order as the requested layer or stage indices.
  • Expose correct feature dimensions and, depending on the architecture, patch size or feature strides.
  • Fail with a clear error for models that cannot expose intermediate features instead of returning incorrect results.
  • Add tests for metadata, output ordering and shapes, invalid indices, and consistency with forward_features() for the final layer or stage.

Package-specific implementations do not have to support every upstream architecture immediately. Clearly documented and tested support for a useful subset is welcome, provided unsupported models are handled explicitly.

Package checklist

  • DINOv2
  • DINOv3
  • TIMM — first implementation target
  • EdgeCrafter — adapt the existing feature pyramid to the public interface
  • Torchvision
  • Ultralytics
  • SuperGradients
  • RF-DETR

Custom model wrappers are not included in this checklist because they are user-defined, but they can implement the same protocols.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions