From 5c500deeb0eee2a24ee06dccb27bc0cc38f69c87 Mon Sep 17 00:00:00 2001 From: alicjak1519 Date: Sun, 13 Feb 2022 10:50:05 +0100 Subject: [PATCH] Add output path to LesionsAnalyzer --- bayesian_cnn_prometheus/analysis/analyse_lesions.py | 3 ++- bayesian_cnn_prometheus/analysis/lesions_analyzer.py | 9 +++++---- .../evaluation/bayesian_model_evaluator.py | 1 - .../run_training_for_experiments.py | 10 +++++----- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bayesian_cnn_prometheus/analysis/analyse_lesions.py b/bayesian_cnn_prometheus/analysis/analyse_lesions.py index 26b046b..e1e8013 100644 --- a/bayesian_cnn_prometheus/analysis/analyse_lesions.py +++ b/bayesian_cnn_prometheus/analysis/analyse_lesions.py @@ -10,6 +10,7 @@ def analyse_lesions(): model_path = sys.argv[1] config_path = sys.argv[2] input_path = sys.argv[3] + output_path = sys.argv[4] patients_to_analysis = [3, 4, 5, 6, 8, 10, 11, 14, 17, 21, 26, 27, 29, 30, 32, 34, 35, 36, 37, 39, 41] @@ -19,7 +20,7 @@ def analyse_lesions(): stride=model_config['preprocessing']['create_chunks']['stride'], mc_sample=model_config['mc_samples']) - lesions_analyzer = LesionsAnalyzer(model_path, input_path, prediction_options, patients_to_analysis) + lesions_analyzer = LesionsAnalyzer(model_path, input_path, prediction_options, patients_to_analysis, output_path) lesions_analyzer.run_analysis() diff --git a/bayesian_cnn_prometheus/analysis/lesions_analyzer.py b/bayesian_cnn_prometheus/analysis/lesions_analyzer.py index 5c7c55e..1090ef4 100644 --- a/bayesian_cnn_prometheus/analysis/lesions_analyzer.py +++ b/bayesian_cnn_prometheus/analysis/lesions_analyzer.py @@ -16,7 +16,7 @@ class LesionsAnalyzer: def __init__(self, model_path: str, input_path: str, prediction_options: PredictionOptions, - patients_to_analysis: List[int] = None): + patients_to_analysis: List[int] = None, output_path: str = None): """ Creates LesionsAnalyzer instance. :param model_path: path to the model in h5 form @@ -24,10 +24,11 @@ def __init__(self, model_path: str, input_path: str, prediction_options: Predict :param prediction_options: parameters for prediction :param patients_to_analysis: indices of patients to perform analysis on them, if None - every patient in the input dir will be analyzed + :param output_path: path to the dir where output should be saved """ self.model_path = model_path self.input_path = input_path - self.output_path = os.path.join(input_path, Paths.RESULTS_DIR) + self.output_path = output_path or os.path.join(input_path, Paths.RESULTS_DIR) self.prediction_options = prediction_options self.patients_to_analysis = patients_to_analysis self.model_evaluator = BayesianModelEvaluator(self.model_path, prediction_options.chunk_size) @@ -36,7 +37,7 @@ def __init__(self, model_path: str, input_path: str, prediction_options: Predict def run_analysis(self): for image_path in tqdm(glob.glob(os.path.join(self.input_path, Paths.IMAGES_DIR, '*.nii.gz'))): - patient_idx = get_patient_index(image_path) + patient_idx = int(get_patient_index(image_path)) if self.patients_to_analysis: if patient_idx not in self.patients_to_analysis: @@ -47,7 +48,7 @@ def run_analysis(self): .format(f'{patient_idx:0>4}', 'nii.gz')) mask_path = os.path.join(self.input_path, Paths.MASKS_DIR, str(Paths.MASK_FILE_PATTERN).format(f'{patient_idx:0>4}', 'nii.gz')) - variance_path = os.path.join(self.input_path, Paths.RESULTS_DIR, + variance_path = os.path.join(self.output_path, str(Paths.VARIANCE_FILE_PATTERN).format(f'{patient_idx:0>4}', 'nii.gz')) nifti = nib.load(image_path) diff --git a/bayesian_cnn_prometheus/evaluation/bayesian_model_evaluator.py b/bayesian_cnn_prometheus/evaluation/bayesian_model_evaluator.py index 965cc72..363207b 100644 --- a/bayesian_cnn_prometheus/evaluation/bayesian_model_evaluator.py +++ b/bayesian_cnn_prometheus/evaluation/bayesian_model_evaluator.py @@ -138,7 +138,6 @@ def binarize_prediction(self, mean_prediction: np.ndarray) -> np.ndarray: mean_prediction = mean_prediction.copy() mean_prediction = mean_prediction * 255 mean_prediction = mean_prediction.astype(np.uint8) - max_value = np.max(mean_prediction) for i in range(mean_prediction.shape[0]): im_slice = mean_prediction[i] diff --git a/bayesian_cnn_prometheus/run_training_for_experiments.py b/bayesian_cnn_prometheus/run_training_for_experiments.py index ae8a570..8155b19 100644 --- a/bayesian_cnn_prometheus/run_training_for_experiments.py +++ b/bayesian_cnn_prometheus/run_training_for_experiments.py @@ -12,7 +12,7 @@ from bayesian_cnn_prometheus.constants import Paths -EXPERIMENTS_DIR = Path('experiments') / 'control_group' +EXPERIMENTS_DIR = Path('experiments_hp50') EXPERIMENTS_DIR = str(EXPERIMENTS_DIR) @@ -144,14 +144,14 @@ def parse(): 'name': 'chunk_change', 'overrides': [ { - 'alias': 's', + 'alias': 'cs', 'key': 'preprocessing.create_chunks.chunk_size', - 'values': [[128, 16, 16]] + 'values': [[64, 32, 32]] }, { - 'alias': 'cs', + 'alias': 's', 'key': 'preprocessing.create_chunks.stride', - 'values': [[64, 16, 16]] + 'values': [[64, 32, 32]] } ], }