mit-han-lab / data-efficient-gans

[NeurIPS 2020] Differentiable Augmentation for Data-Efficient GAN Training
https://arxiv.org/abs/2006.10738
BSD 2-Clause "Simplified" License
1.27k stars 175 forks source link

Q: Why not use adjust_brightness of torchvision? #36

Closed alexrey88 closed 3 years ago

alexrey88 commented 3 years ago

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 commented 3 years ago

Yes, it is because they are not differentiable.

alexrey88 commented 3 years ago

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

zsyzzsoft commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

alexrey88 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

All right, thanks!