keras-vis icon indicating copy to clipboard operation
keras-vis copied to clipboard

Custom_objects for backend.modify_model_backprop()

Open aphan-sevendreamers opened this issue 6 years ago • 6 comments

  • [v] Check that you are up-to-date with the master branch of keras-vis. You can update with: pip install git+git://github.com/raghakot/keras-vis.git --upgrade --no-deps

  • [v] If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.

  • [v] If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with: pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps

  • [ ] Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).

tensorflow_backend.py should be modified in line 85 to allow custom_objects (and saliency.py, backprop_modifiers.py accordingly).

aphan-sevendreamers avatar Apr 17 '18 05:04 aphan-sevendreamers

Is there a quickfix?

shsshs avatar Apr 17 '18 19:04 shsshs

I am visualizing my own model with mobilenet based structure. This works for me. Proceed with caution though.

backend/tensorflow_backend.py Line 52: def modify_model_backprop(model,backprop_modifier,custom_objects): Line 85: modified_model = load_model(model_path,custom_objects=custom_objects) Line 111: modified_model=load_model(model_path,custom_objects=custom_objects)

visualization/saliency.py Line 83: def visualize_saliency(....,custom_objects=None) Line120: model = modifier_fn(model,custom_objects)

Line 192: def visualize_cam(...,custom_objects=None): Line 229: model = modifier_fn(model,custom_objects)

vis/backprop_modifiers.py

Line 7: def guided(model,custom_objects) Line 17: return backend.modify_model_backprop(model,'guided',custom_objects) Line 20: def rectified(model,custom_objects) Line 30: return backend.modify_model_backprop(model,'rectified',custom_objects)

Cheers,

aphan-sevendreamers avatar Apr 18 '18 01:04 aphan-sevendreamers

Thanks a lot! Saliency works with this (at least it gives meaningfull results). CAM gives me only one 224x224 Matrix for my 224x224x3 image.

shsshs avatar Apr 22 '18 11:04 shsshs

Would you mind post your CAM function in saliency.py here. I doubt it is the problem of version between installing via PiPy and the main branch.

aphan-sevendreamers avatar Apr 23 '18 00:04 aphan-sevendreamers

Nope it wasn't. Looks fine for CAM as well, thx again.

shsshs avatar Apr 23 '18 14:04 shsshs

can someone help with this? I could find no examples in the documentation to generate guided grad_CAM as shown in the paper (with the point-wise multiplication of guided_back propagation and a bi-linear interpolated grad_CAM). It would be great if someone can answer this question, add this function to the toolkit or give the same here for instance.

ghost avatar May 24 '18 12:05 ghost