Skip to content

readd functional transforms API to prototype #5295

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

Conversation

pmeier
Copy link
Collaborator

@pmeier pmeier commented Jan 27, 2022

This re-adds the functional API to the prototype transforms. They are not yet compatible with the transforms. That will come in a follow-up PR.

Design principles:

  • Every kernel has to be jit.scriptable
  • Pillow is no longer supported. Note this only applies to the low level kernels. There will be another layer on top, i.e. a higher level functional API, that will preserve BC.
  • Every kernel needs to work on vanilla tensors
  • Kernels can make assumptions on the tensor data, i.e. requiring bounding boxes in XYXY format
  • Kernels that implement the same transform for different feature types should use the transform name suffixed by the feature type in snake case, e.g. horizontal_flip_image and horizontal_flip_bounding_box.
  • Kernels that implement the same transform for different feature types should use the same parameters as much as possible.

In the current state, this PR only adds a few non-image kernels and imports most image kernels from the stable implementation.

@facebook-github-bot
Copy link

facebook-github-bot commented Jan 27, 2022

💊 CI failures summary and remediations

As of commit a77bf1f (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@pmeier pmeier changed the title Transforms/readd functional readd functional transforms API to prototype Jan 27, 2022
@pmeier pmeier requested a review from NicolasHug January 27, 2022 08:49
Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks @pmeier , only took a very brief look

Comment on lines +189 to +190
for kernel_info in KERNEL_INFOS
for idx, sample_input in enumerate(kernel_info.sample_inputs())
Copy link
Member

Choose a reason for hiding this comment

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

instead of the 2 manual for loops could we simply use 2 @parametrize statements?

Also, is there stark difference between passing idx instead of relying on pytest's default ids?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

instead of the 2 manual for loops could we simply use 2 @parametrize statements?

We can't use two separate parametrizations, since the inner loop depends on the outer.

Also, is there stark difference between passing idx instead of relying on pytest's default ids?

Let's look into this more after #5295 (comment).

yield make_bounding_box(format=format, extra_dims=extra_dims_)


class SampleInput:
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain why we need this class?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The other option would be for a simple inputs function to return ((...), dict(...)) to bundle args and kwargs. IMO this is not as convenient as having a single structure to hold everything. To me

yield SampleInput(bounding_box, old_image_size=bounding_box.image_size, new_image_size=new_image_size)

is more readable than

yield (bounding_box,), dict(old_image_size=bounding_box.image_size, new_image_size=new_image_size)

given that it resembles the actual call signature.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Plus, I was looking into lazily loading the samples. This is not implemented yet, so we are generating all samples at test collection time. This can become an issue real quick if we go along this automated tests direction.

Comment on lines +41 to +42
# import at runtime to avoid cyclic imports
from torchvision.prototype.transforms.functional import convert_bounding_box_format
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe, this is a sign to redesign the structure and put this method here or in utils module ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was a design choice to have all transforming functions in torchvision.prototype.transforms.functional. This is not implemented yet, but for the automatic dispatch to work, we need to depend on torchvision.prototype.features. Thus, if we want to honor the design choice, we can't get around the cyclic imports if we want to provide these convenience conversion methods.

If we relax the design choice to all transforming functions need to be present in torchvision.prototype.transforms.functional, but can be imported from somewhere else, I fully agree, and this should be refactored.

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks @pmeier

@pmeier pmeier merged commit 466b845 into pytorch:revamp-prototype-features-transforms Jan 31, 2022
@pmeier pmeier deleted the transforms/readd-functional branch January 31, 2022 15:07
@pmeier
Copy link
Collaborator Author

pmeier commented Feb 4, 2022

@datumbox reviewed in #5375.

datumbox pushed a commit that referenced this pull request Feb 11, 2022
* revamp prototype features (#5283)

* remove decoding from prototype datasets (#5287)

* remove decoder from prototype datasets

* remove unused imports

* cleanup

* fix readme

* use OneHotLabel in SEMEION

* improve voc implementation

* revert unrelated changes

* fix semeion mock data

* fix pcam

* readd functional transforms API to prototype (#5295)

* readd functional transforms

* cleanup

* add missing imports

* remove __torch_function__ dispatch

* readd repr

* readd empty line

* add test for scriptability

* remove function copy

* change import from functional tensor transforms to just functional

* fix import

* fix test

* fix prototype features and functional transforms after review (#5377)

* fix prototype functional transforms after review

* address features review

* make mypy more strict on prototype features

* make mypy more strict for prototype transforms

* fix annotation

* fix kernel tests

* add automatic feature type dispatch to functional transforms (#5323)

* add auto dispatch

* fix missing arguments error message

* remove pil kernel for erase

* automate feature specific parameter detection

* fix typos

* cleanup dispatcher call

* remove __torch_function__ from transform dispatch

* remove auto-generation

* revert unrelated changes

* remove implements decorator

* change register parameter order

* change order of transforms for readability

* add documentation for __torch_function__

* fix mypy

* inline check for support

* refactor kernel registering process

* refactor dispatch to be a regular decorator

* split kernels and dispatchers

* remove sentinels

* replace pass with ...

* appease mypy

* make single kernel dispatchers more concise

* make dispatcher signatures more generic

* make kernel checking more strict

* revert doc changes

* address Franciscos comments

* remove inplace

* rename kernel test module

* fix inplace

* remove special casing for pil and vanilla tensors

* address comments

* update docs

* cleanup features / transforms feature branch (#5406)

* mark candidates for removal

* align signature of resize_bounding_box with corresponding image kernel

* fix documentation of Feature

* remove interpolation mode and antialias option from resize_segmentation_mask

* remove or privatize functionality in features / datasets / transforms
facebook-github-bot pushed a commit that referenced this pull request Feb 16, 2022
Summary:
* revamp prototype features (#5283)

* remove decoding from prototype datasets (#5287)

* remove decoder from prototype datasets

* remove unused imports

* cleanup

* fix readme

* use OneHotLabel in SEMEION

* improve voc implementation

* revert unrelated changes

* fix semeion mock data

* fix pcam

* readd functional transforms API to prototype (#5295)

* readd functional transforms

* cleanup

* add missing imports

* remove __torch_function__ dispatch

* readd repr

* readd empty line

* add test for scriptability

* remove function copy

* change import from functional tensor transforms to just functional

* fix import

* fix test

* fix prototype features and functional transforms after review (#5377)

* fix prototype functional transforms after review

* address features review

* make mypy more strict on prototype features

* make mypy more strict for prototype transforms

* fix annotation

* fix kernel tests

* add automatic feature type dispatch to functional transforms (#5323)

* add auto dispatch

* fix missing arguments error message

* remove pil kernel for erase

* automate feature specific parameter detection

* fix typos

* cleanup dispatcher call

* remove __torch_function__ from transform dispatch

* remove auto-generation

* revert unrelated changes

* remove implements decorator

* change register parameter order

* change order of transforms for readability

* add documentation for __torch_function__

* fix mypy

* inline check for support

* refactor kernel registering process

* refactor dispatch to be a regular decorator

* split kernels and dispatchers

* remove sentinels

* replace pass with ...

* appease mypy

* make single kernel dispatchers more concise

* make dispatcher signatures more generic

* make kernel checking more strict

* revert doc changes

* address Franciscos comments

* remove inplace

* rename kernel test module

* fix inplace

* remove special casing for pil and vanilla tensors

* address comments

* update docs

* cleanup features / transforms feature branch (#5406)

* mark candidates for removal

* align signature of resize_bounding_box with corresponding image kernel

* fix documentation of Feature

* remove interpolation mode and antialias option from resize_segmentation_mask

* remove or privatize functionality in features / datasets / transforms

Reviewed By: sallysyw

Differential Revision: D34265747

fbshipit-source-id: 569ed9f74ac0c026391767c3b422ca0147f55ead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants