Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c2f07f5b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
c2f07f5b
编写于
11月 25, 2022
作者:
V
Vvsmile
提交者:
GitHub
11月 25, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove API: random_crop (#47962)
remove random_crop which is not used in Paddle 2.0
上级
8c797baf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
0 addition
and
86 deletion
+0
-86
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+0
-58
python/paddle/fluid/tests/unittests/test_random_crop_op.py
python/paddle/fluid/tests/unittests/test_random_crop_op.py
+0
-28
未找到文件。
python/paddle/fluid/layers/nn.py
浏览文件 @
c2f07f5b
...
...
@@ -106,7 +106,6 @@ __all__ = [
'resize_trilinear'
,
'resize_nearest'
,
'gather_nd'
,
'random_crop'
,
'relu'
,
'log'
,
'crop_tensor'
,
...
...
@@ -6463,63 +6462,6 @@ def gather_nd(input, index, name=None):
return
output
@
templatedoc
()
def
random_crop
(
x
,
shape
,
seed
=
None
):
"""
${comment}
Args:
x(${x_type}): ${x_comment}
shape(${shape_type}): ${shape_comment}
seed(int|${seed_type}|None): ${seed_comment} By default, the seed will
get from `random.randint(-65536, 65535)`.
Returns:
${out_comment}
Examples:
.. code-block:: python
import paddle.fluid as fluid
img = fluid.data("img", [None, 3, 256, 256])
# cropped_img is [-1, 3, 224, 224]
cropped_img = fluid.layers.random_crop(img, shape=[3, 224, 224])
# cropped_img2 shape: [-1, 2, 224, 224]
# cropped_img2 = fluid.layers.random_crop(img, shape=[2, 224, 224])
# cropped_img3 shape: [-1, 3, 128, 224]
# cropped_img3 = fluid.layers.random_crop(img, shape=[128, 224])
"""
helper
=
LayerHelper
(
"random_crop"
,
**
locals
())
check_variable_and_dtype
(
x
,
'x'
,
[
'float32'
,
'float64'
,
'uint8'
,
'int16'
,
'int32'
],
'random_crop'
)
check_type
(
shape
,
'shape'
,
(
list
,
Variable
),
'random_crop'
)
dtype
=
x
.
dtype
out
=
helper
.
create_variable_for_type_inference
(
dtype
)
if
seed
is
None
:
seed
=
np
.
random
.
randint
(
-
65536
,
65536
)
op_attrs
=
{
"shape"
:
shape
}
if
isinstance
(
seed
,
int
):
op_attrs
[
"startup_seed"
]
=
seed
seed
=
helper
.
create_variable
(
name
=
unique_name
.
generate
(
"random_crop_seed"
),
dtype
=
"int64"
,
persistable
=
True
,
)
elif
not
isinstance
(
seed
,
Variable
):
raise
ValueError
(
"'seed' must be a Variable or an int."
)
helper
.
append_op
(
type
=
"random_crop"
,
inputs
=
{
"X"
:
x
,
"Seed"
:
seed
},
outputs
=
{
"Out"
:
out
,
"SeedOut"
:
seed
},
attrs
=
op_attrs
,
)
return
out
def
log
(
x
,
name
=
None
):
r
"""
Calculates the natural log of the given input tensor, element-wise.
...
...
python/paddle/fluid/tests/unittests/test_random_crop_op.py
浏览文件 @
c2f07f5b
...
...
@@ -15,7 +15,6 @@
import
unittest
import
numpy
as
np
from
op_test
import
OpTest
import
paddle.fluid
as
fluid
class
TestRandomCropOp
(
OpTest
):
...
...
@@ -44,32 +43,5 @@ class TestRandomCropOp(OpTest):
self
.
assertIn
(
True
,
is_equal
)
class
TestRandomCropOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
fluid
.
program_guard
(
fluid
.
Program
()):
def
test_x_type
():
input_data
=
np
.
random
.
random
(
2
,
3
,
256
,
256
).
astype
(
"float32"
)
fluid
.
layers
.
random_crop
(
input_data
)
self
.
assertRaises
(
TypeError
,
test_x_type
)
def
test_x_dtype
():
x2
=
fluid
.
layers
.
data
(
name
=
'x2'
,
shape
=
[
None
,
3
,
256
,
256
],
dtype
=
'float16'
)
fluid
.
layers
.
random_crop
(
x2
)
self
.
assertRaises
(
TypeError
,
test_x_dtype
)
def
test_shape_type
():
x3
=
fluid
.
layers
.
data
(
name
=
'x3'
,
shape
=
[
None
,
3
,
256
,
256
],
dtype
=
'float32'
)
fluid
.
layers
.
random_crop
(
x3
,
shape
=
1
)
self
.
assertRaises
(
TypeError
,
test_shape_type
)
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录