From a0a02bfc7c761cfbd04b8316e2e0004240b97f19 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 9 Oct 2024 23:26:51 +0200 Subject: [PATCH 1/7] Specify package versions that work together --- requirements.txt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index b0b1d93..8162c2f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,10 @@ -numpy -torch -monai -tqdm -lungmask -pytest -pytest-cov +numpy==1.26.2 +torch==2.4.1 +monai==1.3.2 +tqdm==4.66.5 +lungmask==0.2.20 +pytest==8.3.3 +pytest-cov==5.0.0 +requests==2.32.3 +nibabel==5.3.0 +scikit-image==0.24.0 \ No newline at end of file From ffba7f38753111b6f4d31ce0b16cc0916bf594e6 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 9 Oct 2024 23:28:41 +0200 Subject: [PATCH 2/7] Update paths to assets to align with current asset pathing scheme --- assets/readme.md | 2 +- synthlung/__main__.py | 8 ++++---- synthlung/utils/dataset_formatter.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/assets/readme.md b/assets/readme.md index 02f4034..72ff64d 100644 --- a/assets/readme.md +++ b/assets/readme.md @@ -4,7 +4,7 @@ 1. Install synthlung by running `pip install .` 2. Download the MSD Lung Tumor dataset from [here](https://drive.google.com/drive/folders/1HqEgzS8BV2c7xYNrZdEAnrHk7osJJ--2). -3. Extract the zip file into `/assets/`. +3. Extract the zip file into `/assets/images/`. 4. Run `synthlung format --dataset msd` to adjust dataset format 5. Run `synthlung seed --dataset msd` to extract tumor seeds from the dataset 6. Run `synthlung host --dataset msd` to extract lung masks from the images diff --git a/synthlung/__main__.py b/synthlung/__main__.py index 890ac88..3f94991 100644 --- a/synthlung/__main__.py +++ b/synthlung/__main__.py @@ -7,7 +7,7 @@ import json def seed(): - json_file_path = "./assets/source/dataset.json" + json_file_path = "./assets/images/source/dataset.json" with open(json_file_path, 'r') as json_file: image_dict = json.load(json_file) @@ -23,11 +23,11 @@ def format_msd(): def generate_randomized_tumors(): tumor_inserter = InsertTumorPipeline() - json_file_path = "./assets/source/dataset.json" + json_file_path = "./assets/images/source/dataset.json" with open(json_file_path, 'r') as json_file: image_dict = json.load(json_file) - json_seed_path = "./assets/seeds/dataset.json" + json_seed_path = "./assets/images/seeds/dataset.json" with open(json_seed_path, 'r') as json_file: seeds_dict = json.load(json_file) @@ -36,7 +36,7 @@ def generate_randomized_tumors(): def mask_hosts(): lung_masker = LMInferer() host_masker = LungMaskPipeline(lung_masker) - json_file_path = "./assets/source/dataset.json" + json_file_path = "./assets/images/source/dataset.json" with open(json_file_path, 'r') as json_file: image_dict = json.load(json_file) diff --git a/synthlung/utils/dataset_formatter.py b/synthlung/utils/dataset_formatter.py index c7719a0..62ef095 100644 --- a/synthlung/utils/dataset_formatter.py +++ b/synthlung/utils/dataset_formatter.py @@ -9,7 +9,7 @@ LABEL_NII_GZ = 'label.nii.gz' class MSDImageSourceFormatter(ImageSourceFormatter, JSONGenerator): - def __init__(self, source_directory: str = "./assets/Task06_Lung/", target_directory: str = "./assets/source/") -> None: + def __init__(self, source_directory: str = "./assets/images/Task06_Lung/", target_directory: str = "./assets/images/source/") -> None: self.target_directory = target_directory self.source_directory = source_directory From d2b1e53798ad1fcbb8dbed9c4f4ed7fed7bfe728 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 9 Oct 2024 23:29:00 +0200 Subject: [PATCH 3/7] Specify nibabel as writer when saving cropped tumors --- synthlung/utils/tumor_isolation_pipeline.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/synthlung/utils/tumor_isolation_pipeline.py b/synthlung/utils/tumor_isolation_pipeline.py index 4eb0543..f87ad78 100644 --- a/synthlung/utils/tumor_isolation_pipeline.py +++ b/synthlung/utils/tumor_isolation_pipeline.py @@ -64,14 +64,13 @@ def __call__(self, sample:dict) -> Any: class TumorCropPipeline(object): - monai.config.BACKEND = "Nibabel" def __init__(self) -> None: self.compose = Compose([ LoadImaged(keys=['image', 'label'], image_only = False), TumorSeedIsolationd(image_key='image', label_key='label', image_output_key='seed_image', label_output_key='seed_label'), RenameSourceToSeed(meta_dict_keys=['seed_image_meta_dict', 'seed_label_meta_dict']), - SaveImaged(keys=['seed_image'], output_dir='./assets/seeds/', output_postfix='', separate_folder=False), - SaveImaged(keys=['seed_label'], output_dir='./assets/seeds/', output_postfix='', separate_folder=False) + SaveImaged(keys=['seed_image'], output_dir='./assets/seeds/', output_postfix='', separate_folder=False, writer=monai.data.NibabelWriter), + SaveImaged(keys=['seed_label'], output_dir='./assets/seeds/', output_postfix='', separate_folder=False, writer=monai.data.NibabelWriter) ]) def __call__(self, image_dict) -> None: From ac6ef63089aa64c434f616bffb1f152c91479806 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 9 Oct 2024 23:38:58 +0200 Subject: [PATCH 4/7] Specify package versions for Setup.py --- setup.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 4208217..e2a2cd8 100644 --- a/setup.py +++ b/setup.py @@ -10,11 +10,16 @@ packages=setuptools.find_packages(), entry_points={"console_scripts": ["synthlung = synthlung.__main__:main"]}, install_requires=[ - "numpy", - "torch", - "tqdm", - "monai", - "lungmask" + "numpy==1.26.2", + "torch==2.4.1", + "tqdm==4.66.5", + "monai==1.3.2", + "lungmask==0.2.20", + "pytest==8.3.3", + "pytest-cov==5.0.0", + "requests==2.32.3", + "nibabel==5.3.0", + "scikit-image==0.24.0" ], classifiers=[ "Programming Language :: Python :: 3", From a795dd68cebcd51895da2ad748d399408b8b3581 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 11 Oct 2024 21:39:32 +0200 Subject: [PATCH 5/7] Fix directory paths for tumor isolation --- synthlung/__main__.py | 4 ++-- synthlung/utils/tumor_isolation_pipeline.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/synthlung/__main__.py b/synthlung/__main__.py index 3f94991..b7a2326 100644 --- a/synthlung/__main__.py +++ b/synthlung/__main__.py @@ -13,7 +13,7 @@ def seed(): image_dict = json.load(json_file) crop_pipeline = TumorCropPipeline() crop_pipeline(image_dict) - formatter = MSDGenerateJSONFormatter("./assets/seeds/") + formatter = MSDGenerateJSONFormatter("./assets/images/seeds/") formatter.generate_json() def format_msd(): @@ -41,7 +41,7 @@ def mask_hosts(): image_dict = json.load(json_file) host_masker(image_dict) - json_generator = HostJsonGenerator('./assets/hosts/') + json_generator = HostJsonGenerator('./assets/images/hosts/') json_generator.generate_json() def main(): diff --git a/synthlung/utils/tumor_isolation_pipeline.py b/synthlung/utils/tumor_isolation_pipeline.py index f87ad78..f8e7842 100644 --- a/synthlung/utils/tumor_isolation_pipeline.py +++ b/synthlung/utils/tumor_isolation_pipeline.py @@ -69,8 +69,8 @@ def __init__(self) -> None: LoadImaged(keys=['image', 'label'], image_only = False), TumorSeedIsolationd(image_key='image', label_key='label', image_output_key='seed_image', label_output_key='seed_label'), RenameSourceToSeed(meta_dict_keys=['seed_image_meta_dict', 'seed_label_meta_dict']), - SaveImaged(keys=['seed_image'], output_dir='./assets/seeds/', output_postfix='', separate_folder=False, writer=monai.data.NibabelWriter), - SaveImaged(keys=['seed_label'], output_dir='./assets/seeds/', output_postfix='', separate_folder=False, writer=monai.data.NibabelWriter) + SaveImaged(keys=['seed_image'], output_dir='./assets/images/seeds/', output_postfix='', separate_folder=False, writer=monai.data.NibabelWriter), + SaveImaged(keys=['seed_label'], output_dir='./assets/images/seeds/', output_postfix='', separate_folder=False, writer=monai.data.NibabelWriter) ]) def __call__(self, image_dict) -> None: From 9555b0ec67d86195c70bd2d95a0bc26ed2582ec2 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 11 Oct 2024 21:58:21 +0200 Subject: [PATCH 6/7] Fix directory pathing for lung segmentation pipeline --- synthlung/utils/lung_segmentation_pipeline.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synthlung/utils/lung_segmentation_pipeline.py b/synthlung/utils/lung_segmentation_pipeline.py index 22a75c3..e7bab19 100644 --- a/synthlung/utils/lung_segmentation_pipeline.py +++ b/synthlung/utils/lung_segmentation_pipeline.py @@ -43,7 +43,7 @@ def __init__(self, lungmask_inferer: LMInferer) -> None: self.compose = Compose([ LoadImaged(keys=['image'], image_only = False), MaskLungs(lungmask_inferer=self.inferer), - SaveImaged(keys=['mask'], output_dir='./assets/hosts/', output_postfix='', separate_folder=False) + SaveImaged(keys=['mask'], output_dir='./assets/images/hosts/', output_postfix='', separate_folder=False) ]) def __call__(self, image_dict) -> Any: @@ -63,7 +63,7 @@ def generate_json(self) -> None: for filename in os.listdir(self.path): if filename.endswith((NII_GZ_EXTENSION)): sample_data = { - "host_image": "./assets/source/msd/" + (filename[:filename.index(LABEL_NII_GZ)] + IMAGE_NII_GZ).replace('host_', 'source_'), + "host_image": "./assets/source/hosts/" + (filename[:filename.index(LABEL_NII_GZ)] + IMAGE_NII_GZ).replace('host_', 'source_'), "host_label": self.path + filename } dataset_json.append(sample_data) From f9559a673604574f9922470fbfadd99f1cfdf1be Mon Sep 17 00:00:00 2001 From: = Date: Fri, 11 Oct 2024 22:04:08 +0200 Subject: [PATCH 7/7] Fix pathing in the created dataset file --- synthlung/utils/lung_segmentation_pipeline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synthlung/utils/lung_segmentation_pipeline.py b/synthlung/utils/lung_segmentation_pipeline.py index e7bab19..6877e7a 100644 --- a/synthlung/utils/lung_segmentation_pipeline.py +++ b/synthlung/utils/lung_segmentation_pipeline.py @@ -63,7 +63,7 @@ def generate_json(self) -> None: for filename in os.listdir(self.path): if filename.endswith((NII_GZ_EXTENSION)): sample_data = { - "host_image": "./assets/source/hosts/" + (filename[:filename.index(LABEL_NII_GZ)] + IMAGE_NII_GZ).replace('host_', 'source_'), + "host_image": "./assets/images/hosts/" + (filename[:filename.index(LABEL_NII_GZ)] + IMAGE_NII_GZ).replace('host_', 'source_'), "host_label": self.path + filename } dataset_json.append(sample_data)