raghakot / keras-vis

Neural network visualization toolkit for keras
https://raghakot.github.io/keras-vis
MIT License
2.98k stars 660 forks source link

Custom_objects for backend.modify_model_backprop() #107

Open aphan-sevendreamers opened 6 years ago

aphan-sevendreamers commented 6 years ago

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

shsshs commented 6 years ago

Is there a quickfix?

aphan-sevendreamers commented 6 years ago

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,

shsshs commented 6 years ago

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

aphan-sevendreamers commented 6 years ago

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.

shsshs commented 6 years ago

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

ghost commented 6 years ago

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.