Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make initial training pipeline #7

Closed
wants to merge 15 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions synthlung/__main__.py
Original file line number Diff line number Diff line change
@@ -15,13 +15,13 @@
from lungmask import LMInferer

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)
crop_pipeline = TumorCropPipeline()
crop_pipeline(image_dict)
formatter = JsonSeedGenerator("./assets/seeds/")
formatter = JsonSeedGenerator("./assets/images/seeds/")
formatter.generate_json_seeds()

def format_msd():
@@ -31,11 +31,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)

@@ -50,12 +50,12 @@ 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)

host_masker(image_dict)
json_generator = HostJsonGenerator('./assets/hosts/')
json_generator = HostJsonGenerator('./assets/images/hosts/')
json_generator.generate_json()

def train(config_path):
2 changes: 1 addition & 1 deletion synthlung/utils/dataset_formatter.py
Original file line number Diff line number Diff line change
@@ -8,7 +8,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

4 changes: 2 additions & 2 deletions synthlung/utils/lung_segmentation_pipeline.py
Original file line number Diff line number Diff line change
@@ -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/images/source/msd/" + (filename[:filename.index(LABEL_NII_GZ)] + IMAGE_NII_GZ).replace('host_', 'source_'),
"host_label": self.path + filename
}
dataset_json.append(sample_data)
2 changes: 1 addition & 1 deletion synthlung/utils/tumor_insertion_pipeline.py
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ class InsertTumorPipeline(object):
def __init__(self) -> None:
self.randomized_dict = []
self.time = f"{datetime.datetime.now()}".replace(" ", "-").replace(":", ".")
self.dir_name = f"./assets/artificial_tumors/{self.time}/"
self.dir_name = f"./assets/images/artificial_tumors/{self.time}/"
self.compose = Compose([
LoadImaged(keys=['image', 'label', 'image_mask', 'seed_image', 'seed_label']),
InsertTumor(),
4 changes: 2 additions & 2 deletions synthlung/utils/tumor_isolation_pipeline.py
Original file line number Diff line number Diff line change
@@ -70,8 +70,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),
SaveImaged(keys=['seed_label'], output_dir='./assets/seeds/', output_postfix='', separate_folder=False)
SaveImaged(keys=['seed_image'], output_dir='./assets/images/seeds/', output_postfix='', separate_folder=False),
SaveImaged(keys=['seed_label'], output_dir='./assets/images/seeds/', output_postfix='', separate_folder=False)
])

def __call__(self, image_dict) -> None: