Skip to content

Commit 8206430

Browse files
Bug: Check whether model_desc.root is a dir or a zip before extraction (#719)
On bioimageio CI, the models are loaded from a folder and not a `zip` file. So we need to check whether the `model_desc.root` is a *directory* or a *zip file* before trying to extract it [here](https://github.com/CAREamics/careamics/blob/d5062351b6c222177662e9329fbdce365509c5ef/src/careamics/model_io/bioimage/model_description.py#L326C5-L326C41): ```python # extract the zip model and return the directory model_dir = extract(model_desc.root) ``` ## Changes Made Checking the `model_desc.root` if it is a directory or a zip file: ```python # get the model directory if isinstance(model_desc.root, Path) and model_desc.root.is_dir(): model_dir: DirectoryPath = model_desc.root else: # extract the zip model model_dir = extract(model_desc.root) ``` ### Modified features or files - `model_description.py` ## How has this been tested? I tested it by running our bmz tests as well as running the bioimageio collection script: [scripts/check_compatibility_careamics.py](https://github.com/bioimage-io/collection/blob/main/scripts/check_compatibility_careamics.py) ## Related Issues <!-- Link to any related issues or discussions. Use keywords like "Fixes", "Resolves", or "Closes" to link to issues automatically. --> - Resolves #712 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 73e2f3c commit 8206430

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/careamics/model_io/bioimage/model_description.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
Version,
2727
WeightsDescr,
2828
)
29+
from pydantic import DirectoryPath
2930

3031
from careamics.config import Configuration, DataConfig
3132

@@ -322,8 +323,12 @@ def extract_model_path(model_desc: ModelDescr) -> tuple[Path, Path]:
322323
if model_desc.weights.pytorch_state_dict is None:
323324
raise ValueError("No model weights found in model description.")
324325

325-
# extract the zip model and return the directory
326-
model_dir = extract(model_desc.root)
326+
# get the model directory
327+
if isinstance(model_desc.root, Path) and model_desc.root.is_dir():
328+
model_dir: DirectoryPath = model_desc.root
329+
else:
330+
# extract the zip model
331+
model_dir = extract(model_desc.root)
327332

328333
weights_path = model_dir.joinpath(model_desc.weights.pytorch_state_dict.source.path)
329334

0 commit comments

Comments
 (0)