Class RandomCrop

Inheritance Relationships

Base Type

Class Documentation

class RandomCrop : public mindspore::dataset::TensorTransform

Crop the input image at a random location.

Public Functions

explicit RandomCrop(const std::vector<int32_t> &size, const std::vector<int32_t> &padding = {0, 0, 0, 0}, bool pad_if_needed = false, const std::vector<uint8_t> &fill_value = {0, 0, 0}, BorderType padding_mode = BorderType::kConstant)

Constructor.

Note

If the input image is more than one, then make sure that the image size is the same.

Note

The behavior when padding is a sequence of length 2 will change from padding left/top with the first value and right/bottom with the second, to padding left/right with the first one and top/bottom with the second in the future. Or you can pass in a 4-element sequence to specify left, top, right and bottom respectively.

Parameters
  • size[in] A vector representing the output size of the cropped image. If the size is a single value, a squared crop of size (size, size) is returned. If the size has 2 values, it should be (height, width).

  • padding[in] A vector representing the number of pixels to pad the image. If the vector has one value, it pads all sides of the image with that value. If the vector has two values, it pads left and top with the first and right and bottom with the second value. If the vector has four values, it pads left, top, right, and bottom with those values respectively.

  • pad_if_needed[in] A boolean indicating that whether to pad the image if either side is smaller than the given output size.

  • fill_value[in] A vector representing the pixel intensity of the borders if the padding_mode is BorderType.kConstant. If 1 value is provided, it is used for all RGB channels. If 3 values are provided, it is used to fill R, G, B channels respectively.

  • padding_mode[in] The method of padding (default=BorderType::kConstant).It can be any of [BorderType::kConstant, BorderType::kEdge, BorderType::kReflect, BorderType::kSymmetric].

    • BorderType::kConstant, Fill the border with constant values.

    • BorderType::kEdge, Fill the border with the last value on the edge.

    • BorderType::kReflect, Reflect the values on the edge omitting the last value of edge.

    • BorderType::kSymmetric, Reflect the values on the edge repeating the last value of edge.

样例
/* Define operations */
auto decode_op = vision::Decode();
auto random_crop_op = vision::RandomCrop({255, 255}, {10, 10, 10, 10});

/* dataset is an instance of Dataset object */
dataset = dataset->Map({decode_op, random_crop_op},  // operations
                       {"image"});                   // input columns
~RandomCrop() = default

Destructor.