File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed
Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 2222function analyze (input:: AbstractArray{<:Real} , method:: AbstractXAIMethod ; kwargs... )
2323 return method (input, MaxActivationNS (); kwargs... )
2424end
25+ function (method:: AbstractXAIMethod )(input:: AbstractArray{<:Real} ; kwargs... )
26+ return method (input, MaxActivationNS (); kwargs... )
27+ end
2528
2629# Explanations and outputs are returned in a wrapper.
2730# Metadata such as the analyzer allows dispatching on functions like `heatmap`.
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ function LRP(model::Chain, r::AbstractLRPRule; kwargs...)
4242 return LRP (model, rules; kwargs... )
4343end
4444# Additional constructors for convenience:
45+ LRP (model:: Chain ; kwargs... ) = LRP (model, ZeroRule (); kwargs... )
4546LRPZero (model:: Chain ; kwargs... ) = LRP (model, ZeroRule (); kwargs... )
4647LRPEpsilon (model:: Chain ; kwargs... ) = LRP (model, EpsilonRule (); kwargs... )
4748LRPGamma (model:: Chain ; kwargs... ) = LRP (model, GammaRule (); kwargs... )
Original file line number Diff line number Diff line change 2828function test_vgg11 (name, method; kwargs... )
2929 analyzer = method (model)
3030 @testset " $name " begin
31+ # Reference test attribution
3132 print (" Timing $name ...\t " )
3233 @time expl = analyze (img, analyzer; kwargs... )
3334 attr = expl. attribution
34-
3535 @test size (attr) == size (img)
3636 @test_reference " references/vgg11/$(name) .jld2" Dict (" expl" => attr) by =
3737 (r, a) -> isapprox (r[" expl" ], a[" expl" ]; rtol= 0.05 )
3838
39+ # Test direct call of analyzer
40+ expl2 = analyzer (img; kwargs... )
41+ @test expl. attribution ≈ expl2. attribution
42+
43+ # Test direct call of heatmap
3944 h1 = heatmap (expl)
4045 h2 = heatmap (img, analyzer; kwargs... )
4146 @test h1 ≈ h2
7580@testset " Layerwise relevances" begin
7681 test_vgg11 (" LRPZero" , LRPZero; layerwise_relevances= true )
7782end
83+
84+ # Test LRP constructor with no rules
85+ a1 = LRP (model)
86+ a2 = LRPZero (model)
87+ @test a1. model == a2. model
88+ @test a1. rules == a2. rules
You can’t perform that action at this time.
0 commit comments