-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
🚀 The feature
(This was originally pitched in this long feedback thread. It was recommended that I open a separate issue).
I am proposing to a) make Datapoint
part of the public API so that 3rd parties can create custom features, and b) provide a dispatch mechanism by which a 3rd party feature can coerce a transform (either 1st party or 3rd party transform) into dispatching to its own implementation of said transform.
E.g., this would enable me to write a Polygon
subclass of Datapoint
in my own library, which would be able to implement its own affine transformation that both torchvision.transforms.affine
and torchvision.transforms.RandomAffine
(and the other standard transforms) dispatch to when they operate on a Polygon
tensor.
There is already some degree of dispatching going on among some transforms. E.g., for affine
and RandomAffine
, any Datapoint
subclass can simply implement a Datapoint.affine
method. The affine
function checks isinstance(inp, Feature)
and then calls inp.affine(...)
. And RandomAffine._transform
simply calls affine
under the hood, which performs the aforementioned dispatching.
Motivation, pitch
The crown jewel of torchvision.transforms
v2 is its added support for features like bounding boxes and segmentation masks. Presently, the development of new features and transforms is gated on the development efforts of the intrepid torchvision team. It would be great to enable users to implement their own features (e.g. Polygon
or ImageTrack
) and for torchvision's transforms (or 3rd party transforms) to be able to dispatch on those features. This would reduce the burden on the torchvision team in that it enables users to develop bespoke features that have "drop-in" compatibility with standard torchvision pipelines, without you needing to officially support the feature.
Alternatives
No response
Additional context
This proposal had some initial feedback here: #6753 (comment)
and the torchvision team provided positive feedback on this here: #6753 (comment)