Closed alexrey88 closed 3 years ago
Yes, it is because they are not differentiable.
Do you know why? Because I looked at their code and from first glance I thought they were.
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.
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?
In our implementation the output range of each transform is not necessarily [-1, 1], though intuitively it should be.
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].
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.
All right, thanks!
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. :)