Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindarmour
提交
2ffdf100
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看板
提交
2ffdf100
编写于
9月 09, 2020
作者:
L
liuluobin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adjust config check. Modify the exception type to TypeError in function check_model.
上级
2ded64d6
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
41 addition
and
39 deletion
+41
-39
mindarmour/privacy/evaluation/_check_config.py
mindarmour/privacy/evaluation/_check_config.py
+39
-37
mindarmour/utils/_check_param.py
mindarmour/utils/_check_param.py
+1
-1
tests/ut/python/detectors/test_region_based_detector.py
tests/ut/python/detectors/test_region_based_detector.py
+1
-1
未找到文件。
mindarmour/privacy/evaluation/_check_config.py
浏览文件 @
2ffdf100
...
@@ -24,45 +24,39 @@ TAG = "check_config"
...
@@ -24,45 +24,39 @@ TAG = "check_config"
def
_is_positive_int
(
item
):
def
_is_positive_int
(
item
):
"""
"""Verify that the value is a positive integer."""
Verify that the value is a positive integer.
if
not
isinstance
(
item
,
int
):
"""
if
not
isinstance
(
item
,
int
)
or
item
<=
0
:
return
False
return
False
return
True
return
item
>
0
def
_is_non_negative_int
(
item
):
def
_is_non_negative_int
(
item
):
"""
"""Verify that the value is a non-negative integer."""
Verify that the value is a non-negative integer.
if
not
isinstance
(
item
,
int
):
"""
if
not
isinstance
(
item
,
int
)
or
item
<
0
:
return
False
return
False
return
True
return
item
>=
0
def
_is_positive_float
(
item
):
def
_is_positive_float
(
item
):
"""
"""Verify that value is a positive number."""
Verify that value is a positive number.
if
not
isinstance
(
item
,
(
int
,
float
)):
"""
if
not
isinstance
(
item
,
(
int
,
float
))
or
item
<=
0
:
return
False
return
False
return
True
return
item
>
0
def
_is_non_negative_float
(
item
):
def
_is_non_negative_float
(
item
):
"""
"""Verify that value is a non-negative number."""
Verify that value is a non-negative number.
if
not
isinstance
(
item
,
(
int
,
float
)):
"""
if
not
isinstance
(
item
,
(
int
,
float
))
or
item
<
0
:
return
False
return
False
return
True
return
item
>=
0
def
_is_range_0_1_float
(
item
):
if
not
isinstance
(
item
,
(
int
,
float
)):
return
False
return
0
<=
item
<
1
def
_is_positive_int_tuple
(
item
):
def
_is_positive_int_tuple
(
item
):
"""
"""Verify that the input parameter is a positive integer tuple."""
Verify that the input parameter is a positive integer tuple.
"""
if
not
isinstance
(
item
,
tuple
):
if
not
isinstance
(
item
,
tuple
):
return
False
return
False
for
i
in
item
:
for
i
in
item
:
...
@@ -72,21 +66,29 @@ def _is_positive_int_tuple(item):
...
@@ -72,21 +66,29 @@ def _is_positive_int_tuple(item):
def
_is_dict
(
item
):
def
_is_dict
(
item
):
"""
"""Check whether the type is dict."""
Check whether the type is dict.
"""
return
isinstance
(
item
,
dict
)
return
isinstance
(
item
,
dict
)
def
_is_list
(
item
):
"""Check whether the type is list"""
return
isinstance
(
item
,
list
)
def
_is_str
(
item
):
"""Check whether the type is str."""
return
isinstance
(
item
,
str
)
_VALID_CONFIG_CHECKLIST
=
{
_VALID_CONFIG_CHECKLIST
=
{
"knn"
:
{
"knn"
:
{
"n_neighbors"
:
[
_is_positive_int
],
"n_neighbors"
:
[
_is_positive_int
],
"weights"
:
[{
"uniform"
,
"distance"
}],
"weights"
:
[{
"uniform"
,
"distance"
}
,
callable
],
"algorithm"
:
[{
"auto"
,
"ball_tree"
,
"kd_tree"
,
"brute"
}],
"algorithm"
:
[{
"auto"
,
"ball_tree"
,
"kd_tree"
,
"brute"
}],
"leaf_size"
:
[
_is_positive_int
],
"leaf_size"
:
[
_is_positive_int
],
"p"
:
[
_is_positive_int
],
"p"
:
[
_is_positive_int
],
"metric"
:
None
,
"metric"
:
[
_is_str
,
callable
]
,
"metric_params"
:
None
,
"metric_params"
:
[
_is_dict
,
{
None
}]
},
},
"lr"
:
{
"lr"
:
{
"penalty"
:
[{
"l1"
,
"l2"
,
"elasticnet"
,
"none"
}],
"penalty"
:
[{
"l1"
,
"l2"
,
"elasticnet"
,
"none"
}],
...
@@ -102,7 +104,7 @@ _VALID_CONFIG_CHECKLIST = {
...
@@ -102,7 +104,7 @@ _VALID_CONFIG_CHECKLIST = {
"mlp"
:
{
"mlp"
:
{
"hidden_layer_sizes"
:
[
_is_positive_int_tuple
],
"hidden_layer_sizes"
:
[
_is_positive_int_tuple
],
"activation"
:
[{
"identity"
,
"logistic"
,
"tanh"
,
"relu"
}],
"activation"
:
[{
"identity"
,
"logistic"
,
"tanh"
,
"relu"
}],
"solver"
:
{
"lbfgs"
,
"sgd"
,
"adam"
}
,
"solver"
:
[{
"lbfgs"
,
"sgd"
,
"adam"
}]
,
"alpha"
:
[
_is_positive_float
],
"alpha"
:
[
_is_positive_float
],
"batch_size"
:
[{
"auto"
},
_is_positive_int
],
"batch_size"
:
[{
"auto"
},
_is_positive_int
],
"learning_rate"
:
[{
"constant"
,
"invscaling"
,
"adaptive"
}],
"learning_rate"
:
[{
"constant"
,
"invscaling"
,
"adaptive"
}],
...
@@ -117,9 +119,9 @@ _VALID_CONFIG_CHECKLIST = {
...
@@ -117,9 +119,9 @@ _VALID_CONFIG_CHECKLIST = {
"momentum"
:
[
_is_positive_float
],
"momentum"
:
[
_is_positive_float
],
"nesterovs_momentum"
:
[{
True
,
False
}],
"nesterovs_momentum"
:
[{
True
,
False
}],
"early_stopping"
:
[{
True
,
False
}],
"early_stopping"
:
[{
True
,
False
}],
"validation_fraction"
:
[
_is_
positive
_float
],
"validation_fraction"
:
[
_is_
range_0_1
_float
],
"beta_1"
:
[
_is_
positive
_float
],
"beta_1"
:
[
_is_
range_0_1
_float
],
"beta_2"
:
[
_is_
positive
_float
],
"beta_2"
:
[
_is_
range_0_1
_float
],
"epsilon"
:
[
_is_positive_float
],
"epsilon"
:
[
_is_positive_float
],
"n_iter_no_change"
:
[
_is_positive_int
],
"n_iter_no_change"
:
[
_is_positive_int
],
"max_fun"
:
[
_is_positive_int
]
"max_fun"
:
[
_is_positive_int
]
...
@@ -133,7 +135,7 @@ _VALID_CONFIG_CHECKLIST = {
...
@@ -133,7 +135,7 @@ _VALID_CONFIG_CHECKLIST = {
"min_weight_fraction_leaf"
:
[
_is_non_negative_float
],
"min_weight_fraction_leaf"
:
[
_is_non_negative_float
],
"max_features"
:
[{
"auto"
,
"sqrt"
,
"log2"
,
None
},
_is_positive_float
],
"max_features"
:
[{
"auto"
,
"sqrt"
,
"log2"
,
None
},
_is_positive_float
],
"max_leaf_nodes"
:
[
_is_positive_int
,
{
None
}],
"max_leaf_nodes"
:
[
_is_positive_int
,
{
None
}],
"min_impurity_decrease"
:
{
_is_non_negative_float
}
,
"min_impurity_decrease"
:
[
_is_non_negative_float
]
,
"min_impurity_split"
:
[{
None
},
_is_positive_float
],
"min_impurity_split"
:
[{
None
},
_is_positive_float
],
"bootstrap"
:
[{
True
,
False
}],
"bootstrap"
:
[{
True
,
False
}],
"oob_scroe"
:
[{
True
,
False
}],
"oob_scroe"
:
[{
True
,
False
}],
...
@@ -141,9 +143,9 @@ _VALID_CONFIG_CHECKLIST = {
...
@@ -141,9 +143,9 @@ _VALID_CONFIG_CHECKLIST = {
"random_state"
:
None
,
"random_state"
:
None
,
"verbose"
:
[
_is_non_negative_int
],
"verbose"
:
[
_is_non_negative_int
],
"warm_start"
:
[{
True
,
False
}],
"warm_start"
:
[{
True
,
False
}],
"class_weight"
:
None
,
"class_weight"
:
[{
"balanced"
,
"balanced_subsample"
},
_is_dict
,
_is_list
]
,
"ccp_alpha"
:
[
_is_non_negative_float
],
"ccp_alpha"
:
[
_is_non_negative_float
],
"max_samples"
:
[
_is_positive
_float
]
"max_samples"
:
[
{
None
},
_is_positive_int
,
_is_range_0_1
_float
]
}
}
}
}
...
...
mindarmour/utils/_check_param.py
浏览文件 @
2ffdf100
...
@@ -129,7 +129,7 @@ def check_model(model_name, model, model_type):
...
@@ -129,7 +129,7 @@ def check_model(model_name, model, model_type):
model_type
,
model_type
,
type
(
model
).
__name__
)
type
(
model
).
__name__
)
LOGGER
.
error
(
TAG
,
msg
)
LOGGER
.
error
(
TAG
,
msg
)
raise
Valu
eError
(
msg
)
raise
Typ
eError
(
msg
)
def
check_numpy_param
(
arg_name
,
arg_value
):
def
check_numpy_param
(
arg_name
,
arg_value
):
...
...
tests/ut/python/detectors/test_region_based_detector.py
浏览文件 @
2ffdf100
...
@@ -84,7 +84,7 @@ def test_value_error():
...
@@ -84,7 +84,7 @@ def test_value_error():
adv
=
np
.
random
.
rand
(
4
,
4
).
astype
(
np
.
float32
)
adv
=
np
.
random
.
rand
(
4
,
4
).
astype
(
np
.
float32
)
model
=
Model
(
Net
())
model
=
Model
(
Net
())
# model should be mindspore model
# model should be mindspore model
with
pytest
.
raises
(
Valu
eError
):
with
pytest
.
raises
(
Typ
eError
):
assert
RegionBasedDetector
(
Net
())
assert
RegionBasedDetector
(
Net
())
with
pytest
.
raises
(
ValueError
):
with
pytest
.
raises
(
ValueError
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录