Skip to content

Commit

Permalink
Hard-coding postop part, renamed HGG to GBM.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbouget committed Apr 5, 2023
1 parent 6b8ce6e commit ee087a5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
4 changes: 2 additions & 2 deletions gui/SinglePatientComponent/CentralAreaExecutionWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def on_pipeline_execution(self, pipeline_code: str) -> None:
if code == 0: # Operation cancelled
return

if diag.tumor_type == 'High-Grade Glioma':
self.model_name = "MRI_HGGlioma"
if diag.tumor_type == 'Glioblastoma':
self.model_name = "MRI_GBM"
elif diag.tumor_type == 'Low-Grade Glioma':
self.model_name = "MRI_LGGlioma"
elif diag.tumor_type == 'Metastasis':
Expand Down
4 changes: 2 additions & 2 deletions gui/StudyBatchComponent/StudiesSidePanel/SingleStudyWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ def __on_run_pipeline(self) -> None:
if code == 0: # Operation was cancelled by the user
return

if diag.tumor_type == 'High-Grade Glioma':
self.model_name = "MRI_HGGlioma"
if diag.tumor_type == 'Glioblastoma':
self.model_name = "MRI_GBM"
elif diag.tumor_type == 'Low-Grade Glioma':
self.model_name = "MRI_LGGlioma"
elif diag.tumor_type == 'Metastasis':
Expand Down
4 changes: 2 additions & 2 deletions gui/UtilsWidgets/CustomQDialog/TumorTypeSelectionQDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def __init__(self, parent=None):
self.select_tumor_type_label.setStyleSheet("""QLabel{background-color: rgba(248, 248, 248, 1);}""")
self.base_layout.addWidget(self.select_tumor_type_label, 0, 0)
self.select_tumor_type_combobox = QComboBox()
self.select_tumor_type_combobox.addItems(["High-Grade Glioma", "Low-Grade Glioma", "Meningioma", "Metastasis"])
self.tumor_type = "High-Grade Glioma"
self.select_tumor_type_combobox.addItems(["Glioblastoma", "Low-Grade Glioma", "Meningioma", "Metastasis"])
self.tumor_type = "Glioblastoma"

