-
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.
Add cellmap.add_cellpose script and update model loading
- Loading branch information
1 parent
20381fc
commit 2e8e1b9
Showing
7 changed files
with
42 additions
and
27 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
Binary file not shown.
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
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,29 @@ | ||
from pathlib import Path | ||
from cellpose.utils import download_url_to_file | ||
|
||
|
||
def get_model( | ||
model_name: str, | ||
base_path: str = f"{Path(__file__).parent}/models", | ||
): | ||
"""Add model to cellpose | ||
Args: | ||
model_name (str): model name | ||
base_path (str, optional): base path to store Torchscript model. Defaults to "./models". | ||
""" | ||
from . import models_dict | ||
|
||
# download model to cellpose directory | ||
if model_name not in models_dict: | ||
raise ValueError( | ||
f"Model {model_name} is not available. Available models are {list(models_dict.keys())}." | ||
) | ||
|
||
if not (base_path / f"{model_name}.pth").exists(): | ||
print(f"Downloading {model_name} from {models_dict[model_name]}") | ||
download_url_to_file( | ||
models_dict[model_name], str(base_path / f"{model_name}.pth") | ||
) | ||
print("Downloaded model {model_name} to {base_path}.") | ||
return |
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