Skip to content

Could T.Lambda be nn.Module? #3784

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

Open
vadimkantorov opened this issue May 6, 2021 · 6 comments
Open

Could T.Lambda be nn.Module? #3784

vadimkantorov opened this issue May 6, 2021 · 6 comments

Comments

@vadimkantorov
Copy link

vadimkantorov commented May 6, 2021

It would allow it to be placed in nn.ModuleList for passing to RandomApply (for scriptability)

https://pytorch.org/vision/stable/transforms.html#torchvision.transforms.RandomApply

cc @vfdev-5

@fmassa
Copy link
Member

fmassa commented May 6, 2021

Hi,

@vfdev-5 has more context on this and please correct me if I'm missing something.

We tried doing it, but it wouldn't be possible to make it scriptable IIRC, and there were some other things that could be misleading to users.

There is some more discussion in #2645, in particular #2645 (comment), but I'll let @vfdev-5 give more details

@vadimkantorov
Copy link
Author

Real-life usecase: facebookresearch/dino#28 (also partly because Solarization does not exist as a module)

@fmassa
Copy link
Member

fmassa commented May 7, 2021

@datumbox what do you think about adding a nn.Module interface for Solarize?

@datumbox
Copy link
Contributor

datumbox commented May 7, 2021

We already support this, unless you mean something else?

class RandomSolarize(torch.nn.Module):
"""Solarize the image randomly with a given probability by inverting all pixel
values above a threshold. If img is a Tensor, it is expected to be in [..., 1 or 3, H, W] format,
where ... means it can have an arbitrary number of leading dimensions.
If img is PIL Image, it is expected to be in mode "L" or "RGB".
Args:
threshold (float): all pixels equal or above this value are inverted.
p (float): probability of the image being color inverted. Default value is 0.5
"""

@vadimkantorov
Copy link
Author

Unfortunately, it's missing from the docs: http://pytorch.org/vision/master/search.html?q=RandomSolarize&check_keywords=yes&area=default <- no results

@datumbox
Copy link
Contributor

datumbox commented May 7, 2021

@vadimkantorov Thanks for flagging. We really appreciate taking the time to do so. Keep them coming. :)

I just sent a PR to fix this. Should be added shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants