I am trying to understand the purpose of TF GRADIENT TAPE
, in the following code:
import tensorflow as tf
var = tf.Variable(5.0)
with tf.GradientTape() as tape:
op = (2*var)+(var*var)
diff = tape.gradient(op,var)
print (diff)
Op:
diff = tf.Tensor(12.0, shape=(), dtype=float32)
I am confused because since var=5
, the op=(2*5)+(5*5)=>35
, and if I am calculating the derivative of a constant
then diff should be 0
I understand the reason its 12
, because its not taking the var
as 5
instead (2*var)+(var*var)=> 2var+var**2
so calculating the derivative of this function becomes 2+2*var=>12
.
But what I dont understand is, why the value given for var
is not considered?