facebookresearch/TorchRay

Grad CAM Eval Mode

dkosm opened this issue · 1 comments

dkosm commented

Hi,

thank you very much for the nice library. Some very useful implementations to current Saliency methods :)

This may be more a suggestion rather than an issue, but well let's get into it:

My version: torchray 1.0.0.2

As with all torch ray methods, the Grad Cam implementation supports two versions, "simple" and "manual".
During usage of the simple version, the convenient
torchray.attribution.grad_cam.grad_cam(*args, saliency_layer, gradient_to_saliency=, **kwargs) method is used, which itself returns results from torchray.attribution.common.saliency(). This saliency method correctly puts the model in eval mode and everything goes as planned.

On the other hand, the "manual" version uses:
get_example_data()
get_module()
Probe()
gradient_to_grad_cam_saliency()

taken from torchray.attribution.common and torchray.attribution.grad_cam. Going with the example model from get_example_data(), everything is fine, too, since the model is put to eval() mode before being returned be get_example_data. Though, if one wishes to use their own trained models, this change to eval() mode has to happen manually, since it is not done by any method/class used in the "manual" version, namely get_module, Probe, gradient_to_grad_cam.
Only the nice wrapper methods like e.g., gradient_to_grad_cam_saliency ,which use the saliency() method, handle this for the user.

Although, knowledge about the necessity of changing your model to eval mode is something that could be expected by most torch users, it might be helpful to display this info in combination with the "manual" versions, more prominent inside the docs. A way of doing this could be a warning/note next to the "manual" methods. This might helpful to new users of torchray.

I hope I did not miss something inside the docs about this very topic.
Keep up the nice work and thanks for this lib!

@dkosm Thanks for this suggestion; I'm currently writing up my thesis but we will update the docs accordingly once I've submitted.