-
Notifications
You must be signed in to change notification settings - Fork 236
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
Implementing grad-cam in models that use dropout #2
Comments
When calling gradient_function, the actual learning phase should be a scalar. |
Hi,
returns the same error message:
I guess the full code would be more helpful here; I commit it to my repo (thanks for the suggestion by the way!) tomorrow. |
@thiippal You should check your code carefully. I have run this code, and it works well. |
@jf003320018 Which code are you referring to? @jacobgil I've added the full code for grad-cam on this branch. |
I took a look at the branch above (only ran with dummy weights since there were no tensorflow format weights). The problem seems to be the Also in the branch you shared there are a few dimension problems, it seems that MiniVGGNet was called with wrong parameters- (150, 150, 3, 3) instead of (3, 150, 150, 3). |
Traditionally, dropout do not used for convolutional and pooling layers. So it is not needed to use K.set_learning_phase in the code. |
Hi @jacobgil, unfortunately the cam branch was behind a few commits, so the TensorFlow weights were missing. I also did not get far enough to resize the images from the canonical ImageNet size, but thanks for pointing that out! Removing The output, however, is quite interesting: most images produce a class activation map with red colour only, such as the one below: My up-to-date code may be found here ... thanks for your support & patience! |
Hi @thiippal,
An example output i'm getting looks like this: Btw what are the 3 categories in the output? |
Hi Jacob, thanks – should have figured that out: I faced & solved the same issue when originally using your CAM implementation. Now the script returns completely (well perhaps always not so) sensible results. :-) The three classes correspond to T-72 tanks, BMP APCs and 'other', i.e. street and countryside scenes without none of the aforementioned classes. I think this issue can be closed now. Hope this will help someone else implementing Grad-CAM ... thanks for your support! |
Thanks a lot, @jacobgil . you answer:
is ok, and helped me in my code:
|
Hey,
I'm attempting to implement grad-cam into my project, which uses a different architecture than VGG16. The model, which has just two convolutional blocks (see here under MiniVGGNet), uses dropout to combat overfitting. Note that this model still uses Theano; I'm moving to TensorFlow now.
Now, if I've understood correctly, Keras must be told whether to operate in training (include dropout) or testing (exclude dropout) mode, as Francois Chollet describes here.
I've therefore included K.learning_phase (which has been set to zero, that is, testing mode) into the gradient function in grad-cam:
This, however, returns the following error:
Any idea what might be the issue here?
The text was updated successfully, but these errors were encountered: