Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
5e7aa8c7
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5e7aa8c7
编写于
8月 14, 2018
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code clean
上级
855c9e33
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
19 addition
and
17 deletion
+19
-17
paddle/fluid/framework/tensor_impl.h
paddle/fluid/framework/tensor_impl.h
+8
-0
paddle/fluid/operators/cross_entropy_op.cc
paddle/fluid/operators/cross_entropy_op.cc
+3
-5
paddle/fluid/operators/cross_entropy_op.h
paddle/fluid/operators/cross_entropy_op.h
+3
-4
paddle/fluid/operators/softmax_op.h
paddle/fluid/operators/softmax_op.h
+5
-8
未找到文件。
paddle/fluid/framework/tensor_impl.h
浏览文件 @
5e7aa8c7
...
...
@@ -59,6 +59,14 @@ inline T* Tensor::mutable_data(platform::Place place) {
}
inline
Tensor
ReshapeToMatrix
(
const
Tensor
&
src
,
int
num_col_dims
)
{
int
rank
=
src
.
dims
().
size
();
PADDLE_ENFORCE_GE
(
rank
,
2
,
"'ReshapeToMatrix()' is only used for flatten high rank "
"tensors to matrixs. Can not be used in reshaping vectors."
);
if
(
rank
==
2
)
{
return
src
;
}
Tensor
res
;
res
.
ShareDataWith
(
src
);
res
.
Resize
(
flatten_to_2d
(
src
.
dims
(),
num_col_dims
));
...
...
paddle/fluid/operators/cross_entropy_op.cc
浏览文件 @
5e7aa8c7
...
...
@@ -45,11 +45,9 @@ class CrossEntropyOp : public framework::OperatorWithKernel {
"Input(Label) should be 1."
);
}
auto
out_dim_vec
=
framework
::
vectorize
(
framework
::
slice_ddim
(
x_dims
,
0
,
rank
-
1
));
out_dim_vec
.
push_back
(
1
);
ctx
->
SetOutputDim
(
"Y"
,
framework
::
make_ddim
(
out_dim_vec
));
auto
y_dims
=
x_dims
;
y_dims
[
rank
-
1
]
=
1
;
ctx
->
SetOutputDim
(
"Y"
,
y_dims
);
ctx
->
ShareLoD
(
"X"
,
/*->*/
"Y"
);
}
...
...
paddle/fluid/operators/cross_entropy_op.h
浏览文件 @
5e7aa8c7
...
...
@@ -34,10 +34,9 @@ class CrossEntropyOpKernel : public framework::OpKernel<T> {
y
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
int
rank
=
x
->
dims
().
size
();
Tensor
x_2d
=
rank
>
2
?
framework
::
ReshapeToMatrix
(
*
x
,
rank
-
1
)
:
*
x
;
Tensor
labels_2d
=
rank
>
2
?
framework
::
ReshapeToMatrix
(
*
labels
,
rank
-
1
)
:
*
labels
;
Tensor
y_2d
=
rank
>
2
?
framework
::
ReshapeToMatrix
(
*
y
,
rank
-
1
)
:
*
y
;
Tensor
x_2d
=
framework
::
ReshapeToMatrix
(
*
x
,
rank
-
1
);
Tensor
labels_2d
=
framework
::
ReshapeToMatrix
(
*
labels
,
rank
-
1
);
Tensor
y_2d
=
framework
::
ReshapeToMatrix
(
*
y
,
rank
-
1
);
math
::
CrossEntropyFunctor
<
DeviceContext
,
T
>
()(
ctx
.
template
device_context
<
DeviceContext
>(),
&
y_2d
,
&
x_2d
,
&
labels_2d
,
...
...
paddle/fluid/operators/softmax_op.h
浏览文件 @
5e7aa8c7
...
...
@@ -32,9 +32,8 @@ class SoftmaxKernel : public framework::OpKernel<T> {
Out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
int
rank
=
X
->
dims
().
size
();
Tensor
X_2d
=
rank
>
2
?
framework
::
ReshapeToMatrix
(
*
X
,
rank
-
1
)
:
*
X
;
Tensor
Out_2d
=
rank
>
2
?
framework
::
ReshapeToMatrix
(
*
Out
,
rank
-
1
)
:
*
Out
;
Tensor
X_2d
=
framework
::
ReshapeToMatrix
(
*
X
,
rank
-
1
);
Tensor
Out_2d
=
framework
::
ReshapeToMatrix
(
*
Out
,
rank
-
1
);
math
::
SoftmaxFunctor
<
DeviceContext
,
T
>
()(
context
.
template
device_context
<
DeviceContext
>(),
&
X_2d
,
&
Out_2d
);
...
...
@@ -53,11 +52,9 @@ class SoftmaxGradKernel : public framework::OpKernel<T> {
dX
->
mutable_data
<
T
>
(
context
.
GetPlace
());
int
rank
=
Out
->
dims
().
size
();
Tensor
Out_2d
=
rank
>
2
?
framework
::
ReshapeToMatrix
(
*
Out
,
rank
-
1
)
:
*
Out
;
Tensor
dOut_2d
=
rank
>
2
?
framework
::
ReshapeToMatrix
(
*
dOut
,
rank
-
1
)
:
*
dOut
;
Tensor
dX_2d
=
rank
>
2
?
framework
::
ReshapeToMatrix
(
*
dX
,
rank
-
1
)
:
*
dX
;
Tensor
Out_2d
=
framework
::
ReshapeToMatrix
(
*
Out
,
rank
-
1
);
Tensor
dOut_2d
=
framework
::
ReshapeToMatrix
(
*
dOut
,
rank
-
1
);
Tensor
dX_2d
=
framework
::
ReshapeToMatrix
(
*
dX
,
rank
-
1
);
math
::
SoftmaxGradFunctor
<
DeviceContext
,
T
>
()(
context
.
template
device_context
<
DeviceContext
>(),
&
Out_2d
,
&
dOut_2d
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录