Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(BMZ export): torchvision version; model validation #257

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/careamics/model_io/bioimage/bioimage_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_unzip_path(zip_path: Union[Path, str]) -> Path:
return zip_path.parent / (str(zip_path.name) + ".unzip")


def create_env_text(pytorch_version: str) -> str:
def create_env_text(pytorch_version: str, torchvision_version: str) -> str:
"""Create environment yaml content for the bioimage model.

This installs an environment with the specified pytorch version and the latest
Expand All @@ -32,6 +32,8 @@ def create_env_text(pytorch_version: str) -> str:
----------
pytorch_version : str
Pytorch version.
torchvision_version : str
Torchvision version.

Returns
-------
Expand All @@ -43,7 +45,7 @@ def create_env_text(pytorch_version: str) -> str:
f"dependencies:\n"
f" - python=3.10\n"
f" - pytorch={pytorch_version}\n"
f" - torchvision={pytorch_version}\n"
f" - torchvision={torchvision_version}\n"
f" - pip\n"
f" - pip:\n"
f" - git+https://github.com/CAREamics/careamics.git\n"
Expand Down
9 changes: 0 additions & 9 deletions src/careamics/model_io/bioimage/model_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,6 @@ def create_model_description(
weights=weights_descr,
attachments=[FileDescr(source=config_path)],
cite=config.get_algorithm_citations(),
config={ # conversion from float32 to float64 creates small differences...
"bioimageio": {
"test_kwargs": {
"pytorch_state_dict": {
"decimals": 0, # ...so we relax the constraints on the decimals
}
}
}
},
)

return model
Expand Down
9 changes: 5 additions & 4 deletions src/careamics/model_io/bmz_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import pkg_resources
from bioimageio.core import load_description, test_model
from bioimageio.spec import ValidationSummary, save_bioimageio_package
from torch import __version__, load, save
from torch import __version__ as PYTORCH_VERSION
from torch import load, save
from torchvision import __version__ as TORCHVISION_VERSION

from careamics.config import Configuration, load_configuration, save_configuration
from careamics.config.support import SupportedArchitecture
Expand Down Expand Up @@ -141,7 +143,6 @@ def export_to_bmz(
path_to_archive.parent.mkdir(parents=True, exist_ok=True)

# versions
pytorch_version = __version__
careamics_version = pkg_resources.get_distribution("careamics").version

# save files in temporary folder
Expand All @@ -151,7 +152,7 @@ def export_to_bmz(
# create environment file
# TODO move in bioimage module
env_path = temp_path / "environment.yml"
env_path.write_text(create_env_text(pytorch_version))
env_path.write_text(create_env_text(PYTORCH_VERSION, TORCHVISION_VERSION))

# export input and ouputs
inputs = temp_path / "inputs.npy"
Expand All @@ -174,7 +175,7 @@ def export_to_bmz(
inputs=inputs,
outputs=outputs,
weights_path=weight_path,
torch_version=pytorch_version,
torch_version=PYTORCH_VERSION,
careamics_version=careamics_version,
config_path=config_path,
env_path=env_path,
Expand Down
Loading