-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guided Backpropagation in Keras #1777
Comments
hm, still doesn't work for me. I still see no difference. btw, I don't understand why taking relu from it's original function is
On Thu, Feb 25, 2016 at 1:49 PM, francescopittaluga <
|
Hi, Thanks for sharing your code. |
Are there full code example
|
If you don't compile the code like I said, the code given by mbz is pretty complete. |
Hi,
At the moment I can make saliency maps with default backpropagation independent of the backend. For Guided Backprop the problem is the
(substituting them in an existing model did not actually substitute them.) Does someone have an idea for backend-invariant implementation of Related: tensorflow implementation using tf.gradient_override_map, which is a lot more elegant. (Does theano have something like tf.gradient_override_map?) |
@michaelosthege Did you try the saliency example? I am using the same function and get as result the following error: def compile_saliency_function(model):
"""
Compiles a function to compute the saliency maps and predicted classes
for a given minibatch of input images.
"""
inp = model.layers[0].input
outp = model.layers[-1].output
max_outp = K.T.max(outp, axis=1)
saliency = K.gradients(K.sum(max_outp), inp)
max_class = K.T.argmax(outp, axis=1)
return K.function([inp, K.learning_phase()], [saliency, max_class])
compile_saliency_function(new_model)([X_train[:20], 0])[0] Output log: DisconnectedInputError:
Backtrace when that variable is created:
[...]
---> 10 saliency = K.gradients(K.sum(max_outp), inp)
[...]
File "/home/ssierral/.conda/envs/sierraenv/lib/python2.7/site-packages/keras/models.py", line 197, in model_from_json
return layer_from_config(config, custom_objects=custom_objects)
[...] BTW, my model is composed of a embedding layer, an 1D CNN, a K-max pooling function and a softmax layer. Thank you, |
@inulinux12 I reproduced the notebook from the lasagne link.
hope this helps |
It seems to be that using K-max pooling with 1D convolutions is messing the model, and theano is unable to calculate the gradient. I have tried with a basic mnist cnn and the code works perfectly, but 1D CNN for text does not. EDIT: |
Hi, quick question regarding this if either/any of you have a second...I am trying to implement the compile_saliency_function (basic version right now, not guided version) from the code above |
@michaelosthege Do you realize guided backprop with tensorflow backend in keras? If you did, could you share your code? I want to realize it but have not idea. Thank you. |
@jf003320018 No, this did not work because of missing APIs (see my comment of Aug 22). I only managed with the theano backend. All essentials for that are already posted. Not exactly guided backprop, but potentially relevant: for understanding what your network does: DeepLIFT and Quiver |
^ FYI the DeepLIFT framework does implement Guided Backprop, and as of a few days ago there is a tensorflow branch. You can find an example of the different importance score methods implemented within DeepLIFT here: https://github.com/kundajelab/deeplift/blob/tensorflow/examples/public/tal_gata/TAL-GATA%20simulation.ipynb. Heads up: DeepLIFT relies on defining a "reference" input which represents an input that lacks any interesting features. If you don't have a good sense of what the reference input is, I suggest exploring different methods. DeepLIFT has mostly been developed in the context of genomics where the notion of a reference is better-defined than for images; as the creator of DeepLIFT, I recommend using Guided Backprop if you are working on image-like data, at least until we figure out what a good reference for images is (all-zeros doesn't work well, as dark patches can be an interesting feature sometimes). Also, please let me know if you run into any issues. The tensorflow branch passes my unit tests but I have not stress-tested it yet. |
(Also feel free to shoot me an email if you are interested in support for layers other than the ones currently supported) |
@michaelosthege Sorry for disturbing you again. Today, I realize this code in keras using theano backend as described in https://github.com/Lasagne/Recipes/blob/master/examples/Saliency%20Maps%20and%20Guided%20Backpropagation.ipynb. But I find that the results of guided backprop is as same as those of saliency map. So it seems that we cannot just use the ModifiedBackprop and GuidedBackprop from Lasagne. |
@michaelosthege @jf003320018 for the guided propagation, machael you mentioned that there is lack of APIs to do that, did you let the author of Keras to know about it so that someone can work on the APIs? FYI, guided backpropagation is very straightforward in Torch7 (like 5-10 lines). It seems difficult to make it work here. |
@johnny550822 We are missing APIs in tensorflow here, so it is not a Keras issue to start with. And if you look closely this is related to the architectural differences between the two frameworks. |
@michaelosthege :( oh...no. Can you briefly tell me what is missing? Because this may relate to other things that I want to try out with tensorflow+keras... (I am new to them) |
Please refer to my comment from 4 months ago: #1777 (comment)
There I enumerated the missing APIs
From: Johnny<mailto:notifications@github.com>
Sent: Dienstag, 20. Dezember 2016 20:19
To: fchollet/keras<mailto:keras@noreply.github.com>
Cc: michaelosthege<mailto:thecakedev@hotmail.com>; Mention<mailto:mention@noreply.github.com>
Subject: Re: [fchollet/keras] Guided Backpropagation in Keras (#1777)
@michaelosthege<https://github.com/michaelosthege> :( oh...no. Can you briefly tell me what is missing? Because this may relate to other things that I want to try out with tensorflow+keras... (I am new to them)
-
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#1777 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AFnx8hSR5pnH7m4_a5a18zmJFZ5jZGqNks5rKCo2gaJpZM4He10_>.
|
@michaelosthege thanks! |
Did anyone succeed to implement guided backpropagation on keras, not just a basic saliency map defined by the simple gradient? There should be a great difference between the basic version and guided backpropagation. In my implementation I can't achieve any difference between these two approaches. |
saliency map My code is given below for computing gradients in order to visualize the sailency map from keras import backend as K v = compile_saliency_function(model)([X_train[:1], 0])[0] I am getting 421 vector (Because i have 43 features ). But i want to get 424 (where 4 is the number of classes). Could you please tell where should i make changes? |
- GuidedBackProp - keras-team/keras#1777 - https://github.com/Lasagne/Recipes/blob/master/examples/Saliency%20Maps%20and%20Guided%20Backpropagation.ipynb - https://github.com/kundajelab/deeplift/blob/tensorflow/examples/public/tal_gata/TAL-GATA%20simulation.ipynb - http://stackoverflow.com/questions/38340791/guided-back-propagation-in-tensorflow - https://arxiv.org/abs/1412.6806 - http://www.cs.toronto.edu/~guerzhoy/321/lec/W07/HowConvNetsSee.pdf - tensorflow/tensorflow#6422 - http://stackoverflow.com/questions/39793505/in-tensorflow-is-it-possible-to-use-different-learning-rate-for-different-part/39793644#39793644 - http://stackoverflow.com/questions/35298326/freeze-some-variables-scopes-in-tensorflow-stop-gradient-vs-passing-variables - https://arxiv.org/abs/1608.00530 - https://github.com/artvandelay/Deep_Inside_Convolutional_Networks add VisualAttention add http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=7578651 add http://web.mit.edu/zoya/www/visual_attention_reading.pdf add https://github.com/kjw0612/awesome-deep-vision#visual-attention-and-saliency
move keras-team/keras#1777 from 20161231.md to 20160521.md. move https://github.com/Lasagne/Recipes/blob/master/examples/Saliency%20Maps%20and%20Guided%20Backpropagation.ipynb from 20161231.md to 20160521.md. move https://github.com/kundajelab/deeplift/blob/tensorflow/examples/public/tal_gata/TAL-GATA%20simulation.ipynb from 20161231.md to 20160521.md. move http://stackoverflow.com/questions/38340791/guided-back-propagation-in-tensorflow from 20161231.md to 20160521.md. move https://arxiv.org/abs/1412.6806 from 20161231.md to 20160521.md. move http://www.cs.toronto.edu/~guerzhoy/321/lec/W07/HowConvNetsSee.pdf from 20161231.md to 20160521.md. move tensorflow/tensorflow#6422 from 20161231.md to 20160521.md. move http://stackoverflow.com/questions/39793505/in-tensorflow-is-it-possible-to-use-different-learning-rate-for-different-part/39793644#39793644 from 20161231.md to 20160521.md. move http://stackoverflow.com/questions/35298326/freeze-some-variables-scopes-in-tensorflow-stop-gradient-vs-passing-variables from 20161231.md to 20160521.md. move https://arxiv.org/abs/1608.00530 from 20161231.md to 20160521.md. move https://github.com/artvandelay/Deep_Inside_Convolutional_Networks from 20161231.md to 20160521.md. move https://arxiv.org/abs/1611.05418 from 20161231.md to 20160521.md. move https://arxiv.org/abs/1704.07911 from 20161231.md to 20160521.md. move https://blogs.nvidia.com/blog/2017/04/27/how-nvidias-neural-net-makes-decisions from 20161231.md to 20160521.md. move http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=7578651 from 20161231.md to 20160521.md. move http://web.mit.edu/zoya/www/visual_attention_reading.pdf from 20161231.md to 20160521.md. move https://github.com/kjw0612/awesome-deep-vision#visual-attention-and-saliency from 20161231.md to 20160521.md.
move keras-team/keras#1777 from 20161231.md to 20160521.md. move https://github.com/Lasagne/Recipes/blob/master/examples/Saliency%20Maps%20and%20Guided%20Backpropagation.ipynb from 20161231.md to 20160521.md. move https://github.com/kundajelab/deeplift/blob/tensorflow/examples/public/tal_gata/TAL-GATA%20simulation.ipynb from 20161231.md to 20160521.md. move http://stackoverflow.com/questions/38340791/guided-back-propagation-in-tensorflow from 20161231.md to 20160521.md. move https://arxiv.org/abs/1412.6806 from 20161231.md to 20160521.md. move http://www.cs.toronto.edu/~guerzhoy/321/lec/W07/HowConvNetsSee.pdf from 20161231.md to 20160521.md. move tensorflow/tensorflow#6422 from 20161231.md to 20160521.md. move http://stackoverflow.com/questions/39793505/in-tensorflow-is-it-possible-to-use-different-learning-rate-for-different-part/39793644#39793644 from 20161231.md to 20160521.md. move http://stackoverflow.com/questions/35298326/freeze-some-variables-scopes-in-tensorflow-stop-gradient-vs-passing-variables from 20161231.md to 20160521.md. move https://arxiv.org/abs/1608.00530 from 20161231.md to 20160521.md. move https://github.com/artvandelay/Deep_Inside_Convolutional_Networks from 20161231.md to 20160521.md. move https://arxiv.org/abs/1611.05418 from 20161231.md to 20160521.md. move https://arxiv.org/abs/1704.07911 from 20161231.md to 20160521.md. move https://blogs.nvidia.com/blog/2017/04/27/how-nvidias-neural-net-makes-decisions from 20161231.md to 20160521.md. move http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=7578651 from 20161231.md to 20160521.md. move http://web.mit.edu/zoya/www/visual_attention_reading.pdf from 20161231.md to 20160521.md. move https://github.com/kjw0612/awesome-deep-vision#visual-attention-and-saliency from 20161231.md to 20160521.md.
@Andrjusha I have ported the implementation of Guided Backprop from TensorFlow to Keras. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed. |
- GuidedBackProp - keras-team/keras#1777 - https://github.com/Lasagne/Recipes/blob/master/examples/Saliency%20Maps%20and%20Guided%20Backpropagation.ipynb - https://github.com/kundajelab/deeplift/blob/tensorflow/examples/public/tal_gata/TAL-GATA%20simulation.ipynb - http://stackoverflow.com/questions/38340791/guided-back-propagation-in-tensorflow - https://arxiv.org/abs/1412.6806 - http://www.cs.toronto.edu/~guerzhoy/321/lec/W07/HowConvNetsSee.pdf - tensorflow/tensorflow#6422 - http://stackoverflow.com/questions/39793505/in-tensorflow-is-it-possible-to-use-different-learning-rate-for-different-part/39793644#39793644 - http://stackoverflow.com/questions/35298326/freeze-some-variables-scopes-in-tensorflow-stop-gradient-vs-passing-variables - https://arxiv.org/abs/1608.00530 - https://github.com/artvandelay/Deep_Inside_Convolutional_Networks add VisualAttention add http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=7578651 add http://web.mit.edu/zoya/www/visual_attention_reading.pdf add https://github.com/kjw0612/awesome-deep-vision#visual-attention-and-saliency
move keras-team/keras#1777 from 20161231.md to 20160521.md. move https://github.com/Lasagne/Recipes/blob/master/examples/Saliency%20Maps%20and%20Guided%20Backpropagation.ipynb from 20161231.md to 20160521.md. move https://github.com/kundajelab/deeplift/blob/tensorflow/examples/public/tal_gata/TAL-GATA%20simulation.ipynb from 20161231.md to 20160521.md. move http://stackoverflow.com/questions/38340791/guided-back-propagation-in-tensorflow from 20161231.md to 20160521.md. move https://arxiv.org/abs/1412.6806 from 20161231.md to 20160521.md. move http://www.cs.toronto.edu/~guerzhoy/321/lec/W07/HowConvNetsSee.pdf from 20161231.md to 20160521.md. move tensorflow/tensorflow#6422 from 20161231.md to 20160521.md. move http://stackoverflow.com/questions/39793505/in-tensorflow-is-it-possible-to-use-different-learning-rate-for-different-part/39793644#39793644 from 20161231.md to 20160521.md. move http://stackoverflow.com/questions/35298326/freeze-some-variables-scopes-in-tensorflow-stop-gradient-vs-passing-variables from 20161231.md to 20160521.md. move https://arxiv.org/abs/1608.00530 from 20161231.md to 20160521.md. move https://github.com/artvandelay/Deep_Inside_Convolutional_Networks from 20161231.md to 20160521.md. move https://arxiv.org/abs/1611.05418 from 20161231.md to 20160521.md. move https://arxiv.org/abs/1704.07911 from 20161231.md to 20160521.md. move https://blogs.nvidia.com/blog/2017/04/27/how-nvidias-neural-net-makes-decisions from 20161231.md to 20160521.md. move http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=7578651 from 20161231.md to 20160521.md. move http://web.mit.edu/zoya/www/visual_attention_reading.pdf from 20161231.md to 20160521.md. move https://github.com/kjw0612/awesome-deep-vision#visual-attention-and-saliency from 20161231.md to 20160521.md.
move keras-team/keras#1777 from 20161231.md to 20160521.md. move https://github.com/Lasagne/Recipes/blob/master/examples/Saliency%20Maps%20and%20Guided%20Backpropagation.ipynb from 20161231.md to 20160521.md. move https://github.com/kundajelab/deeplift/blob/tensorflow/examples/public/tal_gata/TAL-GATA%20simulation.ipynb from 20161231.md to 20160521.md. move http://stackoverflow.com/questions/38340791/guided-back-propagation-in-tensorflow from 20161231.md to 20160521.md. move https://arxiv.org/abs/1412.6806 from 20161231.md to 20160521.md. move http://www.cs.toronto.edu/~guerzhoy/321/lec/W07/HowConvNetsSee.pdf from 20161231.md to 20160521.md. move tensorflow/tensorflow#6422 from 20161231.md to 20160521.md. move http://stackoverflow.com/questions/39793505/in-tensorflow-is-it-possible-to-use-different-learning-rate-for-different-part/39793644#39793644 from 20161231.md to 20160521.md. move http://stackoverflow.com/questions/35298326/freeze-some-variables-scopes-in-tensorflow-stop-gradient-vs-passing-variables from 20161231.md to 20160521.md. move https://arxiv.org/abs/1608.00530 from 20161231.md to 20160521.md. move https://github.com/artvandelay/Deep_Inside_Convolutional_Networks from 20161231.md to 20160521.md. move https://arxiv.org/abs/1611.05418 from 20161231.md to 20160521.md. move https://arxiv.org/abs/1704.07911 from 20161231.md to 20160521.md. move https://blogs.nvidia.com/blog/2017/04/27/how-nvidias-neural-net-makes-decisions from 20161231.md to 20160521.md. move http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=7578651 from 20161231.md to 20160521.md. move http://web.mit.edu/zoya/www/visual_attention_reading.pdf from 20161231.md to 20160521.md. move https://github.com/kjw0612/awesome-deep-vision#visual-attention-and-saliency from 20161231.md to 20160521.md.
I'm trying to implement Saliency Maps and Guided Backpropagation in Keras using the following code on Lasagne.
https://github.com/Lasagne/Recipes/blob/master/examples/Saliency%20Maps%20and%20Guided%20Backpropagation.ipynb
I manged to make the first part (Saliency Maps) work as follow:
Now, I'm working on the second part (Guided Backpropagation) but it doesn't work. Here is the code:
I've tested the code about in Theano and it's working so my guess is that there is something wrong with the way I'm replacing the activation in the layers (last snippet). Any idea what I'm doing wrong?
The text was updated successfully, but these errors were encountered: