-
Notifications
You must be signed in to change notification settings - Fork 7k
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
improve UX for v2 Compose #7758
Conversation
return image, label | ||
|
||
@pytest.mark.parametrize( | ||
"transform_clss", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not call this transform_class
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would have to be transform_classes
, since it is a list of classes. And since we use cls
for singular, I'm usually just append an s
to it. I'll leave it up to you.
if not self.transforms: | ||
return inputs if needs_unpacking else inputs[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just error in init
? I dont know if it's super valuable to special-case this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends. The old Compose
works as a no-op in case you don't put any transforms in. However, this doesn't sound like a valid use case. So I'm ok in putting this into the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with the error. LMK if you want the no-op behavior back.
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if green, thank you!
Summary: Co-authored-by: Nicolas Hug <contact@nicolas-hug.com> Reviewed By: matteobettini Differential Revision: D48642249 fbshipit-source-id: 48053ff1f6a19d62264500358a4df125751b71e6
The way
Compose
is currently implemented always passes the input "packed" t the individual transforms. Meaning, if one passesCompose([...])(image, label)
individually (on "unpacked"), the transforms inside theCompose
receive(image, label)
, i.e. the individual inputs packed into a tuple.For our builtin transforms this makes no difference, since we operate on arbitrary input structures anyway. However, this becomes relevant as soon as a user wants to add a custom transform into the same pipeline. Assuming the user doesn't want to bother with our whole protocol and knows the sample structure exactly, they like want to write something like
However, dropping this into a
Compose
would not work when passingimage
andlabel
individually, due to the packing behavior described above. Instead the user would have to writeThis is somewhat awkward, since the input of the individual transform no longer conforms to the input of the
Compose
.This transform fixes this behavior. This means, if the inputs to the
Compose
are unpacked, they also have to be unpacked in the signature of the individual transform. Same is true for the other way around: if the input to theCompose
is packed, the individual transform also needs to take a packed input.cc @vfdev-5