Skip to content

Commit

Permalink
Add output path to LesionsAnalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
alicjak1519 committed Feb 13, 2022
1 parent 182b35a commit 5c500de
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion bayesian_cnn_prometheus/analysis/analyse_lesions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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()


Expand Down
9 changes: 5 additions & 4 deletions bayesian_cnn_prometheus/analysis/lesions_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@

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
:param input_path: path to the directory with images, lesions and segmentations labels
: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)
Expand All @@ -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:
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 5 additions & 5 deletions bayesian_cnn_prometheus/run_training_for_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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]]
}
],
}
Expand Down

0 comments on commit 5c500de

Please sign in to comment.