Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindarmour
提交
c4dd9543
M
mindarmour
项目概览
MindSpore
/
mindarmour
通知
4
Star
2
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindarmour
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c4dd9543
编写于
8月 26, 2020
作者:
J
jin-xiulang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix two api issues.
上级
3746066c
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
38 addition
and
30 deletion
+38
-30
example/mnist_demo/lenet5_mnist_fuzzing.py
example/mnist_demo/lenet5_mnist_fuzzing.py
+16
-16
mindarmour/fuzzing/fuzzing.py
mindarmour/fuzzing/fuzzing.py
+18
-10
mindarmour/fuzzing/model_coverage_metrics.py
mindarmour/fuzzing/model_coverage_metrics.py
+2
-2
tests/ut/python/fuzzing/test_fuzzer.py
tests/ut/python/fuzzing/test_fuzzer.py
+2
-2
未找到文件。
example/mnist_demo/lenet5_mnist_fuzzing.py
浏览文件 @
c4dd9543
...
...
@@ -87,7 +87,7 @@ def test_lenet_mnist_fuzzing():
# make initial seeds
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
]
model_coverage_test
.
calculate_coverage
(
...
...
mindarmour/fuzzing/fuzzing.py
浏览文件 @
c4dd9543
...
...
@@ -141,8 +141,8 @@ class Fuzzer:
Args:
mutate_config (list): Mutate configs. The format is
[{'method': 'Blur', 'params': {'auto_param': True}},
{'method': 'Contrast', 'params': {'factor': 2}}].
The
supported methods list is in `self._strategies`, and the
{'method': 'Contrast', 'params': {'factor': 2}}]. The
supported methods list is in `self._strategies`, and the
params of each method must within the range of changeable parameters.
Supported methods are grouped in three types:
Firstly, pixel value based transform methods include:
...
...
@@ -153,8 +153,9 @@ class Fuzzer:
transform methods. The way of setting parameters for first and
second type methods can be seen in 'mindarmour/fuzzing/image_transform.py'.
For third type methods, you can refer to the corresponding class.
initial_seeds (numpy.ndarray): Initial seeds used to generate
mutated samples.
initial_seeds (list[list]): Initial seeds used to generate mutated
samples. The format of initial seeds is [[image_data, label],
[...], ...].
coverage_metric (str): Model coverage metric of neural networks. All
supported metrics are: 'KMNC', 'NBC', 'SNAC'. Default: 'KMNC'.
eval_metrics (Union[list, tuple, str]): Evaluation metrics. If the
...
...
@@ -210,8 +211,18 @@ class Fuzzer:
# Check whether the mutate_config meet the specification.
mutate_config
=
check_param_type
(
'mutate_config'
,
mutate_config
,
list
)
for
method
in
mutate_config
:
check_param_type
(
"method['params']"
,
method
[
'params'
],
dict
)
for
config
in
mutate_config
:
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'
]:
msg
=
"coverage_metric must be in ['KMNC', 'NBC', 'SNAC'], but got {}."
\
.
format
(
coverage_metric
)
...
...
@@ -225,10 +236,7 @@ class Fuzzer:
check_param_type
(
'seed'
,
seed
,
list
)
check_numpy_param
(
'seed[0]'
,
seed
[
0
])
check_numpy_param
(
'seed[1]'
,
seed
[
1
])
if
seed
[
2
]
!=
0
:
msg
=
"initial seed[2] must be 0, but got {}."
.
format
(
seed
[
2
])
LOGGER
.
error
(
TAG
,
msg
)
raise
ValueError
(
msg
)
seed
.
append
(
0
)
seed
,
initial_seeds
=
_select_next
(
initial_seeds
)
fuzz_samples
=
[]
gt_labels
=
[]
...
...
mindarmour/fuzzing/model_coverage_metrics.py
浏览文件 @
c4dd9543
...
...
@@ -140,8 +140,8 @@ class ModelCoverageMetrics:
Args:
dataset (numpy.ndarray): Data for fuzz test.
bias_coefficient (
float): The coefficient used for changing the
neurons' output boundaries. Default: 0.
bias_coefficient (
Union[int, float]): The coefficient used
for changing the
neurons' output boundaries. Default: 0.
batch_size (int): The number of samples in a predict batch.
Default: 32.
...
...
tests/ut/python/fuzzing/test_fuzzer.py
浏览文件 @
c4dd9543
...
...
@@ -113,7 +113,7 @@ def test_fuzzing_ascend():
initial_seeds
=
[]
# make initial seeds
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
]
model_coverage_test
.
calculate_coverage
(
...
...
@@ -159,7 +159,7 @@ def test_fuzzing_cpu():
initial_seeds
=
[]
# make initial seeds
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
]
model_coverage_test
.
calculate_coverage
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录