random_crop

paddle.fluid.layers.random_crop(x, shape, seed=None)[source]

This operator takes a batch of instance, and do random cropping on each instance. It means that cropping positions differs on each instance, which is determined by an uniform random generator. All cropped instances have the same shape, which is determined by the operator’s attribute ‘shape’.

Parameters
  • x (Variable) – A batch of instances to random crop

  • shape (INTS) – The shape of a cropped instance

  • seed (int|Variable|None) – The random seed By default, the seed will get from random.randint(-65536, 65535).

Returns

The cropped instance batch

Examples

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])