Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindarmour
提交
9d4e3959
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看板
提交
9d4e3959
编写于
8月 25, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 25, 2020
浏览文件
操作
浏览文件
下载
差异文件
!91 fix issues
Merge pull request !91 from ZhidanLiu/master
上级
3d887767
afa3f75f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
27 addition
and
23 deletion
+27
-23
example/mnist_demo/lenet5_mnist_coverage.py
example/mnist_demo/lenet5_mnist_coverage.py
+1
-1
example/mnist_demo/lenet5_mnist_fuzzing.py
example/mnist_demo/lenet5_mnist_fuzzing.py
+17
-9
mindarmour/fuzzing/fuzzing.py
mindarmour/fuzzing/fuzzing.py
+2
-6
mindarmour/fuzzing/model_coverage_metrics.py
mindarmour/fuzzing/model_coverage_metrics.py
+3
-3
tests/ut/python/fuzzing/test_coverage_metrics.py
tests/ut/python/fuzzing/test_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_coverage.py
浏览文件 @
9d4e3959
...
...
@@ -51,7 +51,7 @@ def test_lenet_mnist_coverage():
train_images
=
np
.
concatenate
(
train_images
,
axis
=
0
)
# initialize fuzz test with training dataset
model_fuzz_test
=
ModelCoverageMetrics
(
model
,
10
000
,
1
0
,
train_images
)
model_fuzz_test
=
ModelCoverageMetrics
(
model
,
10
,
100
0
,
train_images
)
# fuzz test with original test data
# get test data
...
...
example/mnist_demo/lenet5_mnist_fuzzing.py
浏览文件 @
9d4e3959
...
...
@@ -39,14 +39,22 @@ def test_lenet_mnist_fuzzing():
load_param_into_net
(
net
,
load_dict
)
model
=
Model
(
net
)
mutate_config
=
[{
'method'
:
'Blur'
,
'params'
:
{
'auto_param'
:
True
}},
{
'method'
:
'Contrast'
,
'params'
:
{
'factor'
:
2
}},
{
'method'
:
'Translate'
,
'params'
:
{
'x_bias'
:
0.1
,
'y_bias'
:
0.2
}},
{
'method'
:
'FGSM'
,
'params'
:
{
'eps'
:
0.1
,
'alpha'
:
0.1
}}
]
'params'
:
{
'auto_param'
:
True
}},
{
'method'
:
'Contrast'
,
'params'
:
{
'auto_param'
:
True
}},
{
'method'
:
'Translate'
,
'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'
,
'params'
:
{
'eps'
:
0.3
,
'alpha'
:
0.1
}}
]
# get training data
data_list
=
"./MNIST_unzip/train"
...
...
@@ -59,7 +67,7 @@ def test_lenet_mnist_fuzzing():
train_images
=
np
.
concatenate
(
train_images
,
axis
=
0
)
# initialize fuzz test with training dataset
model_coverage_test
=
ModelCoverageMetrics
(
model
,
10
00
,
1
0
,
train_images
)
model_coverage_test
=
ModelCoverageMetrics
(
model
,
10
,
100
0
,
train_images
)
# fuzz test with original test data
# get test data
...
...
mindarmour/fuzzing/fuzzing.py
浏览文件 @
9d4e3959
...
...
@@ -102,8 +102,9 @@ class Fuzzer:
self
.
_target_model
=
check_model
(
'model'
,
target_model
,
Model
)
train_dataset
=
check_numpy_param
(
'train_dataset'
,
train_dataset
)
self
.
_coverage_metrics
=
ModelCoverageMetrics
(
target_model
,
neuron_num
,
segmented_num
,
neuron_num
,
train_dataset
)
train_dataset
)
# Allowed mutate strategies so far.
self
.
_strategies
=
{
'Contrast'
:
Contrast
,
'Brightness'
:
Brightness
,
'Blur'
:
Blur
,
'Noise'
:
Noise
,
'Translate'
:
Translate
,
...
...
@@ -190,11 +191,6 @@ class Fuzzer:
eval_metrics_
=
[]
avaliable_metrics
=
[
'accuracy'
,
'attack_success_rate'
,
'kmnc'
,
'nbc'
,
'snac'
]
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
:
msg
=
'metric in list `eval_metrics` must be in {}, but got {}.'
\
.
format
(
avaliable_metrics
,
elem
)
...
...
mindarmour/fuzzing/model_coverage_metrics.py
浏览文件 @
9d4e3959
...
...
@@ -43,8 +43,8 @@ class ModelCoverageMetrics:
Args:
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.
segmented_num (int): The number of segmented sections of neurons' output intervals.
train_dataset (numpy.ndarray): Training dataset used for determine
the neurons' output boundaries.
...
...
@@ -56,14 +56,14 @@ class ModelCoverageMetrics:
>>> train_images = np.random.random((10000, 1, 32, 32)).astype(np.float32)
>>> test_images = np.random.random((5000, 1, 32, 32)).astype(np.float32)
>>> model = Model(net)
>>> model_fuzz_test = ModelCoverageMetrics(model, 10
000, 1
0, train_images)
>>> model_fuzz_test = ModelCoverageMetrics(model, 10
, 100
0, train_images)
>>> model_fuzz_test.calculate_coverage(test_images)
>>> 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('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
.
_segmented_num
=
check_int_positive
(
'segmented_num'
,
segmented_num
)
self
.
_neuron_num
=
check_int_positive
(
'neuron_num'
,
neuron_num
)
...
...
tests/ut/python/fuzzing/test_coverage_metrics.py
浏览文件 @
9d4e3959
...
...
@@ -71,7 +71,7 @@ def test_lenet_mnist_coverage_cpu():
# initialize fuzz test with training dataset
training_data
=
(
np
.
random
.
random
((
10000
,
10
))
*
20
).
astype
(
np
.
float32
)
model_fuzz_test
=
ModelCoverageMetrics
(
model
,
10
000
,
1
0
,
training_data
)
model_fuzz_test
=
ModelCoverageMetrics
(
model
,
10
,
100
0
,
training_data
)
# fuzz test with original test data
# get test data
...
...
@@ -105,7 +105,7 @@ def test_lenet_mnist_coverage_ascend():
# initialize fuzz test with training dataset
training_data
=
(
np
.
random
.
random
((
10000
,
10
))
*
20
).
astype
(
np
.
float32
)
model_fuzz_test
=
ModelCoverageMetrics
(
model
,
10
000
,
1
0
,
training_data
)
model_fuzz_test
=
ModelCoverageMetrics
(
model
,
10
,
100
0
,
training_data
)
# fuzz test with original test data
# get test data
...
...
tests/ut/python/fuzzing/test_fuzzer.py
浏览文件 @
9d4e3959
...
...
@@ -102,7 +102,7 @@ def test_fuzzing_ascend():
]
# initialize fuzz test with training dataset
train_images
=
np
.
random
.
rand
(
32
,
1
,
32
,
32
).
astype
(
np
.
float32
)
model_coverage_test
=
ModelCoverageMetrics
(
model
,
10
00
,
1
0
,
train_images
)
model_coverage_test
=
ModelCoverageMetrics
(
model
,
10
,
100
0
,
train_images
)
# fuzz test with original test data
# get test data
...
...
@@ -148,7 +148,7 @@ def test_fuzzing_cpu():
]
# initialize fuzz test with training dataset
train_images
=
np
.
random
.
rand
(
32
,
1
,
32
,
32
).
astype
(
np
.
float32
)
model_coverage_test
=
ModelCoverageMetrics
(
model
,
10
00
,
1
0
,
train_images
)
model_coverage_test
=
ModelCoverageMetrics
(
model
,
10
,
100
0
,
train_images
)
# fuzz test with original test data
# get test data
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录