Skip to content

Commit

Permalink
Merge pull request #240 from mldiego/master
Browse files Browse the repository at this point in the history
Fix bug on ImageStar.estimateRanges
  • Loading branch information
mldiego authored Aug 28, 2024
2 parents 94b77c5 + 3eda77b commit 2b13d82
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 27 deletions.
11 changes: 7 additions & 4 deletions code/nnv/engine/set/ImageStar.m
Original file line number Diff line number Diff line change
Expand Up @@ -857,10 +857,13 @@

if isempty(obj.im_lb) || isempty(obj.im_ub)

x1 = obj.V(:,:,:,1) + tensorprod(obj.V(:,:,:,2:end), obj.pred_lb, 4, 1);
x2 = obj.V(:,:,:,1) + tensorprod(obj.V(:,:,:,2:end), obj.pred_ub, 4, 1);
image_lb = min(x1,x2);
image_ub = max(x1,x2);
gens = obj.V(:,:,:,2:end);
pos_gens = gens;
pos_gens(gens < 0) = 0;
neg_gens = gens;
neg_gens(gens > 0) = 0;
image_lb = obj.V(:,:,:,1) + tensorprod(pos_gens, obj.pred_lb, 4, 1) + tensorprod(neg_gens, obj.pred_ub, 4, 1);
image_ub = obj.V(:,:,:,1) + tensorprod(pos_gens, obj.pred_ub, 4, 1) + tensorprod(neg_gens, obj.pred_lb, 4, 1);

obj.im_lb = image_lb;
obj.im_ub = image_ub;
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
22 changes: 18 additions & 4 deletions code/nnv/examples/Submission/WiP_3d/verify_adrenal.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
load(dataset);

% data to verify (test set)
test_images = permute(test_images, [2 3 4 5 1]);
test_images = squeeze(permute(test_images, [2 3 4 5 1]));
test_labels = test_labels + 1;

% load network
Expand All @@ -21,8 +21,22 @@

% select volumes to verify
N = 50;
inputs = single(test_images(:,:,:,:,1:N));
targets = single(test_labels(1:N));
idxs = zeros(N,1);
count = 1;

for i = 1:length(test_labels)
y = classify(matlabNet,test_images(:,:,:,i));
if single(y) == test_labels(i)
idxs(count) = i;
count = count + 1;
end
if count > N
break
end
end

inputs = single(test_images(:,:,:,idxs));
targets = single(test_labels(idxs));

% Reachability parameters
reachOptions = struct;
Expand Down Expand Up @@ -54,7 +68,7 @@

% 3) Begin verification analysis
for i=1:N
img = squeeze(inputs(:,:,:,:,i));
img = inputs(:,:,:,i);
target = targets(i);
results(i,:) = verify_instance_shape(net, img, target, adv_attack, reachOptions);
end
Expand Down
22 changes: 18 additions & 4 deletions code/nnv/examples/Submission/WiP_3d/verify_fracture.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,23 @@
net = matlab2nnv(net);

% select volumes to verify
N = 50; % even for numCores
inputs = single(test_images(:,:,:,:,1:N));
targets = single(test_labels(1:N));
N = 50;
idxs = zeros(N,1);
count = 1;

for i = 1:length(test_labels)
y = classify(matlabNet,test_images(:,:,:,i));
if single(y) == test_labels(i)
idxs(count) = i;
count = count + 1;
end
if count > N
break
end
end

inputs = single(test_images(:,:,:,idxs));
targets = single(test_labels(idxs));

% Reachability parameters
reachOptions = struct;
Expand Down Expand Up @@ -57,7 +71,7 @@

% 3) Begin verification analysis
for i=1:N
img = squeeze(inputs(:,:,:,:,i));
img = inputs(:,:,:,i);
target = targets(i);
results(i,:) = verify_instance_3d(net, img, target, adv_attack, reachOptions);
end
Expand Down
22 changes: 18 additions & 4 deletions code/nnv/examples/Submission/WiP_3d/verify_nodule.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,23 @@
net = matlab2nnv(net);

