Skip to content

Commit 9c16fc5

Browse files
authored
Add reference tests on VGG-19 (#11)
* fix gradient methods not using the Flux model in test-mode * add reference tests on VGG-19 with random weights, therefore not requiring large downloads of parameters * remove test dependency on Metalhead * update CI configuration
1 parent e6f92d2 commit 9c16fc5

30 files changed

+241
-58
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
name: CI
22
on:
3-
- push
4-
- pull_request
3+
pull_request:
4+
branches:
5+
- master
6+
push:
7+
branches:
8+
- master
59
jobs:
610
test:
711
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}

Project.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,15 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
1515
ColorSchemes = "3"
1616
Flux = "0.12"
1717
ImageCore = "0.8, 0.9"
18-
Metalhead = "0.6"
18+
JLD2 = "0.4"
1919
Zygote = "0.6"
2020
julia = "1.6"
2121

2222
[extras]
23-
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
24-
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
25-
Metalhead = "dbeba491-748d-5e0e-a39e-b530a07fa0cc"
23+
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
2624
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2725
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
2826
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
29-
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
3027

3128
[targets]
32-
test = ["ImageMagick", "Images", "Metalhead", "Random", "ReferenceTests", "Test", "TestImages"]
29+
test = ["JLD2", "Random", "ReferenceTests", "Test"]

src/gradient.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
struct Gradient{C<:Chain} <: AbstractXAIMethod
22
model::C
3-
Gradient(model::Chain) = new{typeof(model)}(check_ouput_softmax(model))
3+
Gradient(model::Chain) = new{typeof(model)}(Flux.testmode!(check_ouput_softmax(model)))
44
end
5-
function (method::Gradient)(input, ns::AbstractNeuronSelector)
6-
output = method.model(input)
5+
function (analyzer::Gradient)(input, ns::AbstractNeuronSelector)
6+
output = analyzer.model(input)
77
output_neuron = ns(output)
8-
expl = gradient((in) -> method.model(in)[output_neuron], input)[1]
8+
expl = gradient((in) -> analyzer.model(in)[output_neuron], input)[1]
99
return expl, output
1010
end
1111

1212
struct InputTimesGradient{C<:Chain} <: AbstractXAIMethod
1313
model::C
14-
InputTimesGradient(model::Chain) = new{typeof(model)}(check_ouput_softmax(model))
14+
InputTimesGradient(model::Chain) = new{typeof(model)}(Flux.testmode!(check_ouput_softmax(model)))
1515
end
1616
function (analyzer::InputTimesGradient)(input, ns::AbstractNeuronSelector)
1717
output = analyzer.model(input)
853 Bytes
Binary file not shown.

test/references/rules/EpsilonRule_Dense_identity.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
853 Bytes
Binary file not shown.

test/references/rules/EpsilonRule_Dense_relu.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
853 Bytes
Binary file not shown.

test/references/rules/GammaRule_Dense_identity.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
853 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)