未验证 提交 c2f07f5b 编写于 作者: V Vvsmile 提交者: GitHub

Remove API: random_crop (#47962)

remove random_crop which is not used in Paddle 2.0
上级 8c797baf
......@@ -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.
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册