Skip to content

fix(zoo): load BioImage.IO weights saved in PyTorch's legacy format - #645

Open
qin-yu wants to merge 1 commit into
mainfrom
qy/fix-legacy-biio-weights
Open

qin-yu wants to merge 1 commit into
mainfrom
qy/fix-legacy-biio-weights

Conversation

@qin-yu

@qin-yu qin-yu commented Nov 25, 2026

Copy link
Copy Markdown
Member

ModelZoo.get_model_by_id, which unet_prediction uses to run a BioImage.IO model ID through PanSeg's own UNet, handed torch.load the reader that bioimageio.spec's download returns. torch.load needs readline to read PyTorch's legacy (non-zip) format, and that reader has none, so models saved in that format failed to load, for example emotional-cricket and thoughtful-turtle:

AttributeError: ‘BytesReader’ object has no attribute ‘readline’

This was there before #642: the download(...source) call in 2.2.0 returned the same reader. I found it while running every PanSeg model on bioimage.io through PanSeg.

This PR:

  • reads the weights into a BytesIO before torch.load, so both formats load
  • lets mock_biio_package save its weights in the legacy format, and runs test_get_model_by_id_resolves_bioimageio_id with both formats; the legacy case fails without the fix

torch.load reads PyTorch's legacy (non-zip) format line by line, but the reader returned by bioimageio.spec's `download` has no `readline`, so `get_model_by_id` failed for models such as emotional-cricket and thoughtful-turtle. Read the weights into a `BytesIO` first.
@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.57%. Comparing base (805efae) to head (5346fe3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #645   +/-   ##
=======================================
  Coverage   89.57%   89.57%           
=======================================
  Files          74       74           
  Lines        8605     8606    +1     
=======================================
+ Hits         7708     7709    +1     
  Misses        897      897           

☔ View full report in Codecov by Harness.
📢 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.

@qin-yu
qin-yu requested a review from KRiedmiller November 25, 2026 00:55

This branch has not been deployed

No deployments
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.

1 participant