% select volumes to verify
N = 50; % even for numCores
inputs = single(test_images(:,:,:,:,1:N));
targets = single(test_labels(1:N));
N = 50;
idxs = zeros(N,1);
count = 1;

for i = 1:length(test_labels)
y = classify(matlabNet,test_images(:,:,:,i));
if single(y) == test_labels(i)
idxs(count) = i;
count = count + 1;
end
if count > N
break
end
end

inputs = single(test_images(:,:,:,idxs));
targets = single(test_labels(idxs));

% Reachability parameters
reachOptions = struct;
Expand Down Expand Up @@ -58,7 +72,7 @@

% 3) Begin verification analysis
for i=1:N
img = squeeze(inputs(:,:,:,:,i));
img = inputs(:,:,:,i);
target = targets(i);
results(i,:) = verify_instance_3d(net, img, target, adv_attack, reachOptions);
end
Expand Down
20 changes: 17 additions & 3 deletions code/nnv/examples/Submission/WiP_3d/verify_organ.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,22 @@

% select volumes to verify
N = 50;
inputs = single(test_images(:,:,:,:,1:N));
targets = single(test_labels(1:N));
idxs = zeros(N,1);
count = 1;

for i = 1:length(test_labels)
y = classify(matlabNet,test_images(:,:,:,i));
if single(y) == test_labels(i)
idxs(count) = i;
count = count + 1;
end
if count > N
break
end
end

inputs = single(test_images(:,:,:,idxs));
targets = single(test_labels(idxs));

% Reachability parameters
reachOptions = struct;
Expand Down Expand Up @@ -57,7 +71,7 @@

% 3) Begin verification analysis
for i=1:N
img = squeeze(inputs(:,:,:,:,i));
img = inputs(:,:,:,i);
target = targets(i);
results(i,:) = verify_instance_3d(net, img, target, adv_attack, reachOptions);
end
Expand Down
22 changes: 18 additions & 4 deletions code/nnv/examples/Submission/WiP_3d/verify_synapse.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,23 @@
net = matlab2nnv(net);

% select volumes to verify
N = 50; % even for numCores
inputs = single(test_images(:,:,:,:,1:N));
targets = single(test_labels(1:N));
N = 50;
idxs = zeros(N,1);
count = 1;

for i = 1:length(test_labels)
y = classify(matlabNet,test_images(:,:,:,i));
if single(y) == test_labels(i)
idxs(count) = i;
count = count + 1;
end
if count > N
break
end
end

inputs = single(test_images(:,:,:,idxs));
targets = single(test_labels(idxs));

% Reachability parameters
reachOptions = struct;
Expand Down Expand Up @@ -57,7 +71,7 @@

% 3) Begin verification analysis
for i=1:N
img = squeeze(inputs(:,:,:,:,i));
img = inputs(:,:,:,i);
target = targets(i);
results(i,:) = verify_instance_3d(net, img, target, adv_attack, reachOptions);
end
Expand Down
22 changes: 18 additions & 4 deletions code/nnv/examples/Submission/WiP_3d/verify_vessel.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,23 @@
net = matlab2nnv(net);

% select volumes to verify
N = 50; % even for numCores
inputs = single(test_images(:,:,:,:,1:N));
targets = single(test_labels(1:N));
N = 50;
idxs = zeros(N,1);
count = 1;

for i = 1:length(test_labels)
y = classify(matlabNet,test_images(:,:,:,i));
if single(y) == test_labels(i)
idxs(count) = i;
count = count + 1;
end
if count > N
break
end
end

inputs = single(test_images(:,:,:,idxs));
targets = single(test_labels(idxs));

% Reachability parameters
reachOptions = struct;
Expand Down Expand Up @@ -52,7 +66,7 @@

% 3) Begin verification analysis
for i=1:N
img = squeeze(inputs(:,:,:,:,i));
img = inputs(:,:,:,i);
target = targets(i);
results(i,:) = verify_instance_shape(net, img, target, adv_attack, reachOptions);
end
Expand Down

0 comments on commit 2b13d82

Please sign in to comment.