Commit 5e6bb054 authored by Andrei-Claudiu Roibu's avatar Andrei-Claudiu Roibu 🖥
Browse files

added masking to eval path, eliminated batch option, set min_max to none in loading

parent 31c05c0c
......@@ -309,7 +309,6 @@ def evaluate_mapping(mapping_evaluation_parameters):
mapping_data_file = mapping_evaluation_parameters['mapping_data_file']
data_list = mapping_evaluation_parameters['data_list']
prediction_output_path = mapping_evaluation_parameters['prediction_output_path']
batch_size = mapping_evaluation_parameters['batch_size']
device = mapping_evaluation_parameters['device']
exit_on_error = mapping_evaluation_parameters['exit_on_error']
......@@ -318,7 +317,6 @@ def evaluate_mapping(mapping_evaluation_parameters):
mapping_data_file,
data_list,
prediction_output_path,
batch_size,
device=device,
exit_on_error=exit_on_error)
......
......@@ -4,6 +4,5 @@ data_directory = "/well/win-biobank/projects/imaging/data/data3/subjectsAll/"
mapping_data_file = "dMRI/autoptx_preproc/tractsNormSummed.nii.gz"
data_list = "datasets/test.txt"
prediction_output_path = "network_predictions"
batch_size = 1
device = 0
exit_on_error = True
\ No newline at end of file
......@@ -206,7 +206,6 @@ def evaluate_mapping(trained_model_path,
mapping_data_file,
data_list,
prediction_output_path,
batch_size,
device=0,
mode='evaluate',
exit_on_error=False):
......@@ -220,7 +219,6 @@ def evaluate_mapping(trained_model_path,
mapping_data_file (str): Path to the input file
data_list (str): Path to a .txt file containing the input files for consideration
prediction_output_path (str): Output prediction path
batch_size (int): Size of batch to be evaluated
device (str/int): Device type used for training (int - GPU id, str- CPU)
mode (str): Current run mode or phase
exit_on_error (bool): Flag that triggers the raising of an exception
......@@ -272,7 +270,7 @@ def evaluate_mapping(trained_model_path,
print("Mapping Volume {}/{}".format(volume_index+1, len(file_paths)))
# Generate volume & header
_, predicted_volume, header, xform = _generate_volume_map(
file_path, model, batch_size, device, cuda_available)
file_path, model, device, cuda_available)
# Generate New Header Affine
......@@ -308,7 +306,7 @@ def evaluate_mapping(trained_model_path,
log.info("rsfMRI Generation Complete")
def _generate_volume_map(file_path, model, batch_size, device, cuda_available):
def _generate_volume_map(file_path, model, device, cuda_available):
"""rsfMRI Volume Generator
This function uses the trained model to generate a new volume
......@@ -316,7 +314,6 @@ def _generate_volume_map(file_path, model, batch_size, device, cuda_available):
Args:
file_path (str): Path to the desired file
model (class): BrainMapper model class
batch_size (int): Size of batch to be evaluated
device (str/int): Device type used for training (int - GPU id, str- CPU)
cuda_available (bool): Flag indicating if a cuda-enabled GPU is present
......@@ -337,26 +334,16 @@ def _generate_volume_map(file_path, model, batch_size, device, cuda_available):
output_volume = []
for i in range(0, len(volume), batch_size):
batch_x = volume[i: i+batch_size]
MNI152_T1_2mm_brain_mask = torch.from_numpy(Image('utils/MNI152_T1_2mm_brain_mask.nii.gz').data)
if cuda_available and (type(device) == int):
batch_x = batch_x.cuda(device)
volume = volume.cuda(device)
MNI152_T1_2mm_brain_mask = MNI152_T1_2mm_brain_mask.cuda(device)
output = model(batch_x)
output_volume.append(output)
output = model(volume)
output = torch.mul(output, MNI152_T1_2mm_brain_mask)
output_volume = torch.cat(output_volume)
predicted_volume = output_volume
# _, predicted_volume = torch.max(output_volume, dim=1)
# This needs to be checked - torch.max returns max values and locations.
# For segmentations, we are interested in the locations
# For the functional data, we might be interested in the actual values.
# The strength of the value represents the strength of the activation
# A threshold might also be required!
predicted_volume = output
predicted_volume = (predicted_volume.cpu().numpy()).astype('float32')
predicted_volume = np.squeeze(predicted_volume)
......
......@@ -439,7 +439,7 @@ def set_orientation(volume, label_map, orientation):
"Orientation value is invalid. It must be either >>coronal<<, >>axial<< or >>sagital<< ")
def load_and_preprocess_evaluation(file_path, min_max=False):
def load_and_preprocess_evaluation(file_path, min_max=None):
"""Load & Preprocessing before evaluation
This function loads a nifty file and returns its volume and header information
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment