Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LRP composites #84

Merged
merged 12 commits into from
Aug 8, 2022
Merged

Add LRP composites #84

merged 12 commits into from
Aug 8, 2022

Conversation

adrhill
Copy link
Member

@adrhill adrhill commented Aug 5, 2022

Closes #82.
Adds Composite, which sequentially applies "Composite Primitives":

To apply a single rule, use:
- LayerRule to apply a rule to the n-th layer of a model
- GlobalRule to apply a rule to all layers of a model
- RangeRule to apply a rule to a positional range of layers of a model
- FirstRule to apply a rule to the first layer of a model
- LastRule to apply a rule to the last layer of a model

To apply a set of rules to multiple layers, use:
- GlobalRuleMap to apply a dictionary that maps layer types to LRP-rules
- FirstNRuleMap for a RuleMap on the first n layers of a model
- LastNRuleMap for a RuleMap on the last n layers
- RangeRuleMap for a RuleMap on generalized ranges

Example

Using a flattened VGG11 model:

julia> composite = Composite(
           GlobalRuleMap(
               ConvLayer => AlphaBetaRule(),
               Dense => EpsilonRule(),
               PoolingLayer => EpsilonRule(),
               DropoutLayer => PassRule(),
               ReshapingLayer => PassRule(),
           ),
           FirstNRuleMap(7, Conv => FlatRule()),
       );

julia> analyzer = LRP(model, composite);

julia> analyzer.rules
19-element Vector{AbstractLRPRule}:
 FlatRule()
 EpsilonRule{Float32}(1.0f-6)
 FlatRule()
 EpsilonRule{Float32}(1.0f-6)
 FlatRule()
 FlatRule()
 EpsilonRule{Float32}(1.0f-6)
 AlphaBetaRule{Float32}(2.0f0, 1.0f0)
 AlphaBetaRule{Float32}(2.0f0, 1.0f0)
 EpsilonRule{Float32}(1.0f-6)
 AlphaBetaRule{Float32}(2.0f0, 1.0f0)
 AlphaBetaRule{Float32}(2.0f0, 1.0f0)
 EpsilonRule{Float32}(1.0f-6)
 PassRule()
 EpsilonRule{Float32}(1.0f-6)
 PassRule()
 EpsilonRule{Float32}(1.0f-6)
 PassRule()
 EpsilonRule{Float32}(1.0f-6)

TODO

  • Pretty-printing of Composites
  • Document Composites in advanced LRP docs

Future work

Moved to PR #85:

  • Add presets similar to those in Zennit, e.g.:
    • EpsilonGammaBox
    • EpsilonPlus
    • EpsilonAlpha2Beta1
    • EpsilonPlusFlat
    • EpsilonAlpha2Beta1Flat
  • Update README with presets

@codecov-commenter
Copy link

codecov-commenter commented Aug 5, 2022

Codecov Report

Merging #84 (271709d) into master (084c962) will increase coverage by 0.29%.
The diff coverage is 97.50%.

@@            Coverage Diff             @@
##           master      #84      +/-   ##
==========================================
+ Coverage   94.23%   94.53%   +0.29%     
==========================================
  Files          13       14       +1     
  Lines         399      439      +40     
==========================================
+ Hits          376      415      +39     
- Misses         23       24       +1     
Impacted Files Coverage Δ
src/lrp/composite.jl 97.22% <97.22%> (ø)
src/lrp/lrp.jl 96.42% <100.00%> (+0.59%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@adrhill adrhill marked this pull request as ready for review August 8, 2022 20:20
@adrhill adrhill merged commit 367b59b into master Aug 8, 2022
@adrhill adrhill deleted the ah/composite branch August 8, 2022 20:21
@adrhill adrhill mentioned this pull request Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add LRP Composites
2 participants