Derivative of neural network with respect to input

前端 未结 3 490
忘掉有多难
忘掉有多难 2021-01-20 18:04

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.

3条回答
  •  萌比男神i
    2021-01-20 18:12

    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

提交回复
热议问题