Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
c318aa5f
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
c318aa5f
编写于
6月 30, 2018
作者:
G
guochaorong
提交者:
GitHub
6月 30, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11850 from guochaorong/revert_11496
Revert "Extend fill_zeros_like_op for zero-filling an LoDTensorArray …
上级
d2ad4a5c
6a358991
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
9 addition
and
161 deletion
+9
-161
paddle/fluid/framework/operator.cc
paddle/fluid/framework/operator.cc
+0
-4
paddle/fluid/operators/fill_zeros_like_op.cc
paddle/fluid/operators/fill_zeros_like_op.cc
+3
-7
paddle/fluid/operators/fill_zeros_like_op.h
paddle/fluid/operators/fill_zeros_like_op.h
+6
-24
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+0
-38
python/paddle/fluid/tests/unittests/test_fill_zeros_like_op_for_array.py
...luid/tests/unittests/test_fill_zeros_like_op_for_array.py
+0
-88
未找到文件。
paddle/fluid/framework/operator.cc
浏览文件 @
c318aa5f
...
...
@@ -748,10 +748,6 @@ proto::VarType::Type OperatorWithKernel::IndicateDataType(
t
=
&
var
->
Get
<
LoDTensor
>
();
}
else
if
(
var
->
IsType
<
SelectedRows
>
())
{
t
=
&
(
var
->
Get
<
SelectedRows
>
().
value
());
}
else
if
(
var
->
IsType
<
LoDTensorArray
>
())
{
const
LoDTensorArray
&
arr
=
var
->
Get
<
LoDTensorArray
>
();
PADDLE_ENFORCE
(
arr
.
size
()
>
0
);
t
=
&
(
arr
[
0
]);
}
if
(
t
!=
nullptr
)
{
int
tmp
=
static_cast
<
int
>
(
ToDataType
(
t
->
type
()));
...
...
paddle/fluid/operators/fill_zeros_like_op.cc
浏览文件 @
c318aa5f
...
...
@@ -26,12 +26,8 @@ class FillZerosLikeOp : public framework::OperatorWithKernel {
"Input(X) of FillZerosLikeOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Output(Out) of FillZerosLikeOp should not be null."
);
if
(
ctx
->
IsRuntime
()
&&
ctx
->
GetOutputsVarType
(
"Out"
)[
0
]
==
framework
::
proto
::
VarType
::
LOD_TENSOR_ARRAY
)
{
return
;
// skip runtime infershape when is tensor array;
}
ctx
->
SetOutputDim
(
"Out"
,
ctx
->
GetInputDim
(
"X"
));
ctx
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
}
};
...
...
@@ -43,7 +39,7 @@ class FillZerosLikeOpMaker : public framework::OpProtoAndCheckerMaker {
AddComment
(
R"DOC(
FillZerosLike Operator.
Fill up a variable with zeros
, supporting both LoDTensor and LoDTensorArray
.
Fill up a variable with zeros.
The output will have the same size as the input.
)DOC"
);
...
...
paddle/fluid/operators/fill_zeros_like_op.h
浏览文件 @
c318aa5f
...
...
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include "paddle/fluid/framework/lod_tensor_array.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/operators/math/math_function.h"
...
...
@@ -24,29 +23,12 @@ template <typename DeviceContext, typename T>
class
FillZerosLikeKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
var
=
context
.
InputVar
(
"X"
);
if
(
var
->
IsType
<
framework
::
LoDTensor
>
())
{
auto
&
input
=
*
context
.
Input
<
framework
::
LoDTensor
>
(
"X"
);
auto
&
output
=
*
context
.
Output
<
framework
::
LoDTensor
>
(
"Out"
);
output
.
Resize
(
input
.
dims
());
output
.
set_lod
(
input
.
lod
());
output
.
mutable_data
<
T
>
(
context
.
GetPlace
());
math
::
SetConstant
<
DeviceContext
,
T
>
setter
;
setter
(
context
.
template
device_context
<
DeviceContext
>(),
&
(
output
),
static_cast
<
T
>
(
0
));
}
else
if
(
var
->
IsType
<
framework
::
LoDTensorArray
>
())
{
auto
&
input
=
*
context
.
Input
<
framework
::
LoDTensorArray
>
(
"X"
);
auto
&
output
=
*
context
.
Output
<
framework
::
LoDTensorArray
>
(
"Out"
);
output
.
resize
(
input
.
size
());
for
(
auto
i
=
0
;
i
<
input
.
size
();
i
++
)
{
output
[
i
].
Resize
(
input
[
i
].
dims
());
output
[
i
].
set_lod
(
input
[
i
].
lod
());
output
[
i
].
mutable_data
<
T
>
(
context
.
GetPlace
());
math
::
SetConstant
<
DeviceContext
,
T
>
setter
;
setter
(
context
.
template
device_context
<
DeviceContext
>(),
&
(
output
[
i
]),
static_cast
<
T
>
(
0
));
}
}
auto
*
out
=
context
.
Output
<
framework
::
Tensor
>
(
"Out"
);
out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
math
::
SetConstant
<
DeviceContext
,
T
>
setter
;
setter
(
context
.
template
device_context
<
DeviceContext
>(),
out
,
static_cast
<
T
>
(
0
));
}
};
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
c318aa5f
...
...
@@ -95,7 +95,6 @@ __all__ = [
'relu'
,
'log'
,
'crop'
,
'fill_zeros_like'
,
]
...
...
@@ -5185,40 +5184,3 @@ def crop(x, shape=None, offsets=None, name=None):
outputs
=
{
'Out'
:
out
},
attrs
=
None
if
len
(
attrs
)
==
0
else
attrs
)
return
out
def
fill_zeros_like
(
x
):
"""
This layer takes an input and outputs a variable that has the same structure as
the input and with all the element values as zero. The variable can be a Tensor
or TensorArray.
.. code-block:: text
Given
X = [[0, 1, 2, 0],
[0, 3, 4, 0],
[0, 0, 0, 0]],
output is:
Out = [[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]].
Args:
x (Variable): The input variable, which could be a tensor or tensor array
Returns:
Variable: The zero-filled variable, which has the same type and shape as
the input variable.
Examples:
.. code-block:: python
y = fluid.layers.fill_zeros_like(x)
"""
helper
=
LayerHelper
(
'fill_zeros_like'
,
**
locals
())
out
=
helper
.
create_tmp_variable
(
dtype
=
x
.
dtype
)
helper
.
append_op
(
type
=
'fill_zeros_like'
,
inputs
=
{
'X'
:
[
x
]},
outputs
=
{
'Out'
:
[
out
]})
return
out
python/paddle/fluid/tests/unittests/test_fill_zeros_like_op_for_array.py
已删除
100644 → 0
浏览文件 @
d2ad4a5c
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
#
# 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
unittest
import
paddle.fluid.core
as
core
import
numpy
import
paddle.fluid.layers
as
layers
from
paddle.fluid.framework
import
Program
,
program_guard
from
paddle.fluid.executor
import
Executor
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
class
TestFillZerosLikeOpForTensorArray
(
unittest
.
TestCase
):
def
place
(
self
):
return
core
.
CPUPlace
()
def
test_zero_filling_lod_tensor_array
(
self
):
tensor
=
core
.
LoDTensor
()
tensor
.
set
(
numpy
.
arange
(
20
).
reshape
(
20
,
1
).
astype
(
'int32'
),
self
.
place
())
tensor
.
set_lod
([[
0
,
2
,
5
],
[
0
,
3
,
9
,
11
,
17
,
20
]])
expect
=
[
numpy
.
array
(
[
0
,
0
,
0
,
0
,
0
],
dtype
=
'int32'
),
numpy
.
array
(
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
],
dtype
=
'int32'
),
numpy
.
array
(
[
0
,
0
,
0
],
dtype
=
'int32'
)
]
lod
=
[[[
0
,
2
,
5
]],
[[
0
,
6
,
12
]],
[[
0
,
3
]]]
self
.
main
(
tensor
=
tensor
,
expect_array
=
expect
,
expect_lod
=
lod
,
expect_max_len
=
3
)
def
main
(
self
,
tensor
,
expect_array
,
expect_lod
,
expect_max_len
,
level
=
0
):
place
=
self
.
place
()
program
=
Program
()
with
program_guard
(
program
):
x
=
layers
.
data
(
name
=
'x'
,
shape
=
[
10
])
x
.
persistable
=
True
table
=
layers
.
lod_rank_table
(
x
,
level
=
level
)
max_len
=
layers
.
max_sequence_len
(
table
)
max_len
.
persistable
=
True
array
=
layers
.
lod_tensor_to_array
(
x
,
table
)
array
=
layers
.
fill_zeros_like
(
array
)
array
.
persistable
=
True
result
=
layers
.
array_to_lod_tensor
(
array
,
table
)
result
.
persistable
=
True
exe
=
Executor
(
place
)
scope
=
core
.
Scope
()
exe
.
run
(
program
,
feed
=
{
'x'
:
tensor
},
scope
=
scope
)
var
=
scope
.
find_var
(
array
.
name
)
array
=
var
.
get_lod_tensor_array
()
if
expect_array
is
not
None
and
expect_lod
is
not
None
:
self
.
check_array_same
(
array
,
expect_array
,
expect_lod
)
self
.
assertEqual
(
numpy
.
array
(
scope
.
find_var
(
max_len
.
name
).
get_tensor
())[
0
],
expect_max_len
)
def
check_array_same
(
self
,
array
,
expect_tensor
,
expect_lod
):
self
.
assertEqual
(
len
(
expect_tensor
),
len
(
array
))
for
i
,
exp
in
enumerate
(
zip
(
expect_tensor
,
expect_lod
)):
exp_tensor
,
exp_lod
=
exp
exp_tensor
=
numpy
.
expand_dims
(
exp_tensor
,
axis
=
1
)
self
.
assertTrue
(
numpy
.
allclose
(
exp_tensor
,
numpy
.
array
(
array
[
i
])))
self
.
assertEqual
(
exp_lod
,
array
[
i
].
lod
())
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录