I'm building a custom neural network implementation. I use Keras for testing to make sure that gradients computed by my implementation match Keras gradients. Thanks to this answer How to obtain the gradients in keras? I was able to compare weights and outputs gradients. However I would also like to compare gradients for INPUTS. My Keras model is just one dense layer.
model = Sequential()
model.add(Dense(output_size,
use_bias=bias,
input_shape=(input_size,),
activation=activation_name))
model.compile(optimizer="sgd", loss=loss_function_name)
...
model.evaluate(x, y)
How can I get gradients in respect to x
?