Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7073ed5b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
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看板
未验证
提交
7073ed5b
编写于
11月 18, 2022
作者:
V
Vvsmile
提交者:
GitHub
11月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove API: pad_constant_like (#47949)
remove pad_constant_like which is not used in paddle 2.0
上级
9aacb31b
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
1 addition
and
135 deletion
+1
-135
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+0
-97
python/paddle/fluid/tests/unittests/test_pad_constant_like.py
...on/paddle/fluid/tests/unittests/test_pad_constant_like.py
+1
-38
未找到文件。
python/paddle/fluid/layers/nn.py
浏览文件 @
7073ed5b
...
@@ -107,7 +107,6 @@ __all__ = [
...
@@ -107,7 +107,6 @@ __all__ = [
'lod_append',
'lod_append',
'lrn',
'lrn',
'pad',
'pad',
'pad_constant_like',
'label_smooth',
'label_smooth',
'roi_pool',
'roi_pool',
'roi_align',
'roi_align',
...
@@ -7022,102 +7021,6 @@ def pad(x, paddings, pad_value=0.0, name=None):
...
@@ -7022,102 +7021,6 @@ def pad(x, paddings, pad_value=0.0, name=None):
return out
return out
def pad_constant_like(x, y, pad_value=0.0, name=None):
r"""
Pad :attr:`y` with :attr:`pad_value`, the number of values padded to
the edges of each axis is specified by the difference of the shape
of :attr:`x` and :attr:`y` . ((0, shape_x_0 - shape_y_0), ... (0, shape_x_n - shape_y_n))
specify padding widths for each axis. The input should be a k-D tensor(k > 0 and k < 7).
See below for an example.
.. code-block:: text
Given:
X = [[[[ 0, 1, 2],
[ 3, 4, 5]],
[[ 6, 7, 8],
[ 9, 10, 11]],
[[12, 13, 14],
[15, 16, 17]]],
[[[18, 19, 20],
[21, 22, 23]],
[[24, 25, 26],
[27, 28, 29]],
[[30, 31, 32],
[33, 34, 35]]]]
X.shape = (2, 3, 2, 3)
Y = [[[[35, 36, 37]],
[[38, 39, 40]],
[[41, 42, 43]]]]
Y.shape = (1, 3, 1, 3)
And
pad_value = 0.
Return:
Out = [[[[35, 36, 37],
[ 0, 0, 0]],
[[38, 39, 40],
[ 0, 0, 0]],
[[41, 42, 43],
[ 0, 0, 0]]],
[[[ 0, 0, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 0]],
[[ 0, 0, 0],
[ 0, 0, 0]]]]
Out.shape = [2, 3, 2, 3]
Args:
x (Variable): Tensor, its shape specifies the shape of output.
y (Variable): Tensor, its rank is the same with :attr:`x`, and for each dimension :math:`i` ,
:math:`y\_shape[i] <= x\_shape[i]` . The data type can be float32 or float64.
pad_value (float): The constant value used to pad.
name(str, optional): The default value is None.
Normally there is no need for user to set this property.
For more information, please refer to :ref:`api_guide_Name`
Returns:
The padded tensor, with the same shape as :attr:`x` and the same data type as :attr:`y`
Return Type:
Variable
Examples:
.. code-block:: python
# x is a rank 4 tensor variable, x.shape = (2, 3, 2, 3)
# y is a rank 4 tensor variable, y.shape = (1, 3, 1, 3)
import paddle.fluid as fluid
x = fluid.data(name='x', shape=[2,3,2,3], dtype='float32')
y = fluid.data(name='y', shape=[1,3,1,3], dtype='float32')
out = fluid.layers.pad_constant_like(x=x, y=y, pad_value=0.)
# out is a rank 4 tensor variable, and out.shape = [2, 3 ,2 , 3]
"""
check_type(x, 'x', (Variable), 'pad_constant_like')
check_variable_and_dtype(
y, 'y', ['float32', 'float64', 'int32', 'int64'], "pad_constant_like"
)
helper = LayerHelper('pad_constant_like', **locals())
dtype = helper.input_dtype(input_param_name='y')
out = helper.create_variable_for_type_inference(dtype)
helper.append_op(
type='pad_constant_like',
inputs={'X': x, 'Y': y},
outputs={'Out': out},
attrs={'pad_value': float(pad_value)},
)
return out
def label_smooth(
def label_smooth(
label, prior_dist=None, epsilon=0.1, dtype="float32", name=None
label, prior_dist=None, epsilon=0.1, dtype="float32", name=None
):
):
...
...
python/paddle/fluid/tests/unittests/test_pad_constant_like.py
浏览文件 @
7073ed5b
...
@@ -14,9 +14,7 @@
...
@@ -14,9 +14,7 @@
import
unittest
import
unittest
import
numpy
as
np
import
numpy
as
np
from
op_test
import
OpTest
,
check_out_dtype
from
op_test
import
OpTest
import
paddle.fluid
as
fluid
from
paddle.fluid
import
Program
,
program_guard
class
TestPadConstantLikeOp
(
OpTest
):
class
TestPadConstantLikeOp
(
OpTest
):
...
@@ -67,40 +65,5 @@ class TestCase2(TestPadConstantLikeOp):
...
@@ -67,40 +65,5 @@ class TestCase2(TestPadConstantLikeOp):
self
.
pad_value
=
0.5
self
.
pad_value
=
0.5
class
TestPadConstantLikeOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
x_data
=
np
.
random
.
random
((
2
,
2
,
2
,
2
)).
astype
(
"float32"
)
y_data
=
np
.
random
.
random
((
2
,
2
,
2
,
2
)).
astype
(
"float32"
)
def
test_Variable_x
():
var_y
=
fluid
.
data
(
name
=
"data_y"
,
shape
=
[
2
,
2
,
2
,
2
],
dtype
=
"float32"
)
fluid
.
layers
.
pad_constant_like
(
x
=
x_data
,
y
=
var_y
)
self
.
assertRaises
(
TypeError
,
test_Variable_x
)
def
test_Variable_y
():
var_x
=
fluid
.
data
(
name
=
"data_x"
,
shape
=
[
2
,
2
,
2
,
2
],
dtype
=
"float32"
)
fluid
.
layers
.
pad_constant_like
(
x
=
var_x
,
y
=
y_data
)
self
.
assertRaises
(
TypeError
,
test_Variable_y
)
class
TestOutDtype
(
unittest
.
TestCase
):
def
test_dtype
(
self
):
api_fn
=
fluid
.
layers
.
pad_constant_like
check_out_dtype
(
api_fn
,
in_specs
=
[([
2
,
3
,
2
,
3
],
'float64'
),
([
1
,
3
,
1
,
3
],)],
expect_dtypes
=
[
'float32'
,
'float64'
,
'int32'
,
'int64'
],
target_index
=
1
,
pad_value
=
0.0
,
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录