From 947b6692d5f64d46fde624faadda1dcd97b32ee0 Mon Sep 17 00:00:00 2001 From: Marwan Zouinkhi Date: Sat, 16 Mar 2024 19:05:08 -0400 Subject: [PATCH 1/8] download checkpoints --- .../pytorch/cosem/load_checkpoint.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 src/cellmap_models/pytorch/cosem/load_checkpoint.py diff --git a/src/cellmap_models/pytorch/cosem/load_checkpoint.py b/src/cellmap_models/pytorch/cosem/load_checkpoint.py new file mode 100755 index 0000000..081a1c4 --- /dev/null +++ b/src/cellmap_models/pytorch/cosem/load_checkpoint.py @@ -0,0 +1,34 @@ +from pathlib import Path +from cellmap_models import download_url_to_file + + + +def download_checkpoint(checkpoint_name: str,local_folder: Path): + """ + download models checkpoint from s3 bucket. + + Args: + checkpoint_name (str): Name of the checkpoint file. + local_folder (Path): Local folder to save the checkpoint. + return: + checkpoint_path (Path): Path to the downloaded checkpoint. + """ + from . import models_dict, models_list, model_names # 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}" + ) + + checkpoint_path = Path( + local_folder/ Path(checkpoint_name.replace(".", "_")) + ).with_suffix(".pth") + 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 From 636c416bbf0ebb80766ca4c5c73e38c6b7d53446 Mon Sep 17 00:00:00 2001 From: Marwan Zouinkhi Date: Sat, 16 Mar 2024 19:05:53 -0400 Subject: [PATCH 2/8] init --- src/cellmap_models/pytorch/cosem/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cellmap_models/pytorch/cosem/__init__.py b/src/cellmap_models/pytorch/cosem/__init__.py index 9109bd7..a840f5a 100755 --- a/src/cellmap_models/pytorch/cosem/__init__.py +++ b/src/cellmap_models/pytorch/cosem/__init__.py @@ -1,4 +1,5 @@ from .load_model import load_model +from .load_checkpoint import download_checkpoint models_dict = { "setup04/1820500": "https://janelia-cosem-networks.s3.amazonaws.com/v0003.2-pytorch/cosem_models/cosem_models/setup04/1820500", From bf1acfaf95036d72e7a305a2d1381d8eabd09bb6 Mon Sep 17 00:00:00 2001 From: Marwan Zouinkhi Date: Sun, 17 Mar 2024 11:46:49 -0400 Subject: [PATCH 3/8] :art: Format Python code with psf/black --- src/cellmap_models/pytorch/cosem/load_checkpoint.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/cellmap_models/pytorch/cosem/load_checkpoint.py b/src/cellmap_models/pytorch/cosem/load_checkpoint.py index 081a1c4..51f19d4 100755 --- a/src/cellmap_models/pytorch/cosem/load_checkpoint.py +++ b/src/cellmap_models/pytorch/cosem/load_checkpoint.py @@ -2,8 +2,7 @@ from cellmap_models import download_url_to_file - -def download_checkpoint(checkpoint_name: str,local_folder: Path): +def download_checkpoint(checkpoint_name: str, local_folder: Path): """ download models checkpoint from s3 bucket. @@ -13,16 +12,16 @@ def download_checkpoint(checkpoint_name: str,local_folder: Path): return: checkpoint_path (Path): Path to the downloaded checkpoint. """ - from . import models_dict, models_list, model_names # avoid circular import + 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}" ) - + checkpoint_path = Path( - local_folder/ Path(checkpoint_name.replace(".", "_")) + local_folder / Path(checkpoint_name.replace(".", "_")) ).with_suffix(".pth") if not checkpoint_path.exists(): url = models_dict[checkpoint_name] From 40b9b57b86333d12502927f846c737af4dcaa392 Mon Sep 17 00:00:00 2001 From: Marwan Zouinkhi Date: Sun, 17 Mar 2024 12:25:48 -0400 Subject: [PATCH 4/8] use checkpoint path instead of folder --- src/cellmap_models/pytorch/cosem/load_checkpoint.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cellmap_models/pytorch/cosem/load_checkpoint.py b/src/cellmap_models/pytorch/cosem/load_checkpoint.py index 51f19d4..74d4e18 100755 --- a/src/cellmap_models/pytorch/cosem/load_checkpoint.py +++ b/src/cellmap_models/pytorch/cosem/load_checkpoint.py @@ -2,7 +2,7 @@ from cellmap_models import download_url_to_file -def download_checkpoint(checkpoint_name: str, local_folder: Path): +def download_checkpoint(checkpoint_name: str, checkpoint_path: Path): """ download models checkpoint from s3 bucket. @@ -20,9 +20,6 @@ def download_checkpoint(checkpoint_name: str, local_folder: Path): f"Checkpoint {checkpoint_name} not found. Available checkpoints: {models_list}" ) - checkpoint_path = Path( - local_folder / Path(checkpoint_name.replace(".", "_")) - ).with_suffix(".pth") if not checkpoint_path.exists(): url = models_dict[checkpoint_name] print(f"Downloading {checkpoint_name} from {url}") From 599b7ecd1fcf1b5ab9da1cf6a529210e55bc2eea Mon Sep 17 00:00:00 2001 From: Marwan Zouinkhi Date: Sun, 17 Mar 2024 12:26:42 -0400 Subject: [PATCH 5/8] fix typo --- src/cellmap_models/pytorch/cosem/load_checkpoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cellmap_models/pytorch/cosem/load_checkpoint.py b/src/cellmap_models/pytorch/cosem/load_checkpoint.py index 74d4e18..ea406bd 100755 --- a/src/cellmap_models/pytorch/cosem/load_checkpoint.py +++ b/src/cellmap_models/pytorch/cosem/load_checkpoint.py @@ -8,7 +8,7 @@ def download_checkpoint(checkpoint_name: str, checkpoint_path: Path): Args: checkpoint_name (str): Name of the checkpoint file. - local_folder (Path): Local folder to save the checkpoint. + local_folder (Path): Local path to save the checkpoint. return: checkpoint_path (Path): Path to the downloaded checkpoint. """ From d85f13a2aa6da2bf88917b532d2bd9fb72c3e260 Mon Sep 17 00:00:00 2001 From: Marwan Zouinkhi Date: Mon, 18 Mar 2024 11:34:57 -0400 Subject: [PATCH 6/8] support cellpose checkpoint download --- .../pytorch/cellpose/__init__.py | 1 + .../download_checkpoint.py} | 0 src/cellmap_models/pytorch/cosem/.DS_Store | Bin 6148 -> 0 bytes .../pytorch/cosem/download_checkpoint.py | 30 ++++++++++++++++++ 4 files changed, 31 insertions(+) rename src/cellmap_models/pytorch/{cosem/load_checkpoint.py => cellpose/download_checkpoint.py} (100%) delete mode 100644 src/cellmap_models/pytorch/cosem/.DS_Store create mode 100755 src/cellmap_models/pytorch/cosem/download_checkpoint.py diff --git a/src/cellmap_models/pytorch/cellpose/__init__.py b/src/cellmap_models/pytorch/cellpose/__init__.py index 6e0bc43..97a9ec5 100644 --- a/src/cellmap_models/pytorch/cellpose/__init__.py +++ b/src/cellmap_models/pytorch/cellpose/__init__.py @@ -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", diff --git a/src/cellmap_models/pytorch/cosem/load_checkpoint.py b/src/cellmap_models/pytorch/cellpose/download_checkpoint.py similarity index 100% rename from src/cellmap_models/pytorch/cosem/load_checkpoint.py rename to src/cellmap_models/pytorch/cellpose/download_checkpoint.py diff --git a/src/cellmap_models/pytorch/cosem/.DS_Store b/src/cellmap_models/pytorch/cosem/.DS_Store deleted file mode 100644 index 4ffd9ab8a762c1c5e58847836a3488df19be85e6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJx{|h5IsXB3RR^d7#Oo7AzIpsF;roJjZTOGREl6|m58=`Ryr}Uu`%!mSi15h zF(ZBf|A3W&JD(v=lTapv(4AyI$9`wOJSlbz0ID%)mjOxukjFxpo5Lz4Xq-wSrcBQw zqSA8&unN`Aak+WuC)m;<4u}JP%>nv$XP^g1(1!t7-)}b{sn_$%k4Z+?_qv3(nH%W%A>uGql)ni?@?>JA_k2Gbo;(E@<^{hdCf*xepdKQWo zmnnKQE7FtAnxLl&wJ|+cWBwq+*7N)}+U_U)(X2>MHY-IBc_fi^0MBfSe1TDFaX=gp z2fiGj{lURP=o$;&kkH49_(f zGIBa7bNNtaWo2$CO0SOdJDLv4Wt3VR5C`H8O!H%j&i~Eq`+q!1p2Puh;9ohQa$eJG z;47K4HSuzE);d@Yuuu>$WYj5Gnd4YD=qO&oq65bqY9P7>Lq_bukRJhUgH+ Date: Mon, 18 Mar 2024 11:37:21 -0400 Subject: [PATCH 7/8] fix init --- src/cellmap_models/pytorch/cosem/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cellmap_models/pytorch/cosem/__init__.py b/src/cellmap_models/pytorch/cosem/__init__.py index a840f5a..785743c 100755 --- a/src/cellmap_models/pytorch/cosem/__init__.py +++ b/src/cellmap_models/pytorch/cosem/__init__.py @@ -1,5 +1,5 @@ from .load_model import load_model -from .load_checkpoint import download_checkpoint +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", From 84be8fe195d5d9c3575a4823a031ab9cb7a20e74 Mon Sep 17 00:00:00 2001 From: Jeff Rhoades <37990507+rhoadesScholar@users.noreply.github.com> Date: Mon, 18 Mar 2024 13:34:45 -0400 Subject: [PATCH 8/8] Update download_checkpoint.py --- src/cellmap_models/pytorch/cellpose/download_checkpoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cellmap_models/pytorch/cellpose/download_checkpoint.py b/src/cellmap_models/pytorch/cellpose/download_checkpoint.py index ea406bd..df850d7 100755 --- a/src/cellmap_models/pytorch/cellpose/download_checkpoint.py +++ b/src/cellmap_models/pytorch/cellpose/download_checkpoint.py @@ -4,7 +4,7 @@ def download_checkpoint(checkpoint_name: str, checkpoint_path: Path): """ - download models checkpoint from s3 bucket. + download models checkpoint from GitHub release resources. Args: checkpoint_name (str): Name of the checkpoint file.