chr5tphr/zennit

Support for padding layers

Samsdas opened this issue · 2 comments

Hi,

I am trying to analyze a model consisting of Padding Layers using LRP. I cant seem to find any mentions of padding layers in the code however. Are they implicitly supported already and if not what steps are necessary to make it work?

Thanks!

Hey @Samsdas

Thank you for the question!
Padding layers are implicitly supported, here is an explanation why:

Zennit overwrites the gradient where necessary to transform it to LRP.
For some types of operations, the gradient is already the correct way of distributing the relevance backward.

For padding, you effectively do an identity operation on the existing input elements, and then append some more elements, which will be independent of your original input.
The gradient of the identity operation is the identity, which means that without modifying the gradient, you already get the correct relevance distribution. Since the padded elements are constants, they simply do not propagate any relevance backward, similar to the bias. You will lose some relevance in the padded elements, meaning that your relevance will not be conservative anymore (if you started with a relevance sum of 1 in the output layer, the input will be <1).

If you use more involved padding operations where the padded elements depend on the input (e.g. periodic boundary padding, repeating the bordering elements), the normalization may be a little off, since some inputs inflate their contribution. This can be fixed by using the zennit.rules.Norm rule for those layers.

Hey @chr5tphr,
big thanks for the fast response. I really appreciate it and I am especially thankful for the explanation of the implicit support of the padding layer!