-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/cellmap_models/pytorch/cellpose/download_checkpoint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |