Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
acf46baf
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
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看板
提交
acf46baf
编写于
6月 17, 2020
作者:
P
pkuliuliu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add Normal op
上级
e9670f3c
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
140 addition
and
1 deletion
+140
-1
mindspore/ops/_op_impl/aicpu/__init__.py
mindspore/ops/_op_impl/aicpu/__init__.py
+1
-0
mindspore/ops/_op_impl/aicpu/normal.py
mindspore/ops/_op_impl/aicpu/normal.py
+33
-0
mindspore/ops/operations/__init__.py
mindspore/ops/operations/__init__.py
+2
-1
mindspore/ops/operations/random_ops.py
mindspore/ops/operations/random_ops.py
+44
-0
tests/st/ops/ascend/test_aicpu_ops/test_normal.py
tests/st/ops/ascend/test_aicpu_ops/test_normal.py
+43
-0
tests/ut/python/ops/test_ops.py
tests/ut/python/ops/test_ops.py
+17
-0
未找到文件。
mindspore/ops/_op_impl/aicpu/__init__.py
浏览文件 @
acf46baf
...
@@ -25,3 +25,4 @@ from .squeeze import _squeeze_aicpu
...
@@ -25,3 +25,4 @@ from .squeeze import _squeeze_aicpu
from
.expand_dims
import
_expand_dims_aicpu
from
.expand_dims
import
_expand_dims_aicpu
from
.random_choice_with_mask
import
_random_choice_with_mask_aicpu
from
.random_choice_with_mask
import
_random_choice_with_mask_aicpu
from
.pack
import
_pack_aicpu
from
.pack
import
_pack_aicpu
from
.normal
import
_normal_aicpu
mindspore/ops/_op_impl/aicpu/normal.py
0 → 100644
浏览文件 @
acf46baf
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""Normal op"""
from
mindspore.ops.op_info_register
import
op_info_register
,
AiCPURegOp
,
DataType
normal_op_info
=
AiCPURegOp
(
"Normal"
)
\
.
fusion_type
(
"OPAQUE"
)
\
.
input
(
0
,
"shape"
,
"required"
)
\
.
input
(
1
,
"mean"
,
"required"
)
\
.
input
(
2
,
"stddev"
,
"required"
)
\
.
output
(
0
,
"y"
,
"required"
)
\
.
attr
(
"seed"
,
"int"
)
\
.
dtype_format
(
DataType
.
I32_Default
,
DataType
.
F32_Default
,
DataType
.
F32_Default
,
DataType
.
F32_Default
)
\
.
dtype_format
(
DataType
.
I32_NCHW
,
DataType
.
F32_NCHW
,
DataType
.
F32_NCHW
,
DataType
.
F32_NCHW
)
\
.
get_op_info
()
@
op_info_register
(
normal_op_info
)
def
_normal_aicpu
():
"""Normal AiCPU register"""
return
mindspore/ops/operations/__init__.py
浏览文件 @
acf46baf
...
@@ -53,7 +53,7 @@ from .math_ops import (Abs, ACos, Asin, Asinh, AddN, AssignAdd, AssignSub, Atan2
...
@@ -53,7 +53,7 @@ from .math_ops import (Abs, ACos, Asin, Asinh, AddN, AssignAdd, AssignSub, Atan2
Sin
,
Sqrt
,
Rsqrt
,
BesselI0e
,
BesselI1e
,
Sin
,
Sqrt
,
Rsqrt
,
BesselI0e
,
BesselI1e
,
Square
,
Sub
,
TensorAdd
,
Sign
,
Round
,
SquareSumAll
,
Atan
,
Atanh
,
Cosh
,
Sinh
)
Square
,
Sub
,
TensorAdd
,
Sign
,
Round
,
SquareSumAll
,
Atan
,
Atanh
,
Cosh
,
Sinh
)
from
.random_ops
import
(
RandomChoiceWithMask
)
from
.random_ops
import
(
RandomChoiceWithMask
,
Normal
)
from
.nn_ops
import
(
LSTM
,
SGD
,
Adam
,
SparseApplyAdam
,
SparseApplyLazyAdam
,
ApplyMomentum
,
BatchNorm
,
from
.nn_ops
import
(
LSTM
,
SGD
,
Adam
,
SparseApplyAdam
,
SparseApplyLazyAdam
,
ApplyMomentum
,
BatchNorm
,
BiasAdd
,
Conv2D
,
BiasAdd
,
Conv2D
,
DepthwiseConv2dNative
,
DepthwiseConv2dNative
,
...
@@ -163,6 +163,7 @@ __all__ = [
...
@@ -163,6 +163,7 @@ __all__ = [
'HSigmoid'
,
'HSigmoid'
,
'Tanh'
,
'Tanh'
,
'RandomChoiceWithMask'
,
'RandomChoiceWithMask'
,
'Normal'
,
'ResizeBilinear'
,
'ResizeBilinear'
,
'ScalarSummary'
,
'ScalarSummary'
,
'ImageSummary'
,
'ImageSummary'
,
...
...
mindspore/ops/operations/random_ops.py
浏览文件 @
acf46baf
...
@@ -64,3 +64,47 @@ class RandomChoiceWithMask(PrimitiveWithInfer):
...
@@ -64,3 +64,47 @@ class RandomChoiceWithMask(PrimitiveWithInfer):
def
infer_dtype
(
self
,
x_dtype
):
def
infer_dtype
(
self
,
x_dtype
):
validator
.
check_tensor_type_same
({
'x'
:
x_dtype
},
[
mstype
.
bool_
],
self
.
name
)
validator
.
check_tensor_type_same
({
'x'
:
x_dtype
},
[
mstype
.
bool_
],
self
.
name
)
return
(
mstype
.
int32
,
mstype
.
bool_
)
return
(
mstype
.
int32
,
mstype
.
bool_
)
class
Normal
(
PrimitiveWithInfer
):
"""
Generates random samples from a normal(Gaussian) distribution.
Args:
seed (int): Random seed. Default: 0.
Inputs:
- **shape** (tuple[int]) - The shape of output tensor. Only constant value is allowed.
- **mean** (Tensor) - The mean of the distribution, with float32 data type.
- **stddev** (Tensor) - The standard deviation of the distribution, with float32 data type.
Outputs:
Tensor, with the given shape from the specific distribution and float32 data type.
Examples:
>>> normal = P.Normal()
>>> mean = Tensor(0., mstype.float32)
>>> stddev = Tensor(1., mstype.float32)
>>> out = normal((32, 3, 3), mean, stddev)
"""
@
prim_attr_register
def
__init__
(
self
,
seed
=
0
):
"""Init Normal"""
validator
.
check_value_type
(
"seed"
,
seed
,
[
int
],
self
.
name
)
def
__infer__
(
self
,
shape
,
mean
,
stddev
):
shape_value
=
shape
[
"value"
]
if
shape_value
is
None
:
raise
ValueError
(
f
"For
{
self
.
name
}
, shape must be const."
)
validator
.
check_value_type
(
"shape"
,
shape_value
,
[
tuple
],
self
.
name
)
for
i
,
shape_i
in
enumerate
(
shape_value
):
validator
.
check_integer
(
"shape[%d]"
%
i
,
shape_i
,
0
,
Rel
.
GE
,
self
.
name
)
validator
.
check_tensor_type_same
({
"mean"
:
mean
[
"dtype"
]},
[
mstype
.
float32
],
self
.
name
)
validator
.
check_tensor_type_same
({
"stddev"
:
stddev
[
"dtype"
]},
[
mstype
.
float32
],
self
.
name
)
out
=
{
"shape"
:
shape_value
,
"dtype"
:
mstype
.
float32
,
"value"
:
None
}
return
out
tests/st/ops/ascend/test_aicpu_ops/test_normal.py
0 → 100644
浏览文件 @
acf46baf
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
import
mindspore.context
as
context
import
mindspore.nn
as
nn
from
mindspore.ops
import
operations
as
P
from
mindspore.common
import
Tensor
from
mindspore.common
import
dtype
as
mstype
context
.
set_context
(
mode
=
context
.
PYNATIVE_MODE
,
device_target
=
"Ascend"
)
class
Net
(
nn
.
Cell
):
def
__init__
(
self
,
shape
=
None
,
mean
=
0.0
,
stddev
=
1.0
,
seed
=
0
):
super
(
Net
,
self
).
__init__
()
self
.
_mean
=
Tensor
(
mean
,
mstype
.
float32
)
self
.
_stddev
=
Tensor
(
stddev
,
mstype
.
float32
)
self
.
_normal
=
P
.
Normal
(
seed
=
seed
)
self
.
_shape
=
shape
def
construct
(
self
):
return
self
.
_normal
(
self
.
_shape
,
self
.
_mean
,
self
.
_stddev
)
def
test_net_3x2x4
():
mean
=
0.0
stddev
=
1.0
seed
=
0
net
=
Net
((
3
,
2
,
4
),
mean
,
stddev
,
seed
)
out
=
net
()
assert
out
.
shape
==
(
3
,
2
,
4
)
tests/ut/python/ops/test_ops.py
浏览文件 @
acf46baf
...
@@ -399,6 +399,19 @@ class InplaceSubNet(nn.Cell):
...
@@ -399,6 +399,19 @@ class InplaceSubNet(nn.Cell):
return
out
return
out
class
NormalNet
(
nn
.
Cell
):
def
__init__
(
self
,
shape
=
None
,
mean
=
0.0
,
stddev
=
1.0
,
seed
=
0
):
super
(
NormalNet
,
self
).
__init__
()
self
.
normal
=
P
.
Normal
(
seed
=
seed
)
self
.
shape
=
shape
self
.
mean
=
Tensor
(
mean
,
mstype
.
float32
)
self
.
stddev
=
Tensor
(
stddev
,
mstype
.
float32
)
def
construct
(
self
):
out
=
self
.
normal
(
self
.
shape
,
self
.
mean
,
self
.
stddev
)
return
out
test_case_math_ops
=
[
test_case_math_ops
=
[
(
'BitwiseAnd'
,
{
(
'BitwiseAnd'
,
{
'block'
:
P
.
BitwiseAnd
(),
'block'
:
P
.
BitwiseAnd
(),
...
@@ -895,6 +908,10 @@ test_case_math_ops = [
...
@@ -895,6 +908,10 @@ test_case_math_ops = [
'desc_inputs'
:
[
Tensor
([
-
1.0
,
0.0
,
1.5
,
2.0
,
5.0
,
15
],
mstype
.
float16
),
Tensor
([
0.0
,
5.0
],
mstype
.
float16
)],
'desc_inputs'
:
[
Tensor
([
-
1.0
,
0.0
,
1.5
,
2.0
,
5.0
,
15
],
mstype
.
float16
),
Tensor
([
0.0
,
5.0
],
mstype
.
float16
)],
'desc_bprop'
:
[],
'desc_bprop'
:
[],
'skip'
:
[
'backward'
]}),
'skip'
:
[
'backward'
]}),
(
'Normal'
,
{
'block'
:
NormalNet
((
3
,
2
,
4
),
0.0
,
1.0
,
0
),
'desc_inputs'
:
[],
'skip'
:
[
'backward'
]}),
]
]
test_case_nn_ops
=
[
test_case_nn_ops
=
[
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录