Skip to content

Conversation

@gitttt-1234
Copy link
Collaborator

@gitttt-1234 gitttt-1234 commented Jan 26, 2026

Summary

  • Fixes confusing logging when loading backbone/head weights separately from legacy .h5 files
  • Adds component-based filtering to only process relevant weights
  • Warnings now only show for truly unexpected mismatches

Problem

When loading legacy TensorFlow/Keras weights into separate PyTorch components (backbone vs head), users saw:

  1. Confusing counts like "22/26 loaded" instead of "22/22"
  2. Many warnings about "No matching PyTorch parameter" for weights that belong to the other component (expected behavior, not an error)

Solution

Added a component parameter to filter legacy weights before mapping:

  • component="backbone": Only processes encoder/decoder weights (excludes "Head" layers)
  • component="head": Only processes head layer weights
  • component=None: No filtering (default, for full model loading in inference)

Changes

sleap_nn/legacy_models.py

  • Added filter_legacy_weights_by_component() helper function
  • Added component parameter to map_legacy_to_pytorch_layers() and load_legacy_model_weights()
  • Cleaned up unused imports

sleap_nn/training/lightning_modules.py

  • Updated backbone loading to pass component="backbone"
  • Updated head loading to pass component="head"

Result

Before:

Loading backbone weights from `model.h5` ...
No matching PyTorch parameter found for model_weights/CentroidConfmapsHead_0/...
No matching PyTorch parameter found for model_weights/OffsetRefinementHead_0/...
Successfully mapped 22/26 legacy weights to PyTorch parameters

After:

Loading backbone weights from `model.h5` ...
Filtered legacy weights for backbone: 22/26 weights
Successfully mapped 22/22 PyTorch parameters from legacy weights

Test plan

  • Verified fix with test script showing correct logging output
  • All existing test_legacy_models.py tests pass (35 passed, 4 skipped, 3 xfailed)
  • CI tests

🤖 Generated with Claude Code

@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.58%. Comparing base (ff91433) to head (54f5cd4).
⚠️ Report is 125 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (ff91433) and HEAD (54f5cd4). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (ff91433) HEAD (54f5cd4)
4 3
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #439       +/-   ##
===========================================
- Coverage   95.28%   84.58%   -10.70%     
===========================================
  Files          49       74       +25     
  Lines        6765    10785     +4020     
===========================================
+ Hits         6446     9123     +2677     
- Misses        319     1662     +1343     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gitttt-1234 gitttt-1234 force-pushed the fix/legacy-weight-loading-logging branch 2 times, most recently from e7e3601 to a09225b Compare January 26, 2026 23:45
When loading backbone/head weights separately from a legacy .h5 file,
the logging showed confusing counts and warnings about unmatched weights
that were expected (e.g., head weights when loading backbone).

Changes:
- Add `filter_legacy_weights_by_component()` to pre-filter weights
- Add `component` parameter to `load_legacy_model_weights()` and
  `map_legacy_to_pytorch_layers()` ("backbone", "head", or None)
- Update training call sites to pass component type
- Warnings now only show for truly unexpected mismatches
- Clean up unused imports

Before: Loading backbone shows warnings for all head weights
After:  Loading backbone only processes backbone weights, no spurious warnings

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@gitttt-1234 gitttt-1234 force-pushed the fix/legacy-weight-loading-logging branch from a09225b to 54f5cd4 Compare January 27, 2026 00:38
@gitttt-1234 gitttt-1234 merged commit 560d072 into main Jan 27, 2026
7 checks passed
@gitttt-1234 gitttt-1234 deleted the fix/legacy-weight-loading-logging branch January 27, 2026 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants