I trained a neural network to do a regression on the sine function and would like to compute the first and second derivative with respect to the input. I tried using the tf.
I don't think you can calculate second order derivatives using tf.gradients. Take a look at tf.hessians (what you really want is the diagonal of the Hessian matrix), e.g. [1].
An alternative is to use tf.GradientTape: [2].
[1] https://github.com/gknilsen/pyhessian
[2] https://www.tensorflow.org/api_docs/python/tf/GradientTape