Skip to content

Commit aa91928

Browse files
authored
Document LRP composites (#43)
1 parent 0530464 commit aa91928

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ Individual LRP rules like `ZeroRule`, `EpsilonRule`, `GammaRule` and `ZBoxRule`
6969
[codecov-img]: https://codecov.io/gh/adrhill/ExplainabilityMethods.jl/branch/master/graph/badge.svg
7070
[codecov-url]: https://codecov.io/gh/adrhill/ExplainabilityMethods.jl
7171

72-
[docs-composites]: https://adrhill.github.io/ExplainabilityMethods.jl/dev/generated/example/#Custom-composites
73-
[docs-custom-rules]: https://adrhill.github.io/ExplainabilityMethods.jl/dev/generated/example/#Custom-rules
72+
[docs-composites]: https://adrhill.github.io/ExplainabilityMethods.jl/dev/generated/advanced_lrp/#Custom-LRP-composites
73+
[docs-custom-rules]: https://adrhill.github.io/ExplainabilityMethods.jl/dev/generated/advanced_lrp/#Custom-LRP-rules
7474

7575
[doi-img]: https://zenodo.org/badge/337430397.svg
7676
[doi-url]: https://zenodo.org/badge/latestdoi/337430397

docs/literate/advanced_lrp.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ index = 10
1818
x, y = MNIST.testdata(Float32, index)
1919
input = reshape(x, 28, 28, 1, :);
2020

21+
# ## Custom LRP composites
22+
# Instead of creating an LRP-analyzer from a single rule (e.g. `LRP(model, GammaRule())`),
23+
# we can also assign rules to each layer individually.
24+
# For this purpose, we create an array of rules that matches the length of the Flux chain:
25+
rules = [
26+
ZBoxRule(),
27+
GammaRule(),
28+
GammaRule(),
29+
EpsilonRule(),
30+
EpsilonRule(),
31+
EpsilonRule(),
32+
ZeroRule(),
33+
ZeroRule(),
34+
]
35+
36+
analyzer = LRP(model, rules)
37+
heatmap(input, analyzer)
38+
39+
# Since some Flux Chains contain other Flux Chains, ExplainabilityMethods provides
40+
# a utility function called [`flatten_model`](@ref).
41+
#
42+
#md # !!! warning "Flattening models"
43+
#md # Not all models can be flattened, e.g. those using
44+
#md # `Parallel` and `SkipConnection` layers.
45+
2146
# ## Custom LRP rules
2247
# Let's define a rule that modifies the weights and biases of our layer on the forward pass.
2348
# The rule has to be of type `AbstractLRPRule`.

0 commit comments

Comments
 (0)