Skip to content

Commit 5b9d24e

Browse files
6962 Fix bundle download naming issue (#6969)
Fixes #6962 . ### Description This PR is used to fix the bundle download issue if using monaihosting source. Detailed information is attached in #6962 . ### 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). - [x] 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 <vennw@nvidia.com> Signed-off-by: monai-bot <monai.miccai2019@gmail.com> Co-authored-by: monai-bot <monai.miccai2019@gmail.com>
1 parent 339292c commit 5b9d24e

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

monai/bundle/scripts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def _get_ngc_bundle_url(model_name: str, version: str) -> str:
160160

161161
def _get_monaihosting_bundle_url(model_name: str, version: str) -> str:
162162
monaihosting_root_path = "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting"
163-
return f"{monaihosting_root_path}/{model_name}/versions/{version}/files/{model_name.lower()}_v{version}.zip"
163+
return f"{monaihosting_root_path}/{model_name.lower()}/versions/{version}/files/{model_name}_v{version}.zip"
164164

165165

166166
def _download_from_github(repo: str, download_path: Path, filename: str, progress: bool = True) -> None:

tests/test_bundle_download.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,7 @@
7171
{"spatial_dims": 3, "out_channels": 5},
7272
]
7373

74-
TEST_CASE_8 = [
75-
"Spleen_CT_Segmentation",
76-
"cuda" if torch.cuda.is_available() else "cpu",
77-
{"spatial_dims": 3, "out_channels": 5},
78-
]
74+
TEST_CASE_8 = [["models/model.pt", "configs/train.json"], "renalStructures_CECT_segmentation", "0.1.0"]
7975

8076
TEST_CASE_9 = [
8177
["network.json", "test_output.pt", "test_input.pt", "large_files.yaml"],
@@ -127,7 +123,7 @@ def test_url_download_bundle(self, bundle_files, bundle_name, url, hash_val):
127123

128124
@parameterized.expand([TEST_CASE_6])
129125
@skip_if_quick
130-
def test_monaihosting_download_bundle(self, bundle_files, bundle_name, url):
126+
def test_monaihosting_url_download_bundle(self, bundle_files, bundle_name, url):
131127
with skip_if_downloading_fails():
132128
# download a single file from url, also use `args_file`
133129
with tempfile.TemporaryDirectory() as tempdir:
@@ -136,7 +132,24 @@ def test_monaihosting_download_bundle(self, bundle_files, bundle_name, url):
136132
parser = ConfigParser()
137133
parser.export_config_file(config=def_args, filepath=def_args_file)
138134
cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file]
139-
cmd += ["--url", url, "--progress", "False", "--source", "monaihosting"]
135+
cmd += ["--url", url, "--progress", "False"]
136+
command_line_tests(cmd)
137+
for file in bundle_files:
138+
file_path = os.path.join(tempdir, bundle_name, file)
139+
self.assertTrue(os.path.exists(file_path))
140+
141+
@parameterized.expand([TEST_CASE_8])
142+
@skip_if_quick
143+
def test_monaihosting_source_download_bundle(self, bundle_files, bundle_name, version):
144+
with skip_if_downloading_fails():
145+
# download a single file from url, also use `args_file`
146+
with tempfile.TemporaryDirectory() as tempdir:
147+
def_args = {"name": bundle_name, "bundle_dir": tempdir, "version": version}
148+
def_args_file = os.path.join(tempdir, "def_args.json")
149+
parser = ConfigParser()
150+
parser.export_config_file(config=def_args, filepath=def_args_file)
151+
cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file]
152+
cmd += ["--progress", "False", "--source", "monaihosting"]
140153
command_line_tests(cmd)
141154
for file in bundle_files:
142155
file_path = os.path.join(tempdir, bundle_name, file)
@@ -210,7 +223,7 @@ def test_load_weights(self, bundle_files, bundle_name, repo, device, model_file)
210223
output_3 = model_3.forward(input_tensor)
211224
assert_allclose(output_3, expected_output, atol=1e-4, rtol=1e-4, type_test=False)
212225

213-
@parameterized.expand([TEST_CASE_7, TEST_CASE_8])
226+
@parameterized.expand([TEST_CASE_7])
214227
@skip_if_quick
215228
def test_load_weights_with_net_override(self, bundle_name, device, net_override):
216229
with skip_if_downloading_fails():

0 commit comments

Comments
 (0)