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

Load checkpoints #4

Merged
merged 8 commits into from
Mar 18, 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
1 change: 1 addition & 0 deletions src/cellmap_models/pytorch/cellpose/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .add_model import add_model
from .load_model import load_model
from .get_model import get_model
from .download_checkpoint import download_checkpoint

models_dict = {
"jrc_mus-epididymis-1_nuc_cp": "https://github.com/janelia-cellmap/cellmap-models/releases/download/2024.03.08/jrc_mus-epididymis-1_nuc_cp",
Expand Down
30 changes: 30 additions & 0 deletions src/cellmap_models/pytorch/cellpose/download_checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from pathlib import Path
from cellmap_models import download_url_to_file


def download_checkpoint(checkpoint_name: str, checkpoint_path: Path):
"""
download models checkpoint from GitHub release resources.
Args:
checkpoint_name (str): Name of the checkpoint file.
local_folder (Path): Local path to save the checkpoint.
return:
checkpoint_path (Path): Path to the downloaded checkpoint.
"""
from . import models_dict, models_list # avoid circular import

# Make sure the checkpoint exists
if checkpoint_name not in models_list:
raise ValueError(
f"Checkpoint {checkpoint_name} not found. Available checkpoints: {models_list}"
)

if not checkpoint_path.exists():
url = models_dict[checkpoint_name]
print(f"Downloading {checkpoint_name} from {url}")
download_url_to_file(url, checkpoint_path)
else:
print(f"Checkpoint {checkpoint_name} found at {checkpoint_path}")

return checkpoint_path
Binary file removed src/cellmap_models/pytorch/cosem/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions src/cellmap_models/pytorch/cosem/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .load_model import load_model
from .download_checkpoint import download_checkpoint

models_dict = {
"setup04/1820500": "https://janelia-cosem-networks.s3.amazonaws.com/v0003.2-pytorch/cosem_models/cosem_models/setup04/1820500",
Expand Down
30 changes: 30 additions & 0 deletions src/cellmap_models/pytorch/cosem/download_checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from pathlib import Path
from cellmap_models import download_url_to_file


def download_checkpoint(checkpoint_name: str, checkpoint_path: Path):
"""
download models checkpoint from s3 bucket.

Args:
checkpoint_name (str): Name of the checkpoint file.
local_folder (Path): Local path to save the checkpoint.
return:
checkpoint_path (Path): Path to the downloaded checkpoint.
"""
from . import models_dict, models_list # avoid circular import

# Make sure the checkpoint exists
if checkpoint_name not in models_list:
raise ValueError(
f"Checkpoint {checkpoint_name} not found. Available checkpoints: {models_list}"
)

if not checkpoint_path.exists():
url = models_dict[checkpoint_name]
print(f"Downloading {checkpoint_name} from {url}")
download_url_to_file(url, checkpoint_path)
else:
print(f"Checkpoint {checkpoint_name} found at {checkpoint_path}")

return checkpoint_path
Loading