diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index adddf52c1e8eabec4c4a05410c9606f275ebcc5f..e9ca037e49916a93c6804463eaf8d43a8118fe61 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -124,7 +124,6 @@ __all__ = [ 'mean_iou', 'relu', 'log', - 'crop', 'crop_tensor', 'pow', 'hard_sigmoid', @@ -9137,108 +9136,6 @@ def mean_iou(input, label, num_classes): return out_mean_iou, out_wrong, out_correct -def crop(x, shape=None, offsets=None, name=None): - """ - Crop input into output, as specified by offsets and shape. - - **Warning:** THIS OP IS DEPRECATED. It will be removed in the future version. - Instructions for updating: Use :ref:`api_fluid_layers_crop_tensor` instead. - - .. code-block:: text - - * Case 1: - Given - X = [[0, 1, 2, 0, 0] - [0, 3, 4, 0, 0] - [0, 0, 0, 0, 0]], - and - shape = [2, 2], - offsets = [0, 1], - output is: - Out = [[1, 2], - [3, 4]]. - * Case 2: - Given - X = [[0, 1, 2, 5, 0] - [0, 3, 4, 6, 0] - [0, 0, 0, 0, 0]], - and shape is tensor - shape = [[0, 0, 0] - [0, 0, 0]] - and - offsets = [0, 1], - - output is: - Out = [[1, 2, 5], - [3, 4, 6]]. - - Parameters: - x (Variable): Tensor, data type can be float32 or float64. - shape (Variable|list/tuple of integers, optional): The output shape is specified - by `shape`, which can be a Tensor or a list/tuple of integers. - If it is a Tensor, it's rank must be the same as `x` , only - it's shape will be used, and the value of it will be ignored. This way - is suitable for the case that the output shape may be changed each - iteration. If it is a list/tuple of integers, it's length must be the same - as the rank of `x` - offsets (Variable|list/tuple of integers|None, optional): Specifies the cropping - offsets at each dimension. It can be a Tensor or a list/tuple - of integers. If it is a Tensor, it's rank must be the same as `x`. - This way is suitable for the case that the offsets may be changed - each iteration. If it is a list/tuple of integers, it's length must be the - same as the rank of `x`. If None, the offsets are 0 at each dimension. - name(str, optional): For detailed information, please refer - to :ref:`api_guide_Name` . Usually name is no need to set and - None by default. - - Returns: - Tensor, The cropped Tensor, which has the same rank and data type with `x`. - - Examples: - - .. code-block:: python - - import paddle.fluid as fluid - import paddle.fluid as fluid - import paddle - paddle.enable_static() - x = fluid.data(name="x", shape=[3, 3, 5], dtype="float32") - y = fluid.data(name="y", shape=[2, 2, 3], dtype="float32") - crop = fluid.layers.crop(x, shape=y) - - # or - z = fluid.data(name="z", shape=[3, 3, 5], dtype="float32") - crop = fluid.layers.crop(z, shape=[2, 2, 3]) - - """ - check_variable_and_dtype(x, 'x', ['float32'], 'crop') - check_type(shape, 'shape', (list, tuple, Variable), 'crop') - helper = LayerHelper('crop', **locals()) - - if offsets is None: - offsets = [0] * len(x.shape) - - out = helper.create_variable_for_type_inference(x.dtype) - ipts = {'X': x} - attrs = {} - if isinstance(shape, Variable): - ipts['Y'] = shape - else: - attrs['shape'] = shape - if isinstance(offsets, Variable): - ipts['Offsets'] = offsets - else: - attrs['offsets'] = offsets - - helper.append_op( - type='crop', - inputs=ipts, - outputs={'Out': out}, - attrs=None if len(attrs) == 0 else attrs, - ) - return out - - def crop_tensor(x, shape=None, offsets=None, name=None): """ Crop input into output, as specified by offsets and shape. diff --git a/python/paddle/fluid/tests/unittests/test_layers.py b/python/paddle/fluid/tests/unittests/test_layers.py index 27d7e42accf18a661c203bb17ca36ab29dacd4b3..f97c94858bd6a5bfd1131ab260450d676de0c15b 100644 --- a/python/paddle/fluid/tests/unittests/test_layers.py +++ b/python/paddle/fluid/tests/unittests/test_layers.py @@ -3588,15 +3588,6 @@ class TestBook(LayerTest): output = layers.l2_normalize(x, axis=1) return output - def make_crop(self): - with program_guard( - fluid.default_main_program(), fluid.default_startup_program() - ): - x = self._get_data(name='x', shape=[3, 5], dtype="float32") - y = self._get_data(name='y', shape=[2, 3], dtype="float32") - output = layers.crop(x, shape=y) - return output - def make_mean_iou(self): with fluid.framework._dygraph_place_guard(place=fluid.CPUPlace()): x = self._get_data(name='x', shape=[16], dtype='int32')