I want to turn my keras model into a theano function so that I can compute the gradients on the inputs. I thought this might be cool for visualizing the network. I want to
For "old" keras(0.3.x for example):
I don't use this version but examples like this one should work.
For "new" keras(1.0+):
Since you use Dropout
layer, you will need to add another input K.learning_phase()
and give it the value 0 (0 for testing, 1 for training.)
code:
from keras import backend as K
K.function([model.layers[0].input, K.learning_phase()], [model.layers[-1].output])
Reference: keras FAQ