Skip to content

Commit

Permalink
feat(load bmz): allow url; let bioimage.core do file validation
Browse files Browse the repository at this point in the history
  • Loading branch information
melisande-c committed Nov 13, 2024
1 parent b444084 commit 6435a04
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/careamics/model_io/bmz_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

import numpy as np
import pkg_resources
from bioimageio.core import load_description, test_model
from bioimageio.core import load_model_description, test_model
from bioimageio.spec import ValidationSummary, save_bioimageio_package
from pydantic import HttpUrl
from torch import __version__ as PYTORCH_VERSION
from torch import load, save
from torchvision import __version__ as TORCHVISION_VERSION
Expand Down Expand Up @@ -193,32 +194,30 @@ def export_to_bmz(


def load_from_bmz(
path: Union[Path, str]
path: Union[Path, str, HttpUrl]
) -> Tuple[Union[FCNModule, VAEModule], Configuration]:
"""Load a model from a BioImage Model Zoo archive.
Parameters
----------
path : Union[Path, str]
Path to the BioImage Model Zoo archive.
path : Path, str or HttpUrl
Path to the BioImage Model Zoo archive. A Http URL must point to a downloadable
location.
Returns
-------
Tuple[CAREamicsKiln, Configuration]
CAREamics model and configuration.
FCNModel or VAEModel
The loaded CAREamics model.
Configuration
The loaded CAREamics configuration.
Raises
------
ValueError
If the path is not a zip file.
"""
path = Path(path)

if path.suffix != ".zip":
raise ValueError(f"Path must be a bioimage.io zip file, got {path}.")

# load description, this creates an unzipped folder next to the archive
model_desc = load_description(path)
model_desc = load_model_description(path)

# extract relative paths
weights_path, config_path = extract_model_path(model_desc)
Expand Down

0 comments on commit 6435a04

Please sign in to comment.