Skip to content

Commit f63cc5e

Browse files
Fix image dimension handling and enable verbose logging in get_nnunet_monai_predictor
1 parent a50ef4c commit f63cc5e

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

monai/apps/nnunet/nnunet_bundle.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ def forward(self, x: MetaTensor) -> MetaTensor:
291291
raise TypeError("Input must be a MetaTensor or a tuple of MetaTensors.")
292292

293293
image_or_list_of_images = x.cpu().numpy()[0, :]
294+
image_or_list_of_images = np.transpose(image_or_list_of_images, (0, 3, 2, 1))
295+
properties_or_list_of_properties["spacing"] = properties_or_list_of_properties["spacing"][::-1]
294296

295297
# input_files should be a list of file paths, one per modality
296298
prediction_output = self.predictor.predict_from_list_of_npy_arrays( # type: ignore
@@ -308,7 +310,7 @@ def forward(self, x: MetaTensor) -> MetaTensor:
308310
for out in prediction_output: # Add batch and channel dimensions
309311
out_tensors.append(torch.from_numpy(np.expand_dims(np.expand_dims(out, 0), 0)))
310312
out_tensor = torch.cat(out_tensors, 0) # Concatenate along batch dimension
311-
313+
out_tensor = out_tensor.permute(0, 1, 4, 3, 2)
312314
return MetaTensor(out_tensor, meta=x.meta)
313315

314316

@@ -363,8 +365,8 @@ def get_nnunet_monai_predictor(model_folder: Union[str, Path], model_name: str =
363365
use_gaussian=True,
364366
use_mirroring=False,
365367
device=torch.device("cuda", 0),
366-
verbose=False,
367-
verbose_preprocessing=False,
368+
verbose=True,
369+
verbose_preprocessing=True,
368370
allow_tqdm=True,
369371
)
370372
# initializes the network architecture, loads the checkpoint

0 commit comments

Comments
 (0)