Skip to content

[Feature] Create a Squeeze transform and update Unsqueeze transform #408

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

Merged
merged 4 commits into from
Sep 9, 2022

Conversation

reachsumit
Copy link
Contributor

Description

Create a Squeeze transform and update Unsqueeze transform

Motivation and Context

This code change is targeted to address the issue#393. "Create a Squeeze transform from the Unsqueeze transform".
close #393

Types of changes

  • [x ] New feature (non-breaking change which adds core functionality)

Changes made:

  • Implemented an inverse operation for Unsqueeze that would squeeze the input.
  • Implemented a Squeeze transform that would be the flipped version of the unsqueeze.
  • Wrote 3 tests: 1 for the unsqueeze inverse operation, one for the squeeze forward, and one for the squeeze inverse.
  • Applied appropriate spec transformations if action is in the keys_inv_in and for all the keys in input_spec.

No pre-commit or pytest issues.

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • [x ] I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • [ x] I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 8, 2022
Copy link
Collaborator

@vmoens vmoens left a comment

Choose a reason for hiding this comment

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

LGTM
I changed the gym version to provisionally fix the CI, let's see if tests pass!
I'll give it a deeper look then and approve in case it works ok :)

@@ -1032,12 +1032,13 @@ def __repr__(self) -> str:


class UnsqueezeTransform(Transform):
"""Flatten adjacent dimensions of a tensor.
"""Inserts a dimension of size one at the specified position.
Copy link
Collaborator

Choose a reason for hiding this comment

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

good catch 😅 damn copy paste!

@vmoens vmoens added the enhancement New feature or request label Sep 9, 2022

unsqueeze.inv(td)

expected_size = [*size, nchannels, 16, 16]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: we could create the torch.Size here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for looking into this. 'torch.Size' object doesn't seem to support item deletion, which is conditionally required on line 481.

@vmoens vmoens merged commit c648a19 into pytorch:main Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Create a Squeeze transform from the Unsqueeze transform
3 participants