Clip values of Variable image

I’m using pytorch autograd to update pixels of an image. I’ve noticed that after a while, the pixels start going out of range (only values in (0,1) make sense). What is the correct way to keep the pixel values in the desired range?

It seems the following snippet is working as it should:


Will this have some unwanted side effects?

afaik, that snippet should work fine.

1 Like