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