Skip to content

Commit

Permalink
change error in loadsave and nifti in nib
Browse files Browse the repository at this point in the history
  • Loading branch information
camillebrianceau committed Jun 4, 2024
1 parent efd771a commit 0506855
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions clinicadl/predict/predict_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,15 +565,17 @@ def _compute_output_nifti(
output = model(x)
output = output.squeeze(0).detach().cpu().float()
# Convert tensor to nifti image with appropriate affine
input_nii = nib.Nifti1Image(image[0].detach().cpu().numpy(), eye(4))
output_nii = nib.Nifti1Image(output[0].numpy(), eye(4))
input_nii = nib.nifti1.Nifti1Image(
image[0].detach().cpu().numpy(), eye(4)
)
output_nii = nib.nifti1.Nifti1Image(output[0].numpy(), eye(4))
# Create file name according to participant and session id
participant_id = data["participant_id"]
session_id = data["session_id"]
input_filename = f"{participant_id}_{session_id}_image_input.nii.gz"
output_filename = f"{participant_id}_{session_id}_image_output.nii.gz"
nib.save(input_nii, nifti_path / input_filename)
nib.save(output_nii, nifti_path / output_filename)
nib.loadsave.save(input_nii, nifti_path / input_filename)
nib.loadsave.save(output_nii, nifti_path / output_filename)

def interpret(self):
"""Performs the interpretation task on a subset of caps_directory defined in a TSV file.
Expand Down Expand Up @@ -728,8 +730,10 @@ def interpret(self):
results_path
/ f"{data['participant_id'][i]}_{data['session_id'][i]}_{self.maps_manager.mode}-{data[f'{self.maps_manager.mode}_id'][i]}_map.nii.gz"
)
output_nii = nib.Nifti1Image(map_pt[i].numpy(), eye(4))
nib.save(output_nii, single_nifti_path)
output_nii = nib.nifti1.Nifti1Image(
map_pt[i].numpy(), eye(4)
)
nib.loadsave.save(output_nii, single_nifti_path)
for i, mode_map in enumerate(cum_maps):
mode_map /= len(data_test)
torch.save(
Expand All @@ -740,8 +744,8 @@ def interpret(self):
import nibabel as nib
from numpy import eye

output_nii = nib.Nifti1Image(mode_map.numpy(), eye(4))
nib.save(
output_nii = nib.nifti1.Nifti1Image(mode_map.numpy(), eye(4))
nib.loadsave.save(
output_nii,
results_path
/ f"mean_{self.maps_manager.mode}-{i}_map.nii.gz",
Expand Down

0 comments on commit 0506855

Please sign in to comment.