Skip to content

Fill colors for tensor affine transforms #2887

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

Closed
voldemortX opened this issue Oct 25, 2020 · 10 comments
Closed

Fill colors for tensor affine transforms #2887

voldemortX opened this issue Oct 25, 2020 · 10 comments

Comments

@voldemortX
Copy link
Contributor

voldemortX commented Oct 25, 2020

🚀 Feature

Support fill color other than 0 for tensor affine transforms (rotate, affine).

Motivation

It is important for pixel-wise tasks (e.g. segmentation) to have different fill color for ignored label (e.g. 255).

Pitch

Different fill colors are supported for tensors like already supported for PIL images in affine transformations.
Specifically, for rotate() and affine() in transforms/functional_tensor.py.

Alternatives

None at the moment.

Additional context

The requested feature was not supported in the recently completed tensor/PIL unification process #2292 probably due to pytorch grid_sampler(), which is what the implementations based on, does not seem to support fill colors other than 0.

@vfdev-5

@fmassa
Copy link
Member

fmassa commented Oct 26, 2020

FYI it is possible to let torchvision implementation support different fill colors than 0 despite grid_sample limitations, by performing grid_sample twice (first on the image, second on a dummy mask), so that we can mask out the fill values and replace them with the user-input.

@voldemortX
Copy link
Contributor Author

voldemortX commented Oct 26, 2020

Thanks! it could be a good enough workaround for now.

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Oct 26, 2020

@voldemortX following @fmassa 's idea, it could be also possible to append this data mask to the input image as additional channel and apply grid_sample once. We think that such solution can be added to torchvision. If you would like to work on that, it would be helpful 👍 .

@voldemortX
Copy link
Contributor Author

I can try it out, but thinking more on it i'm a bit confused right now. shouldn't the easiest way be replacing the 0 afterwards?

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Oct 26, 2020

shouldn't the easiest way be replacing the 0 afterwards?

What do you mean by replacing the 0 ?

@voldemortX
Copy link
Contributor Author

Oh right, I understand now, the original image could have 0.

@voldemortX
Copy link
Contributor Author

I can try it tomorrow or something (UTC-8), but I have not contributed any code before, is unit tests required for a patch like this?

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Oct 26, 2020

I can try it tomorrow or something (UTC-8), but I have not contributed any code before, is unit tests required for a patch like this?

Sounds good ! Let me describe how I'd do that and put some links on the code to modify a bit later. Yes, tests are required. To start contributing, please read this draft CONTRIBUTING guide.
Btw, if something is unclear in the guide feel free to comment out the PR. Thanks

EDIT:
What to do:

@voldemortX
Copy link
Contributor Author

I can try it tomorrow or something (UTC-8), but I have not contributed any code before, is unit tests required for a patch like this?

Sounds good ! Let me describe how I'd do that and put some links on the code to modify a bit later. Yes, tests are required. To start contributing, please read this draft CONTRIBUTING guide.
Btw, if something is unclear in the guide feel free to comment out the PR. Thanks

Ok, thanks.

@voldemortX
Copy link
Contributor Author

Said feature is now supported.

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