Skip to content

Commit

Permalink
7973-add-ngc-prefix (#7974)
Browse files Browse the repository at this point in the history
Fixes #7973 .

### Description

A few sentences describing the changes proposed in this pull request.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

Signed-off-by: Yiheng Wang <[email protected]>
Co-authored-by: YunLiu <[email protected]>
  • Loading branch information
yiheng-wang-nv and KumoLiu authored Aug 3, 2024
1 parent 1ece8a5 commit ae5a04d
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions monai/bundle/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,15 @@ def _remove_ngc_prefix(name: str, prefix: str = "monai_") -> str:


def _download_from_ngc(
download_path: Path, filename: str, version: str, remove_prefix: str | None, progress: bool
download_path: Path,
filename: str,
version: str,
prefix: str = "monai_",
remove_prefix: str | None = "monai_",
progress: bool = True,
) -> None:
# ensure prefix is contained
filename = _add_ngc_prefix(filename)
filename = _add_ngc_prefix(filename, prefix=prefix)
url = _get_ngc_bundle_url(model_name=filename, version=version)
filepath = download_path / f"{filename}_v{version}.zip"
if remove_prefix:
Expand All @@ -231,10 +236,16 @@ def _download_from_ngc(


def _download_from_ngc_private(
download_path: Path, filename: str, version: str, remove_prefix: str | None, repo: str, headers: dict | None = None
download_path: Path,
filename: str,
version: str,
repo: str,
prefix: str = "monai_",
remove_prefix: str | None = "monai_",
headers: dict | None = None,
) -> None:
# ensure prefix is contained
filename = _add_ngc_prefix(filename)
filename = _add_ngc_prefix(filename, prefix=prefix)
request_url = _get_ngc_private_bundle_url(model_name=filename, version=version, repo=repo)
if has_requests:
headers = {} if headers is None else headers
Expand Down Expand Up @@ -491,7 +502,7 @@ def download(
url: url to download the data. If not `None`, data will be downloaded directly
and `source` will not be checked.
If `name` is `None`, filename is determined by `monai.apps.utils._basename(url)`.
remove_prefix: This argument is used when `source` is "ngc". Currently, all ngc bundles
remove_prefix: This argument is used when `source` is "ngc" or "ngc_private". Currently, all ngc bundles
have the ``monai_`` prefix, which is not existing in their model zoo contrasts. In order to
maintain the consistency between these two sources, remove prefix is necessary.
Therefore, if specified, downloaded folder name will remove the prefix.
Expand Down

0 comments on commit ae5a04d

Please sign in to comment.