Keras: calculating derivatives of model output wrt input returns [None]

前端 未结 1 984
天涯浪人
天涯浪人 2020-12-16 07:22

I need help with calculating derivatives for model output wrt inputs in Keras.

I want to add a regularization functional to the loss function. The regularizer conta

1条回答
  •  有刺的猬
    2020-12-16 07:43

    You are computing the gradients respect to X_train, which is not an input variable to the computation graph. Instead you need to get the symbolic input tensor to the model, so try something like:

    grads = K.gradients(model.output, model.input)
    

    0 讨论(0)
提交回复
热议问题