keisen / tf-keras-vis

Neural network visualization toolkit for tf.keras
https://keisen.github.io/tf-keras-vis-docs/
MIT License
313 stars 45 forks source link

Incorrect implementation of LayerCam #88

Closed aguirrejuan closed 2 years ago

aguirrejuan commented 2 years ago

First of all, great job with this repository, it has helped me a lot.

In the paper LayerCAM: Exploring Hierarchical Class Activation Maps for Localization the steps for getting the CAM is:

step 1: $g{ij}^{kc} = \frac{\partial y^c}{\partial A{ij}^k}$ Same as GradCAM step 2: $w{ij}^{kc} = relu (g{ij}^{kc})$ Different from GradCAM, but with the parameter gradient_modifier can be implemented with the class GradCAM. step 3: $\hat{A{ij}^k} = w{ij}^{kc} \cdot A_{ij}^{k}$ Different from GradCAM. GradCAM uses average pooling. step 4: $M^c = Relu(\sum_k \hat{A^k} )$ Same as GradCAM

So, it is not enough to use the parameter: https://github.com/keisen/tf-keras-vis/blob/0bc00a80c04a66669df8dfd8d1137cdca9b86610/tf_keras_vis/layercam.py#L22

It is necessary to implement the operation of step 3.

keisen commented 2 years ago

Hi @aguirrejuan , Thank you for pointing that out! I will improve the problem in next release.

Thanks!