Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
63d9e472
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看板
提交
63d9e472
编写于
6月 02, 2020
作者:
S
sunsuodong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix cpu StridedSliceGrad
上级
4e32dad7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
7 deletion
+34
-7
mindspore/ccsrc/kernel/cpu/slice_grad_cpu_kernel.cc
mindspore/ccsrc/kernel/cpu/slice_grad_cpu_kernel.cc
+5
-5
tests/st/ops/cpu/test_stridedslice_grad_op.py
tests/st/ops/cpu/test_stridedslice_grad_op.py
+28
-1
tests/st/ops/cpu/test_stridedslice_op.py
tests/st/ops/cpu/test_stridedslice_op.py
+1
-1
未找到文件。
mindspore/ccsrc/kernel/cpu/slice_grad_cpu_kernel.cc
浏览文件 @
63d9e472
...
...
@@ -61,11 +61,11 @@ void SliceGradCPUKernel::InitKernel(const CNodePtr &kernel_node) {
end_
.
emplace_back
(
begin_
[
i
]
+
sizes
[
i
]);
}
}
CPUKernelUtils
::
ExpandDimsTo4
(
&
output_dx_shape_
);
auto
input_len
=
input_dy
_shape_
.
size
();
if
(
in
put_len
<
4
)
{
for
(
size_t
i
=
0
;
i
<
4
-
in
put_len
;
++
i
)
{
input_dy_shape_
.
insert
(
input_dy
_shape_
.
begin
(),
1
);
auto
output_len
=
output_dx
_shape_
.
size
();
if
(
out
put_len
<
4
)
{
for
(
size_t
i
=
0
;
i
<
4
-
out
put_len
;
++
i
)
{
output_dx_shape_
.
insert
(
output_dx
_shape_
.
begin
(),
1
);
begin_
.
insert
(
begin_
.
begin
(),
0
);
strides_
.
insert
(
strides_
.
begin
(),
1
);
end_
.
insert
(
end_
.
begin
(),
1
);
...
...
tests/st/ops/cpu/test_stridedslice_grad_op.py
浏览文件 @
63d9e472
...
...
@@ -19,6 +19,7 @@ import pytest
import
mindspore.context
as
context
import
mindspore.nn
as
nn
from
mindspore
import
Tensor
from
mindspore.common
import
dtype
as
mstype
from
mindspore.common.api
import
ms_function
from
mindspore.ops
import
operations
as
P
from
mindspore.ops.operations
import
_grad_ops
as
G
...
...
@@ -38,7 +39,7 @@ class StridedSliceGrad(nn.Cell):
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_cpu
_training
@
pytest
.
mark
.
platform_x86_cpu
@
pytest
.
mark
.
env_onecard
def
test_slice
():
x
=
Tensor
(
np
.
array
([[[
1.
,
1.
,
1.
],
[
2
,
2
,
2
]],
[[
3
,
3
,
3
],
[
4
,
4
,
4
]],
[[
5
,
5
,
5
],
[
6
,
7
,
8
]]]).
astype
(
np
.
float32
))
...
...
@@ -47,3 +48,29 @@ def test_slice():
output
=
ssg
(
dy
,
x
)
expect
=
[[[
0
,
0
,
0
],
[
0
,
0
,
0
]],
[[
0
,
0
,
0
],
[
0
,
0
,
0
]],
[[
5
,
1
,
5
],
[
6
,
1
,
8
]]]
assert
(
output
.
asnumpy
()
==
expect
).
all
()
class
StridedSliceGrad2
(
nn
.
Cell
):
def
__init__
(
self
):
super
(
StridedSliceGrad2
,
self
).
__init__
()
self
.
ssg
=
G
.
StridedSliceGrad
()
self
.
shape
=
P
.
Shape
()
@
ms_function
def
construct
(
self
,
dy
,
x
):
return
self
.
ssg
(
dy
,
self
.
shape
(
x
),
(
0
,
0
,
0
),
(
1
,
4
,
2
),
(
1
,
1
,
1
))
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_cpu
@
pytest
.
mark
.
env_onecard
def
test_slice2
():
x
=
Tensor
(
np
.
arange
(
2
*
4
*
2
).
reshape
(
2
,
4
,
2
),
mstype
.
float32
)
dy
=
Tensor
(
np
.
arange
(
4
*
2
).
reshape
(
4
,
2
),
mstype
.
float32
)
ssg
=
StridedSliceGrad2
()
output
=
ssg
(
dy
,
x
)
expect
=
[[[
0.
,
1.
],
[
2.
,
3.
],
[
4.
,
5.
],
[
6.
,
7.
]],
[[
0.
,
0.
],
[
0.
,
0.
],
[
0.
,
0.
],
[
0.
,
0.
]]]
assert
(
output
.
asnumpy
()
==
expect
).
all
()
if
__name__
==
'__main__'
:
test_slice
()
test_slice2
()
tests/st/ops/cpu/test_stridedslice_op.py
浏览文件 @
63d9e472
...
...
@@ -34,7 +34,7 @@ class StridedSlice(nn.Cell):
@
pytest
.
mark
.
level0
@
pytest
.
mark
.
platform_x86_cpu
_training
@
pytest
.
mark
.
platform_x86_cpu
@
pytest
.
mark
.
env_onecard
def
test_slice
():
x
=
Tensor
(
np
.
array
([[[
1.
,
1.
,
1.
],
[
2
,
2
,
2
]],
[[
3
,
3
,
3
],
[
4
,
4
,
4
]],
[[
5
,
5
,
5
],
[
6
,
7
,
8
]]]).
astype
(
np
.
float32
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录