data is the data (tensor) underlying a variable. If you make operations on a variable, you are generating new terms to the computational graph that describe its expression. For instance, if you update x by multiplying it by itself, the computational graph becomes x^2 and the gradient is 2x). By using data you are instead updating its value. For instance, if the computational graph is 3x, and you set x.data=4, the gradient is still three).
You were getting gradient equal to none because your img is not the variable mapping the original image anymore. Because of efficiency, the gradient values are kept only for the leaf variables.