IS-CAM formula error?
noobgrow opened this issue ยท 4 comments
๐ Feature
https://frgfm.github.io/torch-cam/methods.html#activation-based-methods
Mk /ak formula of ISCAM in the link above is not the same as the original paper.
And I wonder if there is an original implement of ISCAM? Because I find that alpha calculated in paper is sumed by N time. But in your code it is sumed by k time.
Motivation & pitch
.
Alternatives
No response
Additional context
No response
Hi @noobgrow ๐
Thanks for reporting this! So actually, the author reached out to me before the paper even came out to experiment with it. He validated the implementation back then, so I didn't question whether there would be some difference with the upcoming paper ๐
So let me check the difference you're talking about and get back to you ๐
Cheers โ๏ธ
So, this is going to be annoying without LaTex for math rendering, but let's try ๐
In the paper:
alpha_k^c = 1 / N * sum\limits_{i=0}^N (C(M_i))
# Let's expand M_i
alpha_k^c = 1 / N * sum\limits_{i=0}^N (C(sum\limits_{j=0}^{i-1} j / N * X_0 * A_l^k))
# Now we can simplify the sum
alpha_k^c = 1 / N * sum\limits_{i=0}^N (C(\frac{i * (i - 1)}{2N} * X_0 * A_l^k))
In the code, X_0 * A_l^k
is stored as scored_inputs
(cf. https://github.com/frgfm/torch-cam/blob/master/torchcam/methods/activation.py#L411-L414)
and \frac{i * (i - 1)}{2N}
is stored as _coeff
(cf. https://github.com/frgfm/torch-cam/blob/master/torchcam/methods/activation.py#L430)
So this line https://github.com/frgfm/torch-cam/blob/master/torchcam/methods/activation.py#L437 computes C(M_i)
from the paper, they are summed in the following lines, and finally I divide by N here https://github.com/frgfm/torch-cam/blob/master/torchcam/methods/activation.py#L445
However, I realize that the docstring has some errors, I'll correct it to fix the documentation ๐
Let me know if some things are still unclear!