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

Fix for #409 #673

Merged
merged 2 commits into from
Dec 4, 2018
Merged

Fix for #409 #673

merged 2 commits into from
Dec 4, 2018

Conversation

varunagrawal
Copy link
Contributor

@varunagrawal varunagrawal commented Dec 1, 2018

Fix for #409

  • Added separate checks for dimensionality.
  • Fixed bug where check for 2D numpy array passes but there is channel dimension indexing later on.
  • Added tests.

@varunagrawal
Copy link
Contributor Author

@alykhantejani can you please review this.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I have a few questions and comments.

@@ -105,9 +105,17 @@ def to_pil_image(pic, mode=None):
Returns:
PIL Image: Image converted to PIL Image.
"""
if not(_is_numpy_image(pic) or _is_tensor_image(pic)):
if not(torch.is_tensor(pic) or isinstance(pic, np.ndarray)):
Copy link
Member

Choose a reason for hiding this comment

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

can we use instead isisntance(pic, torch.Tensor)? This is the recommended way now to checking if something is an instance of a Tensor or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

raise TypeError('pic should be Tensor or ndarray. Got {}.'.format(type(pic)))

elif torch.is_tensor(pic):
if pic.ndimension() != 3:
raise ValueError('pic should be 3 dimensional. Got {} dimensions.'.format(pic.ndimension()))
Copy link
Member

Choose a reason for hiding this comment

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

Can you remind me again why the code works for 2d np arrays, but not 2d tensors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The is_numpy_image function checks for both 2D and 3D arrays. I assumed this was for some other functionality and left that in to avoid breaking something else. I can add code to work for 2D tensors as well if you'd like.

Copy link
Member

Choose a reason for hiding this comment

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

I see. But there was a bug before for 2d arrays, right?

Copy link
Contributor Author

@varunagrawal varunagrawal Dec 4, 2018

Choose a reason for hiding this comment

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

I don't think so. The bug has been for 2D tensors - we get a TypeError exception. There was functionality for 2D arrays before this PR.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

Thanks!

@fmassa fmassa merged commit 2d493d6 into pytorch:master Dec 4, 2018
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.

2 participants