Skip to content

check if orig_size is list of tensors#3422

Closed
rijobro wants to merge 1 commit into
Project-MONAI:devfrom
rijobro:inverse_divisible_pad
Closed

check if orig_size is list of tensors#3422
rijobro wants to merge 1 commit into
Project-MONAI:devfrom
rijobro:inverse_divisible_pad

Conversation

@rijobro

@rijobro rijobro commented Nov 30, 2021

Copy link
Copy Markdown
Contributor

Sometimes after the dataloader, transform[TraceKeys.ORIG_SIZE] is given as a list of torch.Tensor. Calling np.asarray on this will return a numpy array containing a list (dtype=object), which causes problems. This fix will convert to a single torch.Tensor if necessary and then convert that to a numpy array.

I'm not quite sure the best way to add a test for this. I suspect all our inverses should also be run through the DataLoader, maybe with and EnsureType at the end to simulate the numpy->torch conversion that we normally experience.

Status

Ready

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).

Signed-off-by: Richard Brown <33289025+rijobro@users.noreply.github.com>
@rijobro rijobro requested review from Nic-Ma and wyli November 30, 2021 14:50
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.

@wyli wyli closed this in #3782 Feb 10, 2022
@wyli wyli reopened this Feb 10, 2022
@rijobro rijobro closed this May 19, 2022
@rijobro rijobro deleted the inverse_divisible_pad branch May 19, 2022 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants