-
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
add sequence fill support for ElasticTransform #7141
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2104,8 +2104,12 @@ def __init__(self, alpha=50.0, sigma=5.0, interpolation=InterpolationMode.BILINE | |
interpolation = _interpolation_modes_from_int(interpolation) | ||
self.interpolation = interpolation | ||
|
||
if not isinstance(fill, (int, float)): | ||
raise TypeError(f"fill should be int or float. Got {type(fill)}") | ||
if isinstance(fill, (int, float)): | ||
fill = [float(fill)] | ||
pmeier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
elif isinstance(fill, (list, tuple)): | ||
fill = [float(f) for f in fill] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we actually need to convert to float? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, we do due to JIT 🥲 Removing the float conversion from L2110 gives us import torch.jit
from torchvision import transforms
torch.jit.script(transforms.ElasticTransform(fill=[1]))
I know this is ugly AF and far from being Pythonic, but given that it is on v1 I really don't want to deal with this any more than I have to. |
||
else: | ||
raise TypeError(f"fill should be int or float or a list or tuple of them. Got {type(fill)}") | ||
self.fill = fill | ||
|
||
@staticmethod | ||
|
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.
Drive-by since I was looking into the fill support. This seems to be a copy-paste error. Internally we just convert PIL images to tensors
vision/torchvision/transforms/functional.py
Lines 1558 to 1562 in 59dc938
and then call the tensor kernel:
vision/torchvision/transforms/functional.py
Lines 1573 to 1578 in 59dc938
Meaning, there is no difference between both types.