test: add regression test for RFDETRSegNano PE interpolation at custom resolution#1026
Draft
test: add regression test for RFDETRSegNano PE interpolation at custom resolution#1026
Conversation
2 tasks
…tom resolution Adds test_rfdetr_seg_nano_loads_default_pe_checkpoint_at_custom_resolution to TestL1FacadePEInterpolationEndToEnd. This mirrors the existing RFDETRNano test but covers the segmentation model case reported in issue #1010. The test saves a default-resolution RFDETRSegNano state_dict as a checkpoint (simulating rf-detr-seg-nano.pt) and loads it at a higher resolution, verifying that PE interpolation succeeds and the backbone's position_embeddings tensor has the correct shape for the new resolution. The fix (routing through load_pretrain_weights → interpolate_position_embeddings) was already present in inference._build_model_context; this test pins the wiring so a future refactor cannot reintroduce a divergent loader path that silently skips PE interpolation for segmentation variants. Agent-Logs-Url: https://github.com/roboflow/rf-detr/sessions/c6ff38d8-bd65-4f52-a9ec-e9bc91adfea2 Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix segmentation training error in RFDETRSegNano
test: add regression test for RFDETRSegNano PE interpolation at custom resolution
May 4, 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.
RFDETRSegNano(resolution=1008, num_classes=2)raisedRuntimeError: size mismatch for backbone.0.encoder.encoder.embeddings.position_embeddingswhen loading pretrain weights — the checkpoint's 26×26 PE grid (default 312px resolution) wasn't being interpolated to match the model's 84×84 grid (1008px / patch_size=12).The fix was already present in the current codebase:
inference._build_model_contextroutes throughload_pretrain_weights→interpolate_position_embeddings, andModelConfig._sync_pe_with_resolutioncorrectly propagatespositional_encoding_size = resolution // patch_sizewhen a custom resolution is supplied. However, there was no end-to-end test covering the segmentation model path.Changes
tests/training/test_load_pretrain_weights.py— addstest_rfdetr_seg_nano_loads_default_pe_checkpoint_at_custom_resolutiontoTestL1FacadePEInterpolationEndToEnd, mirroring the existingRFDETRNanotest for the segmentation variant:RFDETRSegNano(no pretrain weights, 90 classes) and saves its state dict as a checkpoint withargs.segmentation_head=True, args.patch_size=12resolution=624(num_classes=2), triggering PE interpolation from 26×26 to 52×52position_embeddingstensor shape is[1, 2705, 384](52²+1 tokens)