Browse Source

!263 fix bug of bounds check in fuzzer

Merge pull request !263 from ZhidanLiu/master
tags/v1.6.0
i-robot Gitee 3 years ago
parent
commit
d61b660623
3 changed files with 7 additions and 5 deletions
  1. +1
    -1
      examples/ai_fuzzer/lenet5_mnist_fuzzing.py
  2. +4
    -4
      mindarmour/fuzz_testing/fuzzing.py
  3. +2
    -0
      mindarmour/fuzz_testing/model_coverage_metrics.py

+ 1
- 1
examples/ai_fuzzer/lenet5_mnist_fuzzing.py View File

@@ -51,7 +51,7 @@ def test_lenet_mnist_fuzzing():
{'method': 'Shear',
'params': {'auto_param': [True]}},
{'method': 'FGSM',
'params': {'eps': [0.3, 0.2, 0.4], 'alpha': [0.1]}}
'params': {'eps': [0.3, 0.2, 0.4], 'alpha': [0.1], 'bounds': [(0, 1)]}}
]

# get training data


+ 4
- 4
mindarmour/fuzz_testing/fuzzing.py View File

@@ -191,9 +191,9 @@ class Fuzzer:
- dict, metrics report of fuzzer.

Raises:
ValueError, coverage must be subclass of CoverageMetrics.
ValueError, if initial seeds is empty.
ValueError, if element of seed is not two in initial seeds.
ValueError: Coverage must be subclass of CoverageMetrics.
ValueError: If initial seeds is empty.
ValueError: If element of seed is not two in initial seeds.
"""
# Check parameters.
if not isinstance(coverage, CoverageMetrics):
@@ -356,7 +356,7 @@ class Fuzzer:
check_param_type(param_name, params[param_name], list)
for param_value in params[param_name]:
if param_name == 'bounds':
_ = check_param_bounds('bounds', param_name)
_ = check_param_bounds('bounds', param_value)
elif param_name == 'norm_level':
_ = check_norm_level(param_value)
else:


+ 2
- 0
mindarmour/fuzz_testing/model_coverage_metrics.py View File

@@ -157,8 +157,10 @@ class NeuronCoverage(CoverageMetrics):
"""
def __init__(self, model, threshold=0.1, incremental=False, batch_size=32):
super(NeuronCoverage, self).__init__(model, incremental, batch_size)
threshold = check_param_type('threshold', threshold, float)
self.threshold = check_value_positive('threshold', threshold)


def get_metrics(self, dataset):
"""
Get the metric of neuron coverage: the proportion of activated neurons to total neurons in the network.


Loading…
Cancel
Save