From e6914bea84312cc53bbc7902b06db4f4e57cfea3 Mon Sep 17 00:00:00 2001 From: Yiheng Wang Date: Mon, 11 Sep 2023 12:19:10 +0800 Subject: [PATCH 1/3] Fix download naming issue Signed-off-by: Yiheng Wang --- monai/bundle/scripts.py | 2 +- tests/test_bundle_download.py | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index cbd6447657..50f4f8bcef 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -160,7 +160,7 @@ def _get_ngc_bundle_url(model_name: str, version: str) -> str: def _get_monaihosting_bundle_url(model_name: str, version: str) -> str: monaihosting_root_path = "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting" - return f"{monaihosting_root_path}/{model_name}/versions/{version}/files/{model_name.lower()}_v{version}.zip" + return f"{monaihosting_root_path}/{model_name.lower()}/versions/{version}/files/{model_name}_v{version}.zip" def _download_from_github(repo: str, download_path: Path, filename: str, progress: bool = True) -> None: diff --git a/tests/test_bundle_download.py b/tests/test_bundle_download.py index 0a6486bc40..35cf9d1c43 100644 --- a/tests/test_bundle_download.py +++ b/tests/test_bundle_download.py @@ -72,9 +72,9 @@ ] TEST_CASE_8 = [ - "Spleen_CT_Segmentation", - "cuda" if torch.cuda.is_available() else "cpu", - {"spatial_dims": 3, "out_channels": 5}, + ["models/model.pt", "configs/train.json"], + "renalStructures_CECT_segmentation", + "0.1.0", ] TEST_CASE_9 = [ @@ -127,7 +127,7 @@ def test_url_download_bundle(self, bundle_files, bundle_name, url, hash_val): @parameterized.expand([TEST_CASE_6]) @skip_if_quick - def test_monaihosting_download_bundle(self, bundle_files, bundle_name, url): + def test_monaihosting_url_download_bundle(self, bundle_files, bundle_name, url): with skip_if_downloading_fails(): # download a single file from url, also use `args_file` with tempfile.TemporaryDirectory() as tempdir: @@ -142,6 +142,23 @@ def test_monaihosting_download_bundle(self, bundle_files, bundle_name, url): file_path = os.path.join(tempdir, bundle_name, file) self.assertTrue(os.path.exists(file_path)) + @parameterized.expand([TEST_CASE_8]) + @skip_if_quick + def test_monaihosting_source_download_bundle(self, bundle_files, bundle_name, version): + with skip_if_downloading_fails(): + # download a single file from url, also use `args_file` + with tempfile.TemporaryDirectory() as tempdir: + def_args = {"name": bundle_name, "bundle_dir": tempdir, "version": version} + def_args_file = os.path.join(tempdir, "def_args.json") + parser = ConfigParser() + parser.export_config_file(config=def_args, filepath=def_args_file) + cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file] + cmd += ["--progress", "False", "--source", "monaihosting"] + command_line_tests(cmd) + for file in bundle_files: + file_path = os.path.join(tempdir, bundle_name, file) + self.assertTrue(os.path.exists(file_path)) + class TestLoad(unittest.TestCase): @parameterized.expand([TEST_CASE_4]) @@ -210,7 +227,7 @@ def test_load_weights(self, bundle_files, bundle_name, repo, device, model_file) output_3 = model_3.forward(input_tensor) assert_allclose(output_3, expected_output, atol=1e-4, rtol=1e-4, type_test=False) - @parameterized.expand([TEST_CASE_7, TEST_CASE_8]) + @parameterized.expand([TEST_CASE_7]) @skip_if_quick def test_load_weights_with_net_override(self, bundle_name, device, net_override): with skip_if_downloading_fails(): From a659959a716e99fc27c8f1ba7a2ef87d7d3e3c3e Mon Sep 17 00:00:00 2001 From: Yiheng Wang Date: Mon, 11 Sep 2023 12:22:45 +0800 Subject: [PATCH 2/3] no need to specify source if using url Signed-off-by: Yiheng Wang --- tests/test_bundle_download.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_bundle_download.py b/tests/test_bundle_download.py index 35cf9d1c43..90bdae6449 100644 --- a/tests/test_bundle_download.py +++ b/tests/test_bundle_download.py @@ -136,7 +136,7 @@ def test_monaihosting_url_download_bundle(self, bundle_files, bundle_name, url): parser = ConfigParser() parser.export_config_file(config=def_args, filepath=def_args_file) cmd = ["coverage", "run", "-m", "monai.bundle", "download", "--args_file", def_args_file] - cmd += ["--url", url, "--progress", "False", "--source", "monaihosting"] + cmd += ["--url", url, "--progress", "False"] command_line_tests(cmd) for file in bundle_files: file_path = os.path.join(tempdir, bundle_name, file) From bc095994050687259c287f3303d3f242d27daf42 Mon Sep 17 00:00:00 2001 From: monai-bot Date: Mon, 11 Sep 2023 04:51:22 +0000 Subject: [PATCH 3/3] [MONAI] code formatting Signed-off-by: monai-bot --- tests/test_bundle_download.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/test_bundle_download.py b/tests/test_bundle_download.py index 90bdae6449..89dea8e653 100644 --- a/tests/test_bundle_download.py +++ b/tests/test_bundle_download.py @@ -71,11 +71,7 @@ {"spatial_dims": 3, "out_channels": 5}, ] -TEST_CASE_8 = [ - ["models/model.pt", "configs/train.json"], - "renalStructures_CECT_segmentation", - "0.1.0", -] +TEST_CASE_8 = [["models/model.pt", "configs/train.json"], "renalStructures_CECT_segmentation", "0.1.0"] TEST_CASE_9 = [ ["network.json", "test_output.pt", "test_input.pt", "large_files.yaml"],