Ejemplo n.º 1
0
    def test_actions(self):
        testing_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                   "testing_data")
        url = "https://drive.google.com/uc?id=13MhoPsNgI6qboJfLicFf_jNvsFUbIYsd"
        filepath = os.path.join(testing_dir, "MedNIST.tar.gz")
        output_dir = testing_dir
        md5_value = "0bc7306e7427e00ad1c5526a6677552d"
        try:
            download_and_extract(url, filepath, output_dir, md5_value)
            download_and_extract(url, filepath, output_dir, md5_value)
        except (ContentTooShortError, HTTPError, RuntimeError) as e:
            print(str(e))
            if isinstance(e, RuntimeError):
                # FIXME: skip MD5 check as current downloading method may fail
                self.assertTrue(str(e).startswith("md5 check"))
            return  # skipping this test due the network connection errors

        wrong_md5 = "0"
        try:
            download_url(url, filepath, wrong_md5)
        except (ContentTooShortError, HTTPError, RuntimeError) as e:
            print(str(e))
            if isinstance(e, RuntimeError):
                # FIXME: skip MD5 check as current downloading method may fail
                self.assertTrue(str(e).startswith("md5 check"))
            return  # skipping this test due the network connection errors

        try:
            extractall(filepath, output_dir, wrong_md5)
        except RuntimeError as e:
            self.assertTrue(str(e).startswith("md5 check"))
Ejemplo n.º 2
0
    def test_actions(self):
        testing_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                   "testing_data")
        config_dict = testing_data_config("images", "mednist")
        url = config_dict["url"]
        filepath = Path(testing_dir) / "MedNIST.tar.gz"
        output_dir = Path(testing_dir)
        hash_val, hash_type = config_dict["hash_val"], config_dict["hash_type"]
        with skip_if_downloading_fails():
            download_and_extract(url,
                                 filepath,
                                 output_dir,
                                 hash_val=hash_val,
                                 hash_type=hash_type)
            download_and_extract(url,
                                 filepath,
                                 output_dir,
                                 hash_val=hash_val,
                                 hash_type=hash_type)

        wrong_md5 = "0"
        with self.assertLogs(logger="monai.apps", level="ERROR"):
            try:
                download_url(url, filepath, wrong_md5)
            except (ContentTooShortError, HTTPError, RuntimeError) as e:
                if isinstance(e, RuntimeError):
                    # FIXME: skip MD5 check as current downloading method may fail
                    self.assertTrue(str(e).startswith("md5 check"))
                return  # skipping this test due the network connection errors

        try:
            extractall(filepath, output_dir, wrong_md5)
        except RuntimeError as e:
            self.assertTrue(str(e).startswith("md5 check"))
    def test_actions(self):
        tempdir = tempfile.mkdtemp()
        url = "https://www.dropbox.com/s/5wwskxctvcxiuea/MedNIST.tar.gz?dl=1"
        filepath = os.path.join(tempdir, "MedNIST.tar.gz")
        output_dir = tempdir
        md5_value = "0bc7306e7427e00ad1c5526a6677552d"
        try:
            download_and_extract(url, filepath, output_dir, md5_value)
            download_and_extract(url, filepath, output_dir, md5_value)
        except (ContentTooShortError, HTTPError):
            pass  # ignore remote errors in this test

        wrong_md5 = "0"
        try:
            download_url(url, filepath, wrong_md5)
        except RuntimeError as e:
            self.assertTrue(str(e).startswith("MD5 check"))

        shutil.rmtree(os.path.join(tempdir, "MedNIST"))
        try:
            extractall(filepath, output_dir, wrong_md5)
        except RuntimeError as e:
            self.assertTrue(str(e).startswith("MD5 check"))

        shutil.rmtree(tempdir)
Ejemplo n.º 4
0
def run_main():
    dataset_file = os.path.join(TEST_DATA, "dataset.zip")
    dataset_url = "https://github.com/Project-MONAI/MONAILabel/releases/download/data/test_dataset.zip"
    if not os.path.exists(os.path.join(TEST_DATA, "dataset")):
        if not os.path.exists(dataset_file):
            download_url(url=dataset_url, filepath=dataset_file)
        extractall(filepath=dataset_file, output_dir=TEST_DATA)
os.makedirs(res_dir, exist_ok=True)
trained_model_path = os.path.join(res_dir, "net_key_metric=0.7314.pt")

if not os.path.exists(trained_model_path):
    resource = "https://github.com/Thibault-Pelletier/MonaiWorkshop/raw/e29cdaa46e0097db909478e95c001d303ae963ab/results/net_key_metric%3D0.7314.pt"
    download_url(url=resource, filepath=trained_model_path)

# Download data if necessary
resource = "https://drive.google.com/uc?id=1aMc9eW_fGCphGBjAKDedxu8-aJVcSczd"  # Full 2.9 GB dataset
# resource = "https://drive.google.com/uc?id=1rZwPR3CFlFmYTev2YkxTJDfmLrbCiy63"  # Small 200 MB dataset subset

compressed_file = os.path.join(root_dir, "brats2015 - data.zip")
if not os.path.exists(data_dir):
    os.makedirs(data_dir)
    download_url(url=resource, filepath=compressed_file)
    extractall(filepath=compressed_file, output_dir=data_dir)

# Set dataset path
train_dirs = [
    os.path.join(data_dir, "train", "HGG"),
    os.path.join(data_dir, "train", "LGG")
]
test_dir = os.path.join(data_dir, "test", "HGG_LGG")

data_dicts = []
for train_dir in train_dirs:
    test_folders = os.listdir(train_dir)

    for test_folder in test_folders:
        test_folder_path = os.path.join(train_dir, test_folder)
        data_files = os.listdir(test_folder_path)