-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
6,031 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5,655 changes: 5,655 additions & 0 deletions
5,655
examples/cars_workshop/.ipynb_checkpoints/4 visualverification-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
2 | ||
2,2,2 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 | ||
1,1 | ||
-1,1 | ||
-1 | ||
-1 | ||
1,0 | ||
0,1 | ||
0 | ||
0 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using LazySets, Test, LinearAlgebra, GLPKMathProgInterface | ||
using NeuralVerification | ||
import NeuralVerification: ReLU, Id | ||
using JLD2 | ||
|
||
function test_solver(solver, test_selected) | ||
|
||
# index of all violated cases in the first 1000 images. | ||
violation_idx = [25, 142, 179, 183, 283, 285, 387, 392, 612, 647, 737] | ||
# index of selected holding cases in the first 1000 images. | ||
satisfied_idx = [10, 100, 200, 300, 400, 500 ,600, 700, 800, 900, 999, 213, 391, 660, 911] | ||
|
||
if test_selected | ||
test_idx = [violation_idx; satisfied_idx] | ||
else | ||
test_idx = 1:1000 | ||
end | ||
|
||
@load "MNIST_1000_data.jld2" train_x train_y | ||
|
||
net_file = "$(@__DIR__)/../examples/networks/mnist_1000.nnet" | ||
mnist_net = read_nnet(net_file, last_layer_activation = Id()) | ||
|
||
for i = test_idx | ||
|
||
input_center = reshape(train_x[:,:,i], 28*28) | ||
label = train_y[i] | ||
A = zeros(Float64, 10, 10) | ||
A[diagind(A)] .= 1 | ||
A[:, label+1] = A[:, label+1] .- 1 | ||
A = A[1:end .!= label+1,:] | ||
|
||
b = zeros(Float64, 9) | ||
|
||
Y = HPolytope(A, b) | ||
pred = argmax(NeuralVerification.compute_output(mnist_net, input_center))-1 | ||
|
||
if pred != label | ||
continue | ||
end | ||
|
||
epsilon = 1.0/255.0 | ||
upper = input_center .+ epsilon | ||
lower = input_center .- epsilon | ||
clamp!(upper, 0.0, 1.0) | ||
clamp!(lower, 0.0, 1.0) | ||
X = Hyperrectangle(low=lower, high=upper) | ||
|
||
problem_mnist = Problem(mnist_net, X, Y) | ||
|
||
result = solve(solver, problem_mnist) | ||
|
||
if result.status == :violated | ||
@test i ∈ violation_idx | ||
noisy = argmax(NeuralVerification.compute_output(mnist_net, result.counter_example))-1 | ||
@test noisy != pred | ||
elseif result.status == :holds | ||
@test !(i ∈ violation_idx) | ||
else #result.status == :unknown | ||
|
||
end | ||
end | ||
end | ||
|
||
# if test_selected = true, only test selected index. Otherwise, test all 1000 images. | ||
test_selected = true | ||
|
||
# Please note the number of tests maybe different for different solvers. | ||
# Because the test cases depends on the result. | ||
|
||
if test_selected | ||
@testset "MNIST selected, ReluVal" begin | ||
test_solver(ReluVal(), test_selected) | ||
end | ||
@testset "MNIST selected, Neurify" begin | ||
test_solver(Neurify(), test_selected) | ||
end | ||
else | ||
@testset "MNIST 1000, ReluVal" begin | ||
test_solver(ReluVal(), test_selected) | ||
end | ||
@testset "MNIST 1000, Neurify" begin | ||
test_solver(Neurify(), test_selected) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.