Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion monai/transforms/croppad/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from typing import Any, Callable, Dict, Hashable, List, Mapping, Optional, Sequence, Tuple, Union

import numpy as np
import torch

from monai.config import IndexSelection, KeysCollection
from monai.config.type_definitions import NdarrayOrTensor
Expand Down Expand Up @@ -315,7 +316,10 @@ def inverse(self, data: Mapping[Hashable, NdarrayOrTensor]) -> Dict[Hashable, Nd
for key in self.key_iterator(d):
transform = self.get_most_recent_transform(d, key)
# Create inverse transform
orig_size = np.array(transform[TraceKeys.ORIG_SIZE])
orig_size = transform[TraceKeys.ORIG_SIZE]
if isinstance(orig_size[0], torch.Tensor):
orig_size = torch.as_tensor(orig_size)
orig_size = np.asarray(orig_size)

@Nic-Ma Nic-Ma Dec 1, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rijobro ,

I think maybe you can simply use the convert_data_type utility here to convert to numpy array with wrap_sequence arg?

Thanks.

current_size = np.array(d[key].shape[1:])
roi_start = np.floor((current_size - orig_size) / 2)
roi_end = orig_size + roi_start
Expand Down