Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if orig_size is list of tensors #3422

Closed
wants to merge 1 commit into from

Conversation

rijobro
Copy link
Contributor

@rijobro rijobro commented Nov 30, 2021

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 wyli and Nic-Ma 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)
Copy link
Contributor

@Nic-Ma Nic-Ma Dec 1, 2021

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.

None yet

3 participants