Open
Add decoder-only deformable neck to Hungarian DETR detector#4
Conversation
Copilot
AI
changed the title
[WIP] Add DinoV3 feature extractor and integrate into framework
Add DINOv2 ViT and ConvNext feature extractors with RetinaNet detectors
Jun 19, 2026
TNodeCode
marked this pull request as ready for review
June 19, 2026 18:55
Owner
|
Can you also add a custom Detektion head that uses hungarian matching for matching detections and ground truth? |
There was a problem hiding this comment.
Pull request overview
This PR integrates HuggingFace Transformers DINOv2 backbones (ViT and ConvNeXt) into the project and wires them into torchvision RetinaNet detectors, enabling training/inference with these newer feature extractors.
Changes:
- Added
feature_extractors.pyimplementing DINOv2 ViT/ConvNeXt extractors plus RetinaNet-compatible backbone adapters (5-level pyramids). - Added two new
AbstractDetectorimplementations using those backbones with torchvision’sRetinaNet. - Updated dependencies to include
transformers.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| requirements.txt | Adds transformers dependency required by the new DINOv2/ConvNeXt backbones. |
| feature_extractors.py | Introduces DINOv2-based feature extractors and backbone adapters that emit RetinaNet-compatible feature pyramids. |
| detectors.py | Adds new RetinaNet detector classes that use the new DINOv2 ViT/ConvNeXt backbones. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+77
to
+95
| captured = OrderedDict() | ||
| hooks = [] | ||
|
|
||
| if self.output_patches: | ||
| # key= default-argument captures current string at definition time | ||
| hooks.append( | ||
| self.model.embeddings.register_forward_hook( | ||
| lambda m, i, o, key="embeddings": captured.update({key: o}) | ||
| ) | ||
| ) | ||
| for layer_idx in self.layers: | ||
| # key=layer_idx default-argument captures the current int at definition time | ||
| hooks.append( | ||
| self.model.encoder.layer[layer_idx].register_forward_hook( | ||
| lambda m, i, o, key=layer_idx: captured.update({key: o}) | ||
| ) | ||
| ) | ||
|
|
||
| z = self.model(x) |
Owner
There was a problem hiding this comment.
Then use output_hidden_states=True
Copilot
AI
changed the title
Add DINOv2 ViT and ConvNext feature extractors with RetinaNet detectors
Add DETR-style Hungarian matching detection head for DINOv2
Jun 19, 2026
Copilot
AI
changed the title
Add DETR-style Hungarian matching detection head for DINOv2
Add mkdocs usage docs for dataset layout, training flow, and inference
Jun 19, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
TNodeCode
requested changes
Jun 19, 2026
Copilot
AI
changed the title
Add mkdocs usage docs for dataset layout, training flow, and inference
Add decoder-only deformable neck to Hungarian DETR detector
Jun 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Hungarian DETR path was consuming backbone features too directly, without a deformable-transformer-style neck. This update introduces a decoder-only deformable neck (no encoder stack) and makes neck depth configurable for DINO backbone outputs.
Decoder-only deformable neck
DeformableDecoderNeckandDeformableDecoderLayerinhungarian_head.py.Head integration
HungarianDetectionHeadnow routes backbone features through the new neck before class/box prediction.TransformerDecoderpath that operated on raw projected features.Configurability surfaced in detector API
DINOv2HungarianDetectornow forwards:num_decoder_layers(neck depth)num_feature_levels(multi-scale memory levels)replace_head(...)preserves these settings when rebuilding the head for class-count changes.Behavioral intent