Skip to content

Commit 4776821

Browse files
authored
Merge pull request #287 from cirens-utd/master
Changes for MNIST MLP experiment with weight perturbation, will run tests shortly
2 parents 036a521 + 8f1bc7d commit 4776821

File tree

17 files changed

+3786
-14
lines changed

17 files changed

+3786
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ code/nnv/UUV/
33
code/nnv/tbxmanager/
44
code/nnv/tests/io/models/*.caffemodel
55
.venv
6+
*.asv
67

78

89
data/vgg16_cache.mat

code/nnv/engine/nn/NN.m

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
input_sets = {}; % input set values for each layer (cell array of cells of layer input sets)
4141
dis_opt = []; % display option = 'display' or []
4242
lp_solver = 'linprog'; % choose linprog as default LP solver for constructing reachable set user can choose 'glpk' or 'linprog' as an LP solver
43+
matlabnet = []; % the matlab network this NN was created from
4344

4445
% To facilitate graph computation flow
4546
name2indx = []; % Match name to index in nnvLayers list
@@ -440,21 +441,57 @@
440441
methods % secondary methods (verification, safety, robustness...)
441442

442443
% Verify a VNN-LIB specification
443-
function result = verify_vnnlib(obj, propertyFile, reachOptions)
444+
function [result, X] = verify_vnnlib(obj, propertyFile, reachOptions, needReshape)
445+
446+
arguments
447+
obj
448+
propertyFile
449+
reachOptions
450+
needReshape = 0;
451+
end
444452

445453
% Load specification to verify
446454
property = load_vnnlib(propertyFile);
447455
lb = property.lb;
448456
ub = property.ub;
449-
457+
458+
if isfield(reachOptions, 'single_average_input') && reachOptions.single_average_input
459+
if ~isa(lb, 'cell')
460+
lb = (lb + ub)/2;
461+
ub = lb;
462+
else
463+
lb = (lb{1} + ub{1})/2;
464+
ub = lb;
465+
end
466+
end
467+
468+
if needReshape > 0.1
469+
% Format bounds into correct dimensions
470+
% (using code from run_vnncomp2024_instance.m)
471+
472+
first_layer = obj.Layers(1, 1);
473+
inputSize = first_layer{1}.InputSize;
474+
if needReshape == 1
475+
lb = permute(lb, [2 1 3]);
476+
ub = permute(ub, [2 1 3]);
477+
elseif needReshape == 2
478+
newSize = [inputSize(2) inputSize(1) inputSize(3:end)];
479+
lb = reshape(lb, newSize);
480+
lb = permute(lb, [2 1 3 4]);
481+
ub = reshape(ub, newSize);
482+
ub = permute(ub, [2 1 3 4]);
483+
else
484+
error("Unsupported value for needReshape")
485+
end
486+
end
487+
450488
% Create reachability parameters and options
451489
if contains(reachOptions.reachMethod, "zono")
452490
X = ImageZono(lb, ub);
453491
else
454-
X = ImageStar(lb,ub);
492+
X = ImageStar(lb, ub);
455493
end
456-
457-
% Compute reachability
494+
458495
Y = obj.reach(X, reachOptions); % Seems to be working
459496
result = verify_specification(Y, property.prop);
460497

@@ -1473,6 +1510,18 @@ function start_pool(obj)
14731510
end
14741511
end
14751512

1513+
% return the indices of layers of the specified types
1514+
function layers = get_layer_indices(obj, layer_types)
1515+
layers = [];
1516+
for l = 1:length(obj.Layers)
1517+
for n = 1:length(layer_types)
1518+
if isa(obj.Layers{l}, layer_types(n))
1519+
layers = [layers l];
1520+
end
1521+
end
1522+
end
1523+
end
1524+
14761525
end % end helper functions
14771526

14781527

0 commit comments

Comments
 (0)