self.base_layout.addWidget(self.select_tumor_type_combobox, 0, 1)
self.exit_accept_pushbutton = QDialogButtonBox(QDialogButtonBox.Ok)
Expand Down
31 changes: 24 additions & 7 deletions utils/logic/PipelineCreationHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ModelNameType(Enum):
"""
_init_ = 'value string'

HGGlioma = 0, 'MRI_HGGLioma'
HGGlioma = 0, 'MRI_GBM'
LGGlioma = 1, 'MRI_LGGlioma'
Meningioma = 2, 'MRI_Meningioma'
Metastasis = 3, 'MRI_Metastase'
Expand All @@ -47,6 +47,7 @@ def create_pipeline(model_name: str, patient_parameters, task: str) -> dict:
How to allow for all possible combinations of what to use/what to run/on which timestamps?
@TODO. Still heavily hard-coded atm, will need to rely only on the pipeline json files
@TODO. Postop segmentation not adapting to the number of inputs, defaulting to the 4 inputs.
Returns
-------
dict
Expand All @@ -61,14 +62,14 @@ def create_pipeline(model_name: str, patient_parameters, task: str) -> dict:
elif task == 'preop_segmentation':
return __create_segmentation_pipeline(model_name, patient_parameters)
elif task == 'postop_segmentation':
download_model(model_name='MRI_Tumor_Postop')
download_model(model_name='MRI_GBM_Postop_FV_4p')
return __create_postop_segmentation_pipeline(model_name, patient_parameters)
elif task == 'other_segmentation':
return __create_other_segmentation_pipeline(model_name, patient_parameters)
elif task == 'preop_reporting':
return __create_preop_reporting_pipeline(model_name, patient_parameters)
elif task == 'postop_reporting':
download_model(model_name='MRI_Tumor_Postop')
download_model(model_name='MRI_GBM_Postop_FV_4p')
return __create_postop_reporting_pipeline(model_name, patient_parameters)
else:
return __create_custom_pipeline(task, model_name, patient_parameters)
Expand Down Expand Up @@ -158,9 +159,15 @@ def __create_other_segmentation_pipeline(model_name, patient_parameters):

def __create_postop_segmentation_pipeline(model_name, patient_parameters):
"""
The default postop segmentation model is the one with four inputs, but based on the loaded images another fitting
model could be used.
@TODO. Ideally, in the future, the disambiguation of the best model to use should be done in the backend. In that
case, how to properly retrieve the corresponding pipeline.json?
"""
infile = open(os.path.join(SoftwareConfigResources.getInstance().models_path, "MRI_Tumor_Postop", 'pipeline.json'), 'rb')
postop_model_name = "MRI_GBM_Postop_FV_4p"
if SoftwareConfigResources.getInstance().user_preferences.use_manual_sequences:
postop_model_name = select_appropriate_postop_model(patient_parameters)
infile = open(os.path.join(SoftwareConfigResources.getInstance().models_path, postop_model_name, 'pipeline.json'), 'rb')
raw_pip = json.load(infile)

pip = {}
Expand Down Expand Up @@ -226,6 +233,7 @@ def __create_preop_reporting_pipeline(model_name, patient_parameters):
pip[pip_num]["target"] = ["Brain"]
pip[pip_num]["model"] = "MRI_Brain"
pip[pip_num]["description"] = "Brain segmentation in T1CE (T0)"
download_model("MRI_Brain")

pip_num_int = pip_num_int + 1
pip_num = str(pip_num_int)
Expand Down Expand Up @@ -493,9 +501,8 @@ def __create_postop_reporting_pipeline(model_name, patient_parameters):
pip[pip_num]["inputs"]["4"]["space"]["timestamp"] = 1
pip[pip_num]["inputs"]["4"]["space"]["sequence"] = "T1-CE"
pip[pip_num]["target"] = ["Tumor"]
pip[pip_num]["model"] = "MRI_Tumor_Postop"
pip[pip_num]["model"] = "MRI_GBM_Postop_FV_4p"
pip[pip_num]["description"] = "Tumor segmentation in T1CE (T1)"
# download_model(model_name='MRI_Tumor_Postop')

pip_num_int = pip_num_int + 1
pip_num = str(pip_num_int)
Expand Down Expand Up @@ -589,3 +596,13 @@ def __create_custom_pipeline(task, tumor_type, patient_parameters):
pip[pip_num]["description"] = k + " segmentation in T1CE (T{})".format(str(timestamp_order))
download_model(model_name=model_name)
return pip


def select_appropriate_postop_model(patient_parameters) -> str:
"""
Temporary method, which will be deported in the backend, for selecting the best postoperative glioblastoma
segmentation model based on available inputs.
"""
model_name = "MRI_GBM_Postop_FV_4p"

return model_name
6 changes: 5 additions & 1 deletion utils/models_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def download_model(model_name: str):
model_params = cloud_models_list.loc[cloud_models_list['Model'] == model_name]
url = model_params['link'].values[0]
md5 = model_params['sum'].values[0]
dep = list(model_params['dependencies'].values)
tmp_dep = model_params['dependencies'].values[0]
dep = list(tmp_dep.strip().split(';')) if tmp_dep == tmp_dep else []
models_path = os.path.join(expanduser('~'), '.raidionics', 'resources', 'models')
os.makedirs(models_path, exist_ok=True)
models_archive_path = os.path.join(expanduser('~'), '.raidionics', 'resources', 'models',
Expand All @@ -112,6 +113,9 @@ def download_model(model_name: str):
download_state = True

if download_state:
if os.path.exists(models_archive_path):
# Just in case, deleting the old cached archive, if a new one is to be downloaded
os.remove(models_archive_path)
headers = {}

response = requests.get(url, headers=headers, stream=True)
Expand Down

0 comments on commit ee087a5

Please sign in to comment.