Skip to content
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

Q: Why not use adjust_brightness of torchvision? #36

Closed
alexrey88 opened this issue Dec 3, 2020 · 8 comments
Closed

Q: Why not use adjust_brightness of torchvision? #36

alexrey88 opened this issue Dec 3, 2020 · 8 comments

Comments

@alexrey88
Copy link

Why not use functions from torchvision instead of writing you own? Is it because adjust_brightness, adjust_saturation and adjust_contrast of torchvision are not differentiable? Because I thought they were. Thanks for your answer. :)

@zsyzzsoft
Copy link
Collaborator

Yes, it is because they are not differentiable.

@alexrey88
Copy link
Author

Do you know why? Because I looked at their code and from first glance I thought they were.

@zsyzzsoft
Copy link
Collaborator

I had a second look - it seems that torchvision transforms recently have supported torch tensors, which may be differentiable as opposed to PIL images. But they are not implemented to work for GANs, e.g., pixels that are not in [0, 1] after augmentation will be clipped and have no gradients.

@alexrey88
Copy link
Author

Yeah, all right, I see, thanks. :) But there is still something I don't understand... rand_brigthness outputs a tensor in range [-1.5, 1.5] according to your code (unless I'm mistaken). And then if you apply rand_contrast to this tensor, its input range won't be [-1.0, 1.0] as wanted. Isn't each transform supposed to output a tensor in the same range as the input tensor?

@zsyzzsoft
Copy link
Collaborator

zsyzzsoft commented Dec 7, 2020

In our implementation the output range of each transform is not necessarily [-1, 1], though intuitively it should be.

@alexrey88
Copy link
Author

So do you think I can add a line tensor = tensor.clamp(-1.0, 1.0) before the return of each color jittering transform? Because in my own code I call rand_brigthness, rand_contrast and then rand_saturation on an input tensor in range[-1.0, 1.0]. My intuition is that each transform should output a tensor in range [-1.0, 1.0].

@zsyzzsoft
Copy link
Collaborator

You may have a try, but I'm not sure whether it will work as some pixels will not have gradients. Without clamp it should also work fine.

@alexrey88
Copy link
Author

All right, thanks!

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

No branches or pull requests

2 participants