How to compute gradient of output wrt input in Tensorflow 2.0
问题 I have a trained Tensorflow 2.0 model (from tf.keras.Sequential()) that takes an input layer with 26 columns (X) and produces an output layer with 1 column (Y). In TF 1.x I was able to calculate the gradient of the output with respect to the input with the following: model = load_model('mymodel.h5') sess = K.get_session() grad_func = tf.gradients(model.output, model.input) gradients = sess.run(grad_func, feed_dict={model.input: X})[0] In TF2 when I try to run tf.gradients(), I get the error: