From c2f07f5bfb0b99387934fbe44400353a9afa367a Mon Sep 17 00:00:00 2001 From: Vvsmile <450864116@qq.com> Date: Fri, 25 Nov 2022 17:35:39 +0800 Subject: [PATCH] Remove API: random_crop (#47962) remove random_crop which is not used in Paddle 2.0 --- python/paddle/fluid/layers/nn.py | 58 ------------------- .../tests/unittests/test_random_crop_op.py | 28 --------- 2 files changed, 86 deletions(-) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 25428cce876..aae6233acc8 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -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. diff --git a/python/paddle/fluid/tests/unittests/test_random_crop_op.py b/python/paddle/fluid/tests/unittests/test_random_crop_op.py index ae474618733..abad6d4cb9d 100644 --- a/python/paddle/fluid/tests/unittests/test_random_crop_op.py +++ b/python/paddle/fluid/tests/unittests/test_random_crop_op.py @@ -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() -- GitLab