提交 c4dd9543 编写于 作者: J jin-xiulang

Fix two api issues.

上级 3746066c
...@@ -39,21 +39,21 @@ def test_lenet_mnist_fuzzing(): ...@@ -39,21 +39,21 @@ def test_lenet_mnist_fuzzing():
load_param_into_net(net, load_dict) load_param_into_net(net, load_dict)
model = Model(net) model = Model(net)
mutate_config = [{'method': 'Blur', mutate_config = [{'method': 'Blur',
'params': {'auto_param': True}}, 'params': {'auto_param': True}},
{'method': 'Contrast', {'method': 'Contrast',
'params': {'auto_param': True}}, 'params': {'auto_param': True}},
{'method': 'Translate', {'method': 'Translate',
'params': {'auto_param': True}}, 'params': {'auto_param': True}},
{'method': 'Brightness', {'method': 'Brightness',
'params': {'auto_param': True}}, 'params': {'auto_param': True}},
{'method': 'Noise', {'method': 'Noise',
'params': {'auto_param': True}}, 'params': {'auto_param': True}},
{'method': 'Scale', {'method': 'Scale',
'params': {'auto_param': True}}, 'params': {'auto_param': True}},
{'method': 'Shear', {'method': 'Shear',
'params': {'auto_param': True}}, 'params': {'auto_param': True}},
{'method': 'FGSM', {'method': 'FGSM',
'params': {'eps': 0.3, 'alpha': 0.1}} 'params': {'eps': 0.3, 'alpha': 0.1}}
] ]
# get training data # get training data
...@@ -87,7 +87,7 @@ def test_lenet_mnist_fuzzing(): ...@@ -87,7 +87,7 @@ def test_lenet_mnist_fuzzing():
# make initial seeds # make initial seeds
for img, label in zip(test_images, test_labels): for img, label in zip(test_images, test_labels):
initial_seeds.append([img, label, 0]) initial_seeds.append([img, label])
initial_seeds = initial_seeds[:100] initial_seeds = initial_seeds[:100]
model_coverage_test.calculate_coverage( model_coverage_test.calculate_coverage(
......
...@@ -141,8 +141,8 @@ class Fuzzer: ...@@ -141,8 +141,8 @@ class Fuzzer:
Args: Args:
mutate_config (list): Mutate configs. The format is mutate_config (list): Mutate configs. The format is
[{'method': 'Blur', 'params': {'auto_param': True}}, [{'method': 'Blur', 'params': {'auto_param': True}},
{'method': 'Contrast', 'params': {'factor': 2}}]. {'method': 'Contrast', 'params': {'factor': 2}}]. The
The supported methods list is in `self._strategies`, and the supported methods list is in `self._strategies`, and the
params of each method must within the range of changeable parameters.  params of each method must within the range of changeable parameters. 
Supported methods are grouped in three types: Supported methods are grouped in three types:
Firstly, pixel value based transform methods include: Firstly, pixel value based transform methods include:
...@@ -153,8 +153,9 @@ class Fuzzer: ...@@ -153,8 +153,9 @@ class Fuzzer:
transform methods. The way of setting parameters for first and transform methods. The way of setting parameters for first and
second type methods can be seen in 'mindarmour/fuzzing/image_transform.py'. second type methods can be seen in 'mindarmour/fuzzing/image_transform.py'.
For third type methods, you can refer to the corresponding class. For third type methods, you can refer to the corresponding class.
initial_seeds (numpy.ndarray): Initial seeds used to generate initial_seeds (list[list]): Initial seeds used to generate mutated
mutated samples. samples. The format of initial seeds is [[image_data, label],
[...], ...].
coverage_metric (str): Model coverage metric of neural networks. All coverage_metric (str): Model coverage metric of neural networks. All
supported metrics are: 'KMNC', 'NBC', 'SNAC'. Default: 'KMNC'. supported metrics are: 'KMNC', 'NBC', 'SNAC'. Default: 'KMNC'.
eval_metrics (Union[list, tuple, str]): Evaluation metrics. If the eval_metrics (Union[list, tuple, str]): Evaluation metrics. If the
...@@ -210,8 +211,18 @@ class Fuzzer: ...@@ -210,8 +211,18 @@ class Fuzzer:
# Check whether the mutate_config meet the specification. # Check whether the mutate_config meet the specification.
mutate_config = check_param_type('mutate_config', mutate_config, list) mutate_config = check_param_type('mutate_config', mutate_config, list)
for method in mutate_config: for config in mutate_config:
check_param_type("method['params']", method['params'], dict) check_param_type("config['params']", config['params'], dict)
if set(config.keys()) != {'method', 'params'}:
msg = "Config must contain 'method' and 'params', but got {}." \
.format(set(config.keys()))
LOGGER.error(TAG, msg)
raise TypeError(msg)
if config['method'] not in self._strategies.keys():
msg = "Config methods must be in {}, but got {}." \
.format(self._strategies.keys(), config['method'])
LOGGER.error(TAG, msg)
raise TypeError(msg)
if coverage_metric not in ['KMNC', 'NBC', 'SNAC']: if coverage_metric not in ['KMNC', 'NBC', 'SNAC']:
msg = "coverage_metric must be in ['KMNC', 'NBC', 'SNAC'], but got {}." \ msg = "coverage_metric must be in ['KMNC', 'NBC', 'SNAC'], but got {}." \
.format(coverage_metric) .format(coverage_metric)
...@@ -225,10 +236,7 @@ class Fuzzer: ...@@ -225,10 +236,7 @@ class Fuzzer:
check_param_type('seed', seed, list) check_param_type('seed', seed, list)
check_numpy_param('seed[0]', seed[0]) check_numpy_param('seed[0]', seed[0])
check_numpy_param('seed[1]', seed[1]) check_numpy_param('seed[1]', seed[1])
if seed[2] != 0: seed.append(0)
msg = "initial seed[2] must be 0, but got {}.".format(seed[2])
LOGGER.error(TAG, msg)
raise ValueError(msg)
seed, initial_seeds = _select_next(initial_seeds) seed, initial_seeds = _select_next(initial_seeds)
fuzz_samples = [] fuzz_samples = []
gt_labels = [] gt_labels = []
......
...@@ -140,8 +140,8 @@ class ModelCoverageMetrics: ...@@ -140,8 +140,8 @@ class ModelCoverageMetrics:
Args: Args:
dataset (numpy.ndarray): Data for fuzz test. dataset (numpy.ndarray): Data for fuzz test.
bias_coefficient (float): The coefficient used for changing the bias_coefficient (Union[int, float]): The coefficient used
neurons' output boundaries. Default: 0. for changing the neurons' output boundaries. Default: 0.
batch_size (int): The number of samples in a predict batch. batch_size (int): The number of samples in a predict batch.
Default: 32. Default: 32.
......
...@@ -113,7 +113,7 @@ def test_fuzzing_ascend(): ...@@ -113,7 +113,7 @@ def test_fuzzing_ascend():
initial_seeds = [] initial_seeds = []
# make initial seeds # make initial seeds
for img, label in zip(test_images, test_labels): for img, label in zip(test_images, test_labels):
initial_seeds.append([img, label, 0]) initial_seeds.append([img, label])
initial_seeds = initial_seeds[:100] initial_seeds = initial_seeds[:100]
model_coverage_test.calculate_coverage( model_coverage_test.calculate_coverage(
...@@ -159,7 +159,7 @@ def test_fuzzing_cpu(): ...@@ -159,7 +159,7 @@ def test_fuzzing_cpu():
initial_seeds = [] initial_seeds = []
# make initial seeds # make initial seeds
for img, label in zip(test_images, test_labels): for img, label in zip(test_images, test_labels):
initial_seeds.append([img, label, 0]) initial_seeds.append([img, label])
initial_seeds = initial_seeds[:100] initial_seeds = initial_seeds[:100]
model_coverage_test.calculate_coverage( model_coverage_test.calculate_coverage(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册