Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
正统之独孤求败
mindspore
提交
bb5320be
M
mindspore
项目概览
正统之独孤求败
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bb5320be
编写于
3月 31, 2020
作者:
G
guohongzilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
iterfaces change: _Constant to Constant
上级
04eab166
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
8 deletion
+22
-8
mindspore/common/initializer.py
mindspore/common/initializer.py
+15
-6
tests/ut/python/utils/test_initializer.py
tests/ut/python/utils/test_initializer.py
+7
-2
未找到文件。
mindspore/common/initializer.py
浏览文件 @
bb5320be
...
...
@@ -180,18 +180,18 @@ class HeUniform(Initializer):
_assignment
(
arr
,
data
)
class
_
Constant
(
Initializer
):
class
Constant
(
Initializer
):
"""
Initialize a constant.
Args:
value (
int or numpy.ndarray
): The value to initialize.
value (
Union[int, numpy.ndarray]
): The value to initialize.
Returns:
Array, initialize array.
"""
def
__init__
(
self
,
value
):
super
(
_
Constant
,
self
).
__init__
(
value
=
value
)
super
(
Constant
,
self
).
__init__
(
value
=
value
)
self
.
value
=
value
def
_initialize
(
self
,
arr
):
...
...
@@ -266,8 +266,16 @@ def initializer(init, shape=None, dtype=mstype.float32):
Args:
init (Union[Tensor, str, Initializer, numbers.Number]): Initialize value.
- `str`: The `init` should be the alias of the class inheriting from `Initializer` and the corresponding
class will be called.
- `Initializer`: The `init` should be the class inheriting from `Initializer` to initialize tensor.
- `numbers.Number`: The `Constant` will be called to initialize tensor.
shape (Union[tuple, list, int]): A list of integers, a tuple of integers or an integer as the shape of
output. Default: None.
output. Default: None.
dtype (:class:`mindspore.dtype`): The type of data in initialized tensor. Default: mstype.float32.
Returns:
...
...
@@ -295,7 +303,7 @@ def initializer(init, shape=None, dtype=mstype.float32):
raise
ValueError
(
msg
)
if
isinstance
(
init
,
numbers
.
Number
):
init_obj
=
_
Constant
(
init
)
init_obj
=
Constant
(
init
)
elif
isinstance
(
init
,
str
):
init_obj
=
_INITIALIZER_ALIAS
[
init
.
lower
()]()
else
:
...
...
@@ -314,4 +322,5 @@ __all__ = [
'HeUniform'
,
'XavierUniform'
,
'One'
,
'Zero'
]
'Zero'
,
'Constant'
]
tests/ut/python/utils/test_initializer.py
浏览文件 @
bb5320be
...
...
@@ -37,8 +37,8 @@ def _check_value(tensor, value_min, value_max):
for
ele
in
nd
.
flatten
():
if
value_min
<=
ele
<=
value_max
:
continue
raise
Typ
eError
(
'value_min = %d, ele = %d, value_max = %d'
%
(
value_min
,
ele
,
value_max
))
raise
Valu
eError
(
'value_min = %d, ele = %d, value_max = %d'
%
(
value_min
,
ele
,
value_max
))
def
_check_uniform
(
tensor
,
boundary_a
,
boundary_b
):
...
...
@@ -92,6 +92,11 @@ def test_init_one_alias():
_check_value
(
tensor
,
1
,
1
)
def
test_init_constant
():
tensor
=
init
.
initializer
(
init
.
Constant
(
1
),
[
2
,
2
],
ms
.
float32
)
_check_value
(
tensor
,
1
,
1
)
def
test_init_uniform
():
scale
=
10
tensor
=
init
.
initializer
(
init
.
Uniform
(
scale
=
scale
),
[
5
,
4
],
ms
.
float32
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录