提交 9d4e3959 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!91 fix issues

Merge pull request !91 from ZhidanLiu/master
...@@ -51,7 +51,7 @@ def test_lenet_mnist_coverage(): ...@@ -51,7 +51,7 @@ def test_lenet_mnist_coverage():
train_images = np.concatenate(train_images, axis=0) train_images = np.concatenate(train_images, axis=0)
# initialize fuzz test with training dataset # initialize fuzz test with training dataset
model_fuzz_test = ModelCoverageMetrics(model, 10000, 10, train_images) model_fuzz_test = ModelCoverageMetrics(model, 10, 1000, train_images)
# fuzz test with original test data # fuzz test with original test data
# get test data # get test data
......
...@@ -41,11 +41,19 @@ def test_lenet_mnist_fuzzing(): ...@@ -41,11 +41,19 @@ def test_lenet_mnist_fuzzing():
mutate_config = [{'method': 'Blur', mutate_config = [{'method': 'Blur',
'params': {'auto_param': True}}, 'params': {'auto_param': True}},
{'method': 'Contrast', {'method': 'Contrast',
'params': {'factor': 2}}, 'params': {'auto_param': True}},
{'method': 'Translate', {'method': 'Translate',
'params': {'x_bias': 0.1, 'y_bias': 0.2}}, 'params': {'auto_param': True}},
{'method': 'Brightness',
'params': {'auto_param': True}},
{'method': 'Noise',
'params': {'auto_param': True}},
{'method': 'Scale',
'params': {'auto_param': True}},
{'method': 'Shear',
'params': {'auto_param': True}},
{'method': 'FGSM', {'method': 'FGSM',
'params': {'eps': 0.1, 'alpha': 0.1}} 'params': {'eps': 0.3, 'alpha': 0.1}}
] ]
# get training data # get training data
...@@ -59,7 +67,7 @@ def test_lenet_mnist_fuzzing(): ...@@ -59,7 +67,7 @@ def test_lenet_mnist_fuzzing():
train_images = np.concatenate(train_images, axis=0) train_images = np.concatenate(train_images, axis=0)
# initialize fuzz test with training dataset # initialize fuzz test with training dataset
model_coverage_test = ModelCoverageMetrics(model, 1000, 10, train_images) model_coverage_test = ModelCoverageMetrics(model, 10, 1000, train_images)
# fuzz test with original test data # fuzz test with original test data
# get test data # get test data
......
...@@ -102,8 +102,9 @@ class Fuzzer: ...@@ -102,8 +102,9 @@ class Fuzzer:
self._target_model = check_model('model', target_model, Model) self._target_model = check_model('model', target_model, Model)
train_dataset = check_numpy_param('train_dataset', train_dataset) train_dataset = check_numpy_param('train_dataset', train_dataset)
self._coverage_metrics = ModelCoverageMetrics(target_model, self._coverage_metrics = ModelCoverageMetrics(target_model,
neuron_num,
segmented_num, segmented_num,
neuron_num, train_dataset) train_dataset)
# Allowed mutate strategies so far. # Allowed mutate strategies so far.
self._strategies = {'Contrast': Contrast, 'Brightness': Brightness, self._strategies = {'Contrast': Contrast, 'Brightness': Brightness,
'Blur': Blur, 'Noise': Noise, 'Translate': Translate, 'Blur': Blur, 'Noise': Noise, 'Translate': Translate,
...@@ -190,11 +191,6 @@ class Fuzzer: ...@@ -190,11 +191,6 @@ class Fuzzer:
eval_metrics_ = [] eval_metrics_ = []
avaliable_metrics = ['accuracy', 'attack_success_rate', 'kmnc', 'nbc', 'snac'] avaliable_metrics = ['accuracy', 'attack_success_rate', 'kmnc', 'nbc', 'snac']
for elem in eval_metrics: for elem in eval_metrics:
if not isinstance(elem, str):
msg = 'the type of metric in list `eval_metrics` must be str, but got {}.' \
.format(type(elem))
LOGGER.error(TAG, msg)
raise TypeError(msg)
if elem not in avaliable_metrics: if elem not in avaliable_metrics:
msg = 'metric in list `eval_metrics` must be in {}, but got {}.' \ msg = 'metric in list `eval_metrics` must be in {}, but got {}.' \
.format(avaliable_metrics, elem) .format(avaliable_metrics, elem)
......
...@@ -43,8 +43,8 @@ class ModelCoverageMetrics: ...@@ -43,8 +43,8 @@ class ModelCoverageMetrics:
Args: Args:
model (Model): The pre-trained model which waiting for testing. model (Model): The pre-trained model which waiting for testing.
segmented_num (int): The number of segmented sections of neurons' output intervals.
neuron_num (int): The number of testing neurons. neuron_num (int): The number of testing neurons.
segmented_num (int): The number of segmented sections of neurons' output intervals.
train_dataset (numpy.ndarray): Training dataset used for determine train_dataset (numpy.ndarray): Training dataset used for determine
the neurons' output boundaries. the neurons' output boundaries.
...@@ -56,14 +56,14 @@ class ModelCoverageMetrics: ...@@ -56,14 +56,14 @@ class ModelCoverageMetrics:
>>> train_images = np.random.random((10000, 1, 32, 32)).astype(np.float32) >>> train_images = np.random.random((10000, 1, 32, 32)).astype(np.float32)
>>> test_images = np.random.random((5000, 1, 32, 32)).astype(np.float32) >>> test_images = np.random.random((5000, 1, 32, 32)).astype(np.float32)
>>> model = Model(net) >>> model = Model(net)
>>> model_fuzz_test = ModelCoverageMetrics(model, 10000, 10, train_images) >>> model_fuzz_test = ModelCoverageMetrics(model, 10, 1000, train_images)
>>> model_fuzz_test.calculate_coverage(test_images) >>> model_fuzz_test.calculate_coverage(test_images)
>>> print('KMNC of this test is : %s', model_fuzz_test.get_kmnc()) >>> print('KMNC of this test is : %s', model_fuzz_test.get_kmnc())
>>> print('NBC of this test is : %s', model_fuzz_test.get_nbc()) >>> print('NBC of this test is : %s', model_fuzz_test.get_nbc())
>>> print('SNAC of this test is : %s', model_fuzz_test.get_snac()) >>> print('SNAC of this test is : %s', model_fuzz_test.get_snac())
""" """
def __init__(self, model, segmented_num, neuron_num, train_dataset): def __init__(self, model, neuron_num, segmented_num, train_dataset):
self._model = check_model('model', model, Model) self._model = check_model('model', model, Model)
self._segmented_num = check_int_positive('segmented_num', segmented_num) self._segmented_num = check_int_positive('segmented_num', segmented_num)
self._neuron_num = check_int_positive('neuron_num', neuron_num) self._neuron_num = check_int_positive('neuron_num', neuron_num)
......
...@@ -71,7 +71,7 @@ def test_lenet_mnist_coverage_cpu(): ...@@ -71,7 +71,7 @@ def test_lenet_mnist_coverage_cpu():
# initialize fuzz test with training dataset # initialize fuzz test with training dataset
training_data = (np.random.random((10000, 10))*20).astype(np.float32) training_data = (np.random.random((10000, 10))*20).astype(np.float32)
model_fuzz_test = ModelCoverageMetrics(model, 10000, 10, training_data) model_fuzz_test = ModelCoverageMetrics(model, 10, 1000, training_data)
# fuzz test with original test data # fuzz test with original test data
# get test data # get test data
...@@ -105,7 +105,7 @@ def test_lenet_mnist_coverage_ascend(): ...@@ -105,7 +105,7 @@ def test_lenet_mnist_coverage_ascend():
# initialize fuzz test with training dataset # initialize fuzz test with training dataset
training_data = (np.random.random((10000, 10))*20).astype(np.float32) training_data = (np.random.random((10000, 10))*20).astype(np.float32)
model_fuzz_test = ModelCoverageMetrics(model, 10000, 10, training_data) model_fuzz_test = ModelCoverageMetrics(model, 10, 1000, training_data)
# fuzz test with original test data # fuzz test with original test data
# get test data # get test data
......
...@@ -102,7 +102,7 @@ def test_fuzzing_ascend(): ...@@ -102,7 +102,7 @@ def test_fuzzing_ascend():
] ]
# initialize fuzz test with training dataset # initialize fuzz test with training dataset
train_images = np.random.rand(32, 1, 32, 32).astype(np.float32) train_images = np.random.rand(32, 1, 32, 32).astype(np.float32)
model_coverage_test = ModelCoverageMetrics(model, 1000, 10, train_images) model_coverage_test = ModelCoverageMetrics(model, 10, 1000, train_images)
# fuzz test with original test data # fuzz test with original test data
# get test data # get test data
...@@ -148,7 +148,7 @@ def test_fuzzing_cpu(): ...@@ -148,7 +148,7 @@ def test_fuzzing_cpu():
] ]
# initialize fuzz test with training dataset # initialize fuzz test with training dataset
train_images = np.random.rand(32, 1, 32, 32).astype(np.float32) train_images = np.random.rand(32, 1, 32, 32).astype(np.float32)
model_coverage_test = ModelCoverageMetrics(model, 1000, 10, train_images) model_coverage_test = ModelCoverageMetrics(model, 10, 1000, train_images)
# fuzz test with original test data # fuzz test with original test data
# get test data # get test data
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册