Skip to content

Commit

Permalink
fix(zoo): fix bioimageio model zoo df initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
qin-yu committed Dec 3, 2024
1 parent d204ee7 commit 2cd47a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
6 changes: 3 additions & 3 deletions plantseg/core/zoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def get_model_by_id(self, model_id: str):
https://bioimage-io.github.io/collection-bioimage-io/rdfs/10.5281/zenodo.8401064/8429203/rdf.yaml
"""

if not self.models_bioimageio:
if not hasattr(self, 'models_bioimageio'):
self.refresh_bioimageio_zoo_urls()

if model_id not in self.models_bioimageio.index:
Expand Down Expand Up @@ -458,13 +458,13 @@ def _is_plantseg_model(self, collection_entry: dict) -> bool:

def get_bioimageio_zoo_plantseg_model_names(self) -> list[str]:
"""Return a list of model names in the BioImage.IO Model Zoo tagged with 'plantseg'."""
if not self.models_bioimageio:
if not hasattr(self, 'models_bioimageio'):
self.refresh_bioimageio_zoo_urls()
return sorted(model_zoo.models_bioimageio[model_zoo.models_bioimageio["supported"]].index.to_list())

def get_bioimageio_zoo_all_model_names(self) -> list[str]:
"""Return a list of all model names in the BioImage.IO Model Zoo."""
if not self.models_bioimageio:
if not hasattr(self, 'models_bioimageio'):

Check warning on line 467 in plantseg/core/zoo.py

View check run for this annotation

Codecov / codecov/patch

plantseg/core/zoo.py#L467

Added line #L467 was not covered by tests
self.refresh_bioimageio_zoo_urls()
return sorted(model_zoo.models_bioimageio.index.to_list())

Check warning on line 469 in plantseg/core/zoo.py

View check run for this annotation

Codecov / codecov/patch

plantseg/core/zoo.py#L469

Added line #L469 was not covered by tests

Expand Down
8 changes: 2 additions & 6 deletions tests/core/test_zoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def test_model_output_normalisation(self, model_name):
class TestBioImageIOModelZoo:
"""Test the BioImage.IO model zoo"""

model_zoo.refresh_bioimageio_zoo_urls()

@pytest.mark.parametrize("model_id", MODEL_IDS)
def test_get_model_by_id(self, model_id):
"""Try to load a model from the BioImage.IO model zoo by ID."""
Expand All @@ -62,9 +64,3 @@ def test_halo_computation_for_bioimageio_model(self, model_id):
model, _, _ = model_zoo.get_model_by_id(model_id)
halo = model_zoo.compute_halo(model)
assert halo == 44

def test_models_bioimageio(self):
"""`model_zoo` has no `models_bioimageio` attribute until `.refresh_bioimageio_zoo_urls()` is called."""
assert not hasattr(model_zoo, 'models_bioimageio')
model_zoo.refresh_bioimageio_zoo_urls()
assert hasattr(model_zoo, 'models_bioimageio')

0 comments on commit 2cd47a4

Please sign in to comment.