From 1e7e93f4eeef68c991e7a7a070bd0171acd8821e Mon Sep 17 00:00:00 2001 From: ZhidanLiu Date: Thu, 26 Aug 2021 15:21:39 +0800 Subject: [PATCH] fix bug of bounds check in fuzzer --- examples/ai_fuzzer/lenet5_mnist_fuzzing.py | 2 +- mindarmour/fuzz_testing/fuzzing.py | 8 ++++---- mindarmour/fuzz_testing/model_coverage_metrics.py | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/ai_fuzzer/lenet5_mnist_fuzzing.py b/examples/ai_fuzzer/lenet5_mnist_fuzzing.py index 2c49e39..3a30b6d 100644 --- a/examples/ai_fuzzer/lenet5_mnist_fuzzing.py +++ b/examples/ai_fuzzer/lenet5_mnist_fuzzing.py @@ -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 diff --git a/mindarmour/fuzz_testing/fuzzing.py b/mindarmour/fuzz_testing/fuzzing.py index 3b9ce74..835f259 100644 --- a/mindarmour/fuzz_testing/fuzzing.py +++ b/mindarmour/fuzz_testing/fuzzing.py @@ -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: diff --git a/mindarmour/fuzz_testing/model_coverage_metrics.py b/mindarmour/fuzz_testing/model_coverage_metrics.py index 7b87cd3..8afd371 100644 --- a/mindarmour/fuzz_testing/model_coverage_metrics.py +++ b/mindarmour/fuzz_testing/model_coverage_metrics.py @@ -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.