When loading PyTorch state dict weights, bioimageio.core uses torch.load(weights_only=True). If the .pth file was saved with extra metadata (e.g. numpy arrays for normalization stats, as done by deepflash2), this raises a cryptic error that does not explain the fix.
Suggested fix: Add a try-except that catches the error and prints a helpful message like: "Your weights file appears to contain non-tensor objects (e.g. numpy arrays). Save only the state dict: torch.save(checkpoint["model"], "weights.pt")"
Steps to reproduce:
- Download a deepflash2 model (e.g.
matjesg/cFOS_in_HC on HuggingFace)
- Load with bioimageio.core — fails with cryptic
torch.load error
- Fix: extract state dict with
weights_only=False then save clean
cc @FynnBe
When loading PyTorch state dict weights, bioimageio.core uses
torch.load(weights_only=True). If the.pthfile was saved with extra metadata (e.g. numpy arrays for normalization stats, as done by deepflash2), this raises a cryptic error that does not explain the fix.Suggested fix: Add a try-except that catches the error and prints a helpful message like: "Your weights file appears to contain non-tensor objects (e.g. numpy arrays). Save only the state dict:
torch.save(checkpoint["model"], "weights.pt")"Steps to reproduce:
matjesg/cFOS_in_HCon HuggingFace)torch.loaderrorweights_only=Falsethen save cleancc @FynnBe