Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8b6fda6f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
接近 2 年 前同步成功
通知
2323
Star
20933
Fork
5424
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8b6fda6f
编写于
9月 21, 2017
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move stride function to ddim.h
上级
bc632df8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
20 addition
and
22 deletion
+20
-22
paddle/framework/ddim.cc
paddle/framework/ddim.cc
+8
-0
paddle/framework/ddim.h
paddle/framework/ddim.h
+1
-0
paddle/operators/crop_op.cc
paddle/operators/crop_op.cc
+6
-5
paddle/operators/crop_op.h
paddle/operators/crop_op.h
+5
-17
未找到文件。
paddle/framework/ddim.cc
浏览文件 @
8b6fda6f
...
...
@@ -292,5 +292,13 @@ DDim flatten_to_2d(const DDim& src, int num_col_dims) {
DDim
flatten_to_1d
(
const
DDim
&
src
)
{
return
make_ddim
({
product
(
src
)});
}
DDim
stride
(
const
DDim
&
ddim
)
{
std
::
vector
<
int64_t
>
strides
(
ddim
.
size
());
strides
[
ddim
.
size
()
-
1
]
=
1
;
for
(
int
i
=
ddim
.
size
()
-
2
;
i
>=
0
;
--
i
)
{
strides
[
i
]
=
strides
[
i
+
1
]
*
ddim
[
i
+
1
];
}
return
framework
::
make_ddim
(
strides
);
}
}
// namespace framework
}
// namespace paddle
paddle/framework/ddim.h
浏览文件 @
8b6fda6f
...
...
@@ -121,6 +121,7 @@ DDim flatten_to_2d(const DDim& src, int num_col_dims);
DDim
flatten_to_1d
(
const
DDim
&
src
);
DDim
stride
(
const
DDim
&
ddim
);
}
// namespace framework
}
// namespace paddle
...
...
paddle/operators/crop_op.cc
浏览文件 @
8b6fda6f
...
...
@@ -32,8 +32,9 @@ class CropOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
OutputVar
(
"Out"
),
"Output(Out) of CropOp should not be null."
);
auto
x_dim
=
ctx
.
Input
<
LoDTensor
>
(
"X"
)
->
dims
();
auto
Y
=
ctx
.
Input
<
LoDTensor
>
(
"Y"
);
if
(
Y
==
nullptr
)
{
auto
*
y
=
ctx
.
Input
<
LoDTensor
>
(
"Y"
);
auto
*
out
=
ctx
.
Output
<
LoDTensor
>
(
"Out"
);
if
(
y
==
nullptr
)
{
auto
shape
=
Attr
<
std
::
vector
<
int
>>
(
"shape"
);
PADDLE_ENFORCE_EQ
(
int64_t
(
shape
.
size
()),
x_dim
.
size
(),
...
...
@@ -42,12 +43,12 @@ class CropOp : public framework::OperatorWithKernel {
for
(
size_t
i
=
0
;
i
<
shape
.
size
();
++
i
)
{
tensor_shape
[
i
]
=
static_cast
<
int64_t
>
(
shape
[
i
]);
}
ctx
.
Output
<
LoDTensor
>
(
"Out"
)
->
Resize
(
framework
::
make_ddim
(
tensor_shape
));
out
->
Resize
(
framework
::
make_ddim
(
tensor_shape
));
}
else
{
PADDLE_ENFORCE_EQ
(
framework
::
arity
(
x_dim
),
framework
::
arity
(
Y
->
dims
()),
PADDLE_ENFORCE_EQ
(
framework
::
arity
(
x_dim
),
framework
::
arity
(
y
->
dims
()),
"Tensor rank of both CropOp's "
"inputs must be same."
);
ctx
.
Output
<
LoDTensor
>
(
"Out"
)
->
Resize
(
Y
->
dims
());
out
->
Resize
(
y
->
dims
());
}
}
};
...
...
paddle/operators/crop_op.h
浏览文件 @
8b6fda6f
...
...
@@ -24,19 +24,7 @@ namespace operators { // Internal
template
<
typename
T
,
size_t
D
,
int
MajorType
=
Eigen
::
RowMajor
,
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenTensor
=
framework
::
EigenTensor
<
T
,
D
,
MajorType
,
IndexType
>
;
using
framework
::
Tensor
;
using
framework
::
DDim
;
// TODO(wanghaoshuang): move this function to other place
DDim
stride
(
const
DDim
&
ddim
)
{
std
::
vector
<
int64_t
>
strides
(
ddim
.
size
());
strides
[
ddim
.
size
()
-
1
]
=
1
;
for
(
int
i
=
ddim
.
size
()
-
2
;
i
>=
0
;
--
i
)
{
strides
[
i
]
=
strides
[
i
+
1
]
*
ddim
[
i
+
1
];
}
return
make_ddim
(
strides
);
}
template
<
typename
T
>
class
CropKernel
:
public
framework
::
OpKernel
{
...
...
@@ -44,13 +32,13 @@ class CropKernel : public framework::OpKernel {
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
*
x
=
context
.
Input
<
Tensor
>
(
"X"
);
auto
*
out
=
context
.
Output
<
Tensor
>
(
"Out"
);
T
*
x_data
=
x
->
data
<
T
>
();
const
T
*
x_data
=
x
->
data
<
T
>
();
T
*
out_data
=
out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
x_stride
=
stride
(
x
->
dims
());
auto
out_stride
=
stride
(
out
->
dims
());
auto
x_stride
=
framework
::
stride
(
x
->
dims
());
auto
out_stride
=
framework
::
stride
(
out
->
dims
());
auto
offsets
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"offsets"
);
PADDLE_ENFORCE_EQ
(
x
_dims
.
size
(),
offsets
.
size
(),
x
->
dims
()
.
size
(),
offsets
.
size
(),
"Offsets size should be equal to dimension size of input tensor."
);
int64_t
offset
=
0
;
for
(
int
i
=
0
;
i
<
offsets
.
size
();
++
i
)
{
...
...
@@ -71,7 +59,7 @@ void CropGradFunction(const framework::ExecutionContext& context) {
Eigen
::
array
<
std
::
pair
<
int
,
int
>
,
D
>
paddings
;
for
(
int
i
=
0
;
i
<
D
;
++
i
)
{
paddings
[
i
].
first
=
offsets
[
i
];
paddings
[
i
].
second
=
d_x
_dims
[
i
]
-
d_out_dims
[
i
]
-
offsets
[
i
];
paddings
[
i
].
second
=
d_x
->
dims
()[
i
]
-
d_out
->
dims
()
[
i
]
-
offsets
[
i
];
}
auto
d_x_tensor
=
EigenTensor
<
T
,
D
>::
From
(
*
d_x
);
auto
d_out_tensor
=
EigenTensor
<
T
,
D
>::
From
(
*
d_out
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录