Class RandomApply

Inheritance Relationships

Base Type

Class Documentation

class RandomApply : public mindspore::dataset::TensorTransform

Randomly perform a series of transforms with a given probability.

Public Functions

explicit RandomApply(const std::vector<TensorTransform*> &transforms, double prob = 0.5)

Constructor.

参数
  • transforms[in] A vector of raw pointers to TensorTransform objects to be applied.

  • prob[in] The probability to apply the transformation list (default=0.5).

样例
/* Define operations */
auto resize_op(new vision::Resize({30, 30}));
auto center_crop_op(new vision::CenterCrop({16, 16}));
auto random_op(new transforms::RandomApply({resize_op, center_crop_op}));

/* dataset is an instance of Dataset object */
dataset = dataset->Map({random_op},   // operations
                       {"image"});    // input columns
explicit RandomApply(const std::vector<std::shared_ptr<TensorTransform>> &transforms, double prob = 0.5)

Constructor.

参数
  • transforms[in] A vector of shared pointers to TensorTransform objects to be applied.

  • prob[in] The probability to apply the transformation list (default=0.5).

样例
/* Define operations */
std::shared_ptr<TensorTransform> resize_op(new vision::Resize({30, 30}));
std::shared_ptr<TensorTransform> center_crop_op(new vision::CenterCrop({16, 16}));
std::shared_ptr<TensorTransform> random_op(new transforms::RandomApply({resize_op, center_crop_op}));

/* dataset is an instance of Dataset object */
dataset = dataset->Map({random_op},   // operations
                       {"image"});    // input columns
explicit RandomApply(const std::vector<std::reference_wrapper<TensorTransform>> &transforms, double prob = 0.5)

Constructor.

参数
  • transforms[in] A vector of TensorTransform objects to be applied.

  • prob[in] The probability to apply the transformation list (default=0.5).

样例
/* Define operations */
vision::Resize resize_op = vision::Resize({30, 30});
vision::CenterCrop center_crop_op = vision::CenterCrop({16, 16});
transforms::RandomApply random_op = transforms::RandomApply({resize_op, center_crop_op});

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

Destructor.