/** * Copyright 2020-2021 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "minddata/dataset/include/dataset/vision.h" #ifdef ENABLE_ACL #include "minddata/dataset/include/dataset/vision_ascend.h" #include "minddata/dataset/kernels/ir/vision/ascend_vision_ir.h" #endif #include "minddata/dataset/include/dataset/transforms.h" #include "minddata/dataset/kernels/ir/vision/affine_ir.h" #include "minddata/dataset/kernels/ir/vision/auto_contrast_ir.h" #include "minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.h" #include "minddata/dataset/kernels/ir/vision/center_crop_ir.h" #include "minddata/dataset/kernels/ir/vision/crop_ir.h" #include "minddata/dataset/kernels/ir/vision/cutmix_batch_ir.h" #include "minddata/dataset/kernels/ir/vision/cutout_ir.h" #include "minddata/dataset/kernels/ir/vision/decode_ir.h" #include "minddata/dataset/kernels/ir/vision/equalize_ir.h" #include "minddata/dataset/kernels/ir/vision/hwc_to_chw_ir.h" #include "minddata/dataset/kernels/ir/vision/invert_ir.h" #include "minddata/dataset/kernels/ir/vision/mixup_batch_ir.h" #include "minddata/dataset/kernels/ir/vision/normalize_ir.h" #include "minddata/dataset/kernels/ir/vision/normalize_pad_ir.h" #include "minddata/dataset/kernels/ir/vision/pad_ir.h" #include "minddata/dataset/kernels/ir/vision/random_affine_ir.h" #include "minddata/dataset/kernels/ir/vision/random_color_adjust_ir.h" #include "minddata/dataset/kernels/ir/vision/random_color_ir.h" #include "minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.h" #include "minddata/dataset/kernels/ir/vision/random_crop_ir.h" #include "minddata/dataset/kernels/ir/vision/random_crop_with_bbox_ir.h" #include "minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.h" #include "minddata/dataset/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.h" #include "minddata/dataset/kernels/ir/vision/random_posterize_ir.h" #include "minddata/dataset/kernels/ir/vision/random_resized_crop_ir.h" #include "minddata/dataset/kernels/ir/vision/random_resized_crop_with_bbox_ir.h" #include "minddata/dataset/kernels/ir/vision/random_resize_ir.h" #include "minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.h" #include "minddata/dataset/kernels/ir/vision/random_rotation_ir.h" #include "minddata/dataset/kernels/ir/vision/random_select_subpolicy_ir.h" #include "minddata/dataset/kernels/ir/vision/random_sharpness_ir.h" #include "minddata/dataset/kernels/ir/vision/random_solarize_ir.h" #include "minddata/dataset/kernels/ir/vision/random_vertical_flip_ir.h" #include "minddata/dataset/kernels/ir/vision/random_vertical_flip_with_bbox_ir.h" #include "minddata/dataset/kernels/ir/vision/rescale_ir.h" #include "minddata/dataset/kernels/ir/vision/resize_ir.h" #include "minddata/dataset/kernels/ir/vision/resize_preserve_ar_ir.h" #include "minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.h" #include "minddata/dataset/kernels/ir/vision/rgba_to_bgr_ir.h" #include "minddata/dataset/kernels/ir/vision/rgba_to_rgb_ir.h" #include "minddata/dataset/kernels/ir/vision/rgb_to_gray_ir.h" #include "minddata/dataset/kernels/ir/vision/rotate_ir.h" #include "minddata/dataset/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.h" #include "minddata/dataset/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.h" #include "minddata/dataset/kernels/ir/vision/swap_red_blue_ir.h" #include "minddata/dataset/kernels/ir/vision/uniform_aug_ir.h" #ifndef ENABLE_ANDROID #include "utils/log_adapter.h" #else #include "mindspore/lite/src/common/log_adapter.h" #endif #include "minddata/dataset/kernels/ir/validators.h" // Kernel image headers (in alphabetical order) namespace mindspore { namespace dataset { // Transform operations for computer vision. namespace vision { // CONSTRUCTORS FOR API CLASSES TO CREATE VISION TENSOR TRANSFORM OPERATIONS // (In alphabetical order) // Affine Transform Operation. struct Affine::Data { Data(float_t degrees, const std::vector &translation, float scale, const std::vector &shear, InterpolationMode interpolation, const std::vector &fill_value) : degrees_(degrees), translation_(translation), scale_(scale), shear_(shear), interpolation_(interpolation), fill_value_(fill_value) {} float degrees_; std::vector translation_; float scale_; std::vector shear_; InterpolationMode interpolation_; std::vector fill_value_; }; Affine::Affine(float_t degrees, const std::vector &translation, float scale, const std::vector &shear, InterpolationMode interpolation, const std::vector &fill_value) : data_(std::make_shared(degrees, translation, scale, shear, interpolation, fill_value)) {} std::shared_ptr Affine::Parse() { return std::make_shared(data_->degrees_, data_->translation_, data_->scale_, data_->shear_, data_->interpolation_, data_->fill_value_); } #ifndef ENABLE_ANDROID // AutoContrast Transform Operation. struct AutoContrast::Data { Data(float cutoff, const std::vector &ignore) : cutoff_(cutoff), ignore_(ignore) {} float cutoff_; std::vector ignore_; }; AutoContrast::AutoContrast(float cutoff, std::vector ignore) : data_(std::make_shared(cutoff, ignore)) {} std::shared_ptr AutoContrast::Parse() { return std::make_shared(data_->cutoff_, data_->ignore_); } // BoundingBoxAugment Transform Operation. struct BoundingBoxAugment::Data { std::shared_ptr transform_; float ratio_; }; BoundingBoxAugment::BoundingBoxAugment(TensorTransform *transform, float ratio) : data_(std::make_shared()) { data_->transform_ = transform ? transform->Parse() : nullptr; data_->ratio_ = ratio; } BoundingBoxAugment::BoundingBoxAugment(const std::shared_ptr &transform, float ratio) : data_(std::make_shared()) { data_->transform_ = transform ? transform->Parse() : nullptr; data_->ratio_ = ratio; } BoundingBoxAugment::BoundingBoxAugment(const std::reference_wrapper transform, float ratio) : data_(std::make_shared()) { data_->transform_ = transform.get().Parse(); data_->ratio_ = ratio; } std::shared_ptr BoundingBoxAugment::Parse() { return std::make_shared(data_->transform_, data_->ratio_); } #endif // not ENABLE_ANDROID // CenterCrop Transform Operation. struct CenterCrop::Data { explicit Data(const std::vector &size) : size_(size) {} std::vector size_; }; CenterCrop::CenterCrop(std::vector size) : data_(std::make_shared(size)) {} std::shared_ptr CenterCrop::Parse() { return std::make_shared(data_->size_); } std::shared_ptr CenterCrop::Parse(const MapTargetDevice &env) { if (env == MapTargetDevice::kAscend310) { #ifdef ENABLE_ACL std::vector usize_; usize_.reserve(data_->size_.size()); std::transform(data_->size_.begin(), data_->size_.end(), std::back_inserter(usize_), [](int32_t i) { return (uint32_t)i; }); return std::make_shared(usize_); #endif // ENABLE_ACL } return std::make_shared(data_->size_); } // RGB2GRAY Transform Operation. std::shared_ptr RGB2GRAY::Parse() { return std::make_shared(); } // Crop Transform Operation. struct Crop::Data { Data(const std::vector &coordinates, const std::vector &size) : coordinates_(coordinates), size_(size) {} std::vector coordinates_; std::vector size_; }; Crop::Crop(std::vector coordinates, std::vector size) : data_(std::make_shared(coordinates, size)) {} std::shared_ptr Crop::Parse() { return std::make_shared(data_->coordinates_, data_->size_); } #ifndef ENABLE_ANDROID // CutMixBatch Transform Operation. struct CutMixBatch::Data { Data(ImageBatchFormat image_batch_format, float alpha, float prob) : image_batch_format_(image_batch_format), alpha_(alpha), prob_(prob) {} float alpha_; float prob_; ImageBatchFormat image_batch_format_; }; CutMixBatch::CutMixBatch(ImageBatchFormat image_batch_format, float alpha, float prob) : data_(std::make_shared(image_batch_format, alpha, prob)) {} std::shared_ptr CutMixBatch::Parse() { return std::make_shared(data_->image_batch_format_, data_->alpha_, data_->prob_); } // CutOutOp. struct CutOut::Data { Data(int32_t length, int32_t num_patches) : length_(length), num_patches_(num_patches) {} int32_t length_; int32_t num_patches_; }; CutOut::CutOut(int32_t length, int32_t num_patches) : data_(std::make_shared(length, num_patches)) {} std::shared_ptr CutOut::Parse() { return std::make_shared(data_->length_, data_->num_patches_); } #endif // not ENABLE_ANDROID // Decode Transform Operation. struct Decode::Data { explicit Data(bool rgb) : rgb_(rgb) {} bool rgb_; }; Decode::Decode(bool rgb) : data_(std::make_shared(rgb)) {} std::shared_ptr Decode::Parse() { return std::make_shared(data_->rgb_); } std::shared_ptr Decode::Parse(const MapTargetDevice &env) { if (env == MapTargetDevice::kAscend310) { #ifdef ENABLE_ACL return std::make_shared(); #endif // ENABLE_ACL } return std::make_shared(data_->rgb_); } #ifdef ENABLE_ACL // DvppDecodeResize Transform Operation. struct DvppDecodeResizeJpeg::Data { explicit Data(const std::vector &resize) : resize_(resize) {} std::vector resize_; }; DvppDecodeResizeJpeg::DvppDecodeResizeJpeg(std::vector resize) : data_(std::make_shared(resize)) {} std::shared_ptr DvppDecodeResizeJpeg::Parse() { return std::make_shared(data_->resize_); } std::shared_ptr DvppDecodeResizeJpeg::Parse(const MapTargetDevice &env) { return std::make_shared(data_->resize_); } // DvppDecodeResizeCrop Transform Operation. struct DvppDecodeResizeCropJpeg::Data { Data(const std::vector &crop, const std::vector &resize) : crop_(crop), resize_(resize) {} std::vector crop_; std::vector resize_; }; DvppDecodeResizeCropJpeg::DvppDecodeResizeCropJpeg(std::vector crop, std::vector resize) : data_(std::make_shared(crop, resize)) {} std::shared_ptr DvppDecodeResizeCropJpeg::Parse() { return std::make_shared(data_->crop_, data_->resize_); } std::shared_ptr DvppDecodeResizeCropJpeg::Parse(const MapTargetDevice &env) { return std::make_shared(data_->crop_, data_->resize_); } // DvppDecodePng Transform Operation. DvppDecodePng::DvppDecodePng() {} std::shared_ptr DvppDecodePng::Parse() { return std::make_shared(); } std::shared_ptr DvppDecodePng::Parse(const MapTargetDevice &env) { return std::make_shared(); } #endif // ENABLE_ACL #ifndef ENABLE_ANDROID // Equalize Transform Operation. Equalize::Equalize() {} std::shared_ptr Equalize::Parse() { return std::make_shared(); } // HwcToChw Transform Operation. HWC2CHW::HWC2CHW() {} std::shared_ptr HWC2CHW::Parse() { return std::make_shared(); } // Invert Transform Operation. Invert::Invert() {} std::shared_ptr Invert::Parse() { return std::make_shared(); } // MixUpBatch Transform Operation. struct MixUpBatch::Data { explicit Data(float alpha) : alpha_(alpha) {} float alpha_; }; MixUpBatch::MixUpBatch(float alpha) : data_(std::make_shared(alpha)) {} std::shared_ptr MixUpBatch::Parse() { return std::make_shared(data_->alpha_); } #endif // not ENABLE_ANDROID // Normalize Transform Operation. struct Normalize::Data { Data(const std::vector &mean, const std::vector &std) : mean_(mean), std_(std) {} std::vector mean_; std::vector std_; }; Normalize::Normalize(std::vector mean, std::vector std) : data_(std::make_shared(mean, std)) {} std::shared_ptr Normalize::Parse() { return std::make_shared(data_->mean_, data_->std_); } std::shared_ptr Normalize::Parse(const MapTargetDevice &env) { if (env == MapTargetDevice::kAscend310) { #ifdef ENABLE_ACL return std::make_shared(data_->mean_, data_->std_); #endif // ENABLE_ACL } return std::make_shared(data_->mean_, data_->std_); } #ifndef ENABLE_ANDROID // NormalizePad Transform Operation. struct NormalizePad::Data { Data(const std::vector &mean, const std::vector &std, const std::string &dtype) : mean_(mean), std_(std), dtype_(dtype) {} std::vector mean_; std::vector std_; std::string dtype_; }; NormalizePad::NormalizePad(const std::vector &mean, const std::vector &std, const std::vector &dtype) : data_(std::make_shared(mean, std, CharToString(dtype))) {} std::shared_ptr NormalizePad::Parse() { return std::make_shared(data_->mean_, data_->std_, data_->dtype_); } // Pad Transform Operation. struct Pad::Data { Data(const std::vector &padding, const std::vector &fill_value, BorderType padding_mode) : padding_(padding), fill_value_(fill_value), padding_mode_(padding_mode) {} std::vector padding_; std::vector fill_value_; BorderType padding_mode_; }; Pad::Pad(std::vector padding, std::vector fill_value, BorderType padding_mode) : data_(std::make_shared(padding, fill_value, padding_mode)) {} std::shared_ptr Pad::Parse() { return std::make_shared(data_->padding_, data_->fill_value_, data_->padding_mode_); } #endif // not ENABLE_ANDROID // RandomAffine Transform Operation. struct RandomAffine::Data { Data(const std::vector °rees, const std::vector &translate_range, const std::vector &scale_range, const std::vector &shear_ranges, InterpolationMode interpolation, const std::vector &fill_value) : degrees_(degrees), translate_range_(translate_range), scale_range_(scale_range), shear_ranges_(shear_ranges), interpolation_(interpolation), fill_value_(fill_value) {} std::vector degrees_; // min_degree, max_degree std::vector translate_range_; // maximum x translation percentage, maximum y translation percentage std::vector scale_range_; // min_scale, max_scale std::vector shear_ranges_; // min_x_shear, max_x_shear, min_y_shear, max_y_shear InterpolationMode interpolation_; std::vector fill_value_; }; RandomAffine::RandomAffine(const std::vector °rees, const std::vector &translate_range, const std::vector &scale_range, const std::vector &shear_ranges, InterpolationMode interpolation, const std::vector &fill_value) : data_(std::make_shared(degrees, translate_range, scale_range, shear_ranges, interpolation, fill_value)) {} std::shared_ptr RandomAffine::Parse() { return std::make_shared(data_->degrees_, data_->translate_range_, data_->scale_range_, data_->shear_ranges_, data_->interpolation_, data_->fill_value_); } #ifndef ENABLE_ANDROID // RandomColor Transform Operation. struct RandomColor::Data { Data(float t_lb, float t_ub) : t_lb_(t_lb), t_ub_(t_ub) {} float t_lb_; float t_ub_; }; RandomColor::RandomColor(float t_lb, float t_ub) : data_(std::make_shared(t_lb, t_ub)) {} std::shared_ptr RandomColor::Parse() { return std::make_shared(data_->t_lb_, data_->t_ub_); } // RandomColorAdjust Transform Operation. struct RandomColorAdjust::Data { Data(const std::vector &brightness, const std::vector &contrast, const std::vector &saturation, const std::vector &hue) : brightness_(brightness), contrast_(contrast), saturation_(saturation), hue_(hue) {} std::vector brightness_; std::vector contrast_; std::vector saturation_; std::vector hue_; }; RandomColorAdjust::RandomColorAdjust(std::vector brightness, std::vector contrast, std::vector saturation, std::vector hue) : data_(std::make_shared(brightness, contrast, saturation, hue)) {} std::shared_ptr RandomColorAdjust::Parse() { return std::make_shared(data_->brightness_, data_->contrast_, data_->saturation_, data_->hue_); } // RandomCrop Transform Operation. struct RandomCrop::Data { Data(const std::vector &size, const std::vector &padding, bool pad_if_needed, const std::vector &fill_value, BorderType padding_mode) : size_(size), padding_(padding), pad_if_needed_(pad_if_needed), fill_value_(fill_value), padding_mode_(padding_mode) {} std::vector size_; std::vector padding_; bool pad_if_needed_; std::vector fill_value_; BorderType padding_mode_; }; RandomCrop::RandomCrop(std::vector size, std::vector padding, bool pad_if_needed, std::vector fill_value, BorderType padding_mode) : data_(std::make_shared(size, padding, pad_if_needed, fill_value, padding_mode)) {} std::shared_ptr RandomCrop::Parse() { return std::make_shared(data_->size_, data_->padding_, data_->pad_if_needed_, data_->fill_value_, data_->padding_mode_); } // RandomCropDecodeResize Transform Operation. struct RandomCropDecodeResize::Data { Data(const std::vector &size, const std::vector &scale, const std::vector &ratio, InterpolationMode interpolation, int32_t max_attempts) : size_(size), scale_(scale), ratio_(ratio), interpolation_(interpolation), max_attempts_(max_attempts) {} std::vector size_; std::vector scale_; std::vector ratio_; InterpolationMode interpolation_; int32_t max_attempts_; }; RandomCropDecodeResize::RandomCropDecodeResize(std::vector size, std::vector scale, std::vector ratio, InterpolationMode interpolation, int32_t max_attempts) : data_(std::make_shared(size, scale, ratio, interpolation, max_attempts)) {} std::shared_ptr RandomCropDecodeResize::Parse() { return std::make_shared(data_->size_, data_->scale_, data_->ratio_, data_->interpolation_, data_->max_attempts_); } // RandomCropWithBBox Transform Operation. struct RandomCropWithBBox::Data { Data(const std::vector &size, const std::vector &padding, bool pad_if_needed, const std::vector &fill_value, BorderType padding_mode) : size_(size), padding_(padding), pad_if_needed_(pad_if_needed), fill_value_(fill_value), padding_mode_(padding_mode) {} std::vector size_; std::vector padding_; bool pad_if_needed_; std::vector fill_value_; BorderType padding_mode_; }; RandomCropWithBBox::RandomCropWithBBox(std::vector size, std::vector padding, bool pad_if_needed, std::vector fill_value, BorderType padding_mode) : data_(std::make_shared(size, padding, pad_if_needed, fill_value, padding_mode)) {} std::shared_ptr RandomCropWithBBox::Parse() { return std::make_shared(data_->size_, data_->padding_, data_->pad_if_needed_, data_->fill_value_, data_->padding_mode_); } // RandomHorizontalFlip. struct RandomHorizontalFlip::Data { explicit Data(float prob) : probability_(prob) {} float probability_; }; RandomHorizontalFlip::RandomHorizontalFlip(float prob) : data_(std::make_shared(prob)) {} std::shared_ptr RandomHorizontalFlip::Parse() { return std::make_shared(data_->probability_); } // RandomHorizontalFlipWithBBox struct RandomHorizontalFlipWithBBox::Data { explicit Data(float prob) : probability_(prob) {} float probability_; }; RandomHorizontalFlipWithBBox::RandomHorizontalFlipWithBBox(float prob) : data_(std::make_shared(prob)) {} std::shared_ptr RandomHorizontalFlipWithBBox::Parse() { return std::make_shared(data_->probability_); } // RandomPosterize Transform Operation. struct RandomPosterize::Data { explicit Data(const std::vector &bit_range) : bit_range_(bit_range) {} std::vector bit_range_; }; RandomPosterize::RandomPosterize(const std::vector &bit_range) : data_(std::make_shared(bit_range)) {} std::shared_ptr RandomPosterize::Parse() { return std::make_shared(data_->bit_range_); } // RandomResize Transform Operation. struct RandomResize::Data { explicit Data(const std::vector &size) : size_(size) {} std::vector size_; }; RandomResize::RandomResize(std::vector size) : data_(std::make_shared(size)) {} std::shared_ptr RandomResize::Parse() { return std::make_shared(data_->size_); } // RandomResizeWithBBox Transform Operation. struct RandomResizeWithBBox::Data { explicit Data(const std::vector &size) : size_(size) {} std::vector size_; }; RandomResizeWithBBox::RandomResizeWithBBox(std::vector size) : data_(std::make_shared(size)) {} std::shared_ptr RandomResizeWithBBox::Parse() { return std::make_shared(data_->size_); } // RandomResizedCrop Transform Operation. struct RandomResizedCrop::Data { Data(const std::vector &size, const std::vector &scale, const std::vector &ratio, InterpolationMode interpolation, int32_t max_attempts) : size_(size), scale_(scale), ratio_(ratio), interpolation_(interpolation), max_attempts_(max_attempts) {} std::vector size_; std::vector scale_; std::vector ratio_; InterpolationMode interpolation_; int32_t max_attempts_; }; RandomResizedCrop::RandomResizedCrop(std::vector size, std::vector scale, std::vector ratio, InterpolationMode interpolation, int32_t max_attempts) : data_(std::make_shared(size, scale, ratio, interpolation, max_attempts)) {} std::shared_ptr RandomResizedCrop::Parse() { return std::make_shared(data_->size_, data_->scale_, data_->ratio_, data_->interpolation_, data_->max_attempts_); } // RandomResizedCrop Transform Operation. struct RandomResizedCropWithBBox::Data { Data(const std::vector &size, const std::vector &scale, const std::vector &ratio, InterpolationMode interpolation, int32_t max_attempts) : size_(size), scale_(scale), ratio_(ratio), interpolation_(interpolation), max_attempts_(max_attempts) {} std::vector size_; std::vector scale_; std::vector ratio_; InterpolationMode interpolation_; int32_t max_attempts_; }; RandomResizedCropWithBBox::RandomResizedCropWithBBox(std::vector size, std::vector scale, std::vector ratio, InterpolationMode interpolation, int32_t max_attempts) : data_(std::make_shared(size, scale, ratio, interpolation, max_attempts)) {} std::shared_ptr RandomResizedCropWithBBox::Parse() { return std::make_shared(data_->size_, data_->scale_, data_->ratio_, data_->interpolation_, data_->max_attempts_); } // RandomRotation Transform Operation. struct RandomRotation::Data { Data(const std::vector °rees, InterpolationMode interpolation_mode, bool expand, const std::vector ¢er, const std::vector &fill_value) : degrees_(degrees), interpolation_mode_(interpolation_mode), expand_(expand), center_(center), fill_value_(fill_value) {} std::vector degrees_; InterpolationMode interpolation_mode_; std::vector center_; bool expand_; std::vector fill_value_; }; RandomRotation::RandomRotation(std::vector degrees, InterpolationMode interpolation_mode, bool expand, std::vector center, std::vector fill_value) : data_(std::make_shared(degrees, interpolation_mode, expand, center, fill_value)) {} std::shared_ptr RandomRotation::Parse() { return std::make_shared(data_->degrees_, data_->interpolation_mode_, data_->expand_, data_->center_, data_->fill_value_); } // RandomSelectSubpolicy Transform Operation. struct RandomSelectSubpolicy::Data { std::vector, double>>> policy_; }; RandomSelectSubpolicy::RandomSelectSubpolicy( const std::vector>> &policy) : data_(std::make_shared()) { for (int32_t i = 0; i < policy.size(); i++) { std::vector, double>> subpolicy; for (int32_t j = 0; j < policy[i].size(); j++) { TensorTransform *op = policy[i][j].first; std::shared_ptr operation = (op ? op->Parse() : nullptr); double prob = policy[i][j].second; subpolicy.emplace_back(std::move(std::make_pair(operation, prob))); } data_->policy_.emplace_back(subpolicy); } } RandomSelectSubpolicy::RandomSelectSubpolicy( const std::vector, double>>> &policy) : data_(std::make_shared()) { for (int32_t i = 0; i < policy.size(); i++) { std::vector, double>> subpolicy; for (int32_t j = 0; j < policy[i].size(); j++) { std::shared_ptr op = policy[i][j].first; std::shared_ptr operation = (op ? op->Parse() : nullptr); double prob = policy[i][j].second; subpolicy.emplace_back(std::move(std::make_pair(operation, prob))); } data_->policy_.emplace_back(subpolicy); } } RandomSelectSubpolicy::RandomSelectSubpolicy( const std::vector, double>>> &policy) : data_(std::make_shared()) { for (int32_t i = 0; i < policy.size(); i++) { std::vector, double>> subpolicy; for (int32_t j = 0; j < policy[i].size(); j++) { TensorTransform &op = policy[i][j].first; std::shared_ptr operation = op.Parse(); double prob = policy[i][j].second; subpolicy.emplace_back(std::move(std::make_pair(operation, prob))); } data_->policy_.emplace_back(subpolicy); } } std::shared_ptr RandomSelectSubpolicy::Parse() { return std::make_shared(data_->policy_); } // RandomSharpness Transform Operation. struct RandomSharpness::Data { explicit Data(const std::vector °rees) : degrees_(degrees) {} std::vector degrees_; }; RandomSharpness::RandomSharpness(std::vector degrees) : data_(std::make_shared(degrees)) {} std::shared_ptr RandomSharpness::Parse() { return std::make_shared(data_->degrees_); } // RandomSolarize Transform Operation. struct RandomSolarize::Data { explicit Data(const std::vector &threshold) : threshold_(threshold) {} std::vector threshold_; }; RandomSolarize::RandomSolarize(std::vector threshold) : data_(std::make_shared(threshold)) {} std::shared_ptr RandomSolarize::Parse() { return std::make_shared(data_->threshold_); } // RandomVerticalFlip Transform Operation. struct RandomVerticalFlip::Data { explicit Data(float prob) : probability_(prob) {} float probability_; }; RandomVerticalFlip::RandomVerticalFlip(float prob) : data_(std::make_shared(prob)) {} std::shared_ptr RandomVerticalFlip::Parse() { return std::make_shared(data_->probability_); } // RandomVerticalFlipWithBBox Transform Operation. struct RandomVerticalFlipWithBBox::Data { explicit Data(float prob) : probability_(prob) {} float probability_; }; RandomVerticalFlipWithBBox::RandomVerticalFlipWithBBox(float prob) : data_(std::make_shared(prob)) {} std::shared_ptr RandomVerticalFlipWithBBox::Parse() { return std::make_shared(data_->probability_); } // Rescale Transform Operation. struct Rescale::Data { Data(float rescale, float shift) : rescale_(rescale), shift_(shift) {} float rescale_; float shift_; }; Rescale::Rescale(float rescale, float shift) : data_(std::make_shared(rescale, shift)) {} std::shared_ptr Rescale::Parse() { return std::make_shared(data_->rescale_, data_->shift_); } #endif // not ENABLE_ANDROID // Resize Transform Operation. struct Resize::Data { Data(const std::vector &size, InterpolationMode interpolation) : size_(size), interpolation_(interpolation) {} std::vector size_; InterpolationMode interpolation_; }; Resize::Resize(std::vector size, InterpolationMode interpolation) : data_(std::make_shared(size, interpolation)) {} std::shared_ptr Resize::Parse() { return std::make_shared(data_->size_, data_->interpolation_); } std::shared_ptr Resize::Parse(const MapTargetDevice &env) { if (env == MapTargetDevice::kAscend310) { #ifdef ENABLE_ACL std::vector usize_; usize_.reserve(data_->size_.size()); std::transform(data_->size_.begin(), data_->size_.end(), std::back_inserter(usize_), [](int32_t i) { return (uint32_t)i; }); return std::make_shared(usize_); #endif // ENABLE_ACL } return std::make_shared(data_->size_, data_->interpolation_); } // ResizePreserveAR Transform Operation. struct ResizePreserveAR::Data { Data(int32_t height, int32_t width, int32_t img_orientation) : height_(height), width_(width), img_orientation_(img_orientation) {} int32_t height_; int32_t width_; int32_t img_orientation_; }; ResizePreserveAR::ResizePreserveAR(int32_t height, int32_t width, int32_t img_orientation) : data_(std::make_shared(height, width, img_orientation)) {} std::shared_ptr ResizePreserveAR::Parse() { return std::make_shared(data_->height_, data_->width_, data_->img_orientation_); } #ifdef ENABLE_ANDROID // Rotate Transform Operation. Rotate::Rotate() {} std::shared_ptr Rotate::Parse() { return std::make_shared(); } #endif // ENABLE_ANDROID #ifndef ENABLE_ANDROID // ResizeWithBBox Transform Operation. struct ResizeWithBBox::Data { Data(const std::vector &size, InterpolationMode interpolation) : size_(size), interpolation_(interpolation) {} std::vector size_; InterpolationMode interpolation_; }; ResizeWithBBox::ResizeWithBBox(std::vector size, InterpolationMode interpolation) : data_(std::make_shared(size, interpolation)) {} std::shared_ptr ResizeWithBBox::Parse() { return std::make_shared(data_->size_, data_->interpolation_); } // RgbaToBgr Transform Operation. RGBA2BGR::RGBA2BGR() {} std::shared_ptr RGBA2BGR::Parse() { return std::make_shared(); } // RgbaToRgb Transform Operation. RGBA2RGB::RGBA2RGB() {} std::shared_ptr RGBA2RGB::Parse() { return std::make_shared(); } // SoftDvppDecodeRandomCropResizeJpeg Transform Operation. struct SoftDvppDecodeRandomCropResizeJpeg::Data { Data(const std::vector &size, const std::vector &scale, const std::vector &ratio, int32_t max_attempts) : size_(size), scale_(scale), ratio_(ratio), max_attempts_(max_attempts) {} std::vector size_; std::vector scale_; std::vector ratio_; int32_t max_attempts_; }; SoftDvppDecodeRandomCropResizeJpeg::SoftDvppDecodeRandomCropResizeJpeg(std::vector size, std::vector scale, std::vector ratio, int32_t max_attempts) : data_(std::make_shared(size, scale, ratio, max_attempts)) {} std::shared_ptr SoftDvppDecodeRandomCropResizeJpeg::Parse() { return std::make_shared(data_->size_, data_->scale_, data_->ratio_, data_->max_attempts_); } // SoftDvppDecodeResizeJpeg Transform Operation. struct SoftDvppDecodeResizeJpeg::Data { explicit Data(const std::vector &size) : size_(size) {} std::vector size_; }; SoftDvppDecodeResizeJpeg::SoftDvppDecodeResizeJpeg(std::vector size) : data_(std::make_shared(size)) {} std::shared_ptr SoftDvppDecodeResizeJpeg::Parse() { return std::make_shared(data_->size_); } // SwapRedBlue Transform Operation. SwapRedBlue::SwapRedBlue() {} std::shared_ptr SwapRedBlue::Parse() { return std::make_shared(); } // UniformAug Transform Operation. struct UniformAugment::Data { std::vector> transforms_; int32_t num_ops_; }; UniformAugment::UniformAugment(const std::vector &transforms, int32_t num_ops) : data_(std::make_shared()) { (void)std::transform( transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_), [](TensorTransform *const op) -> std::shared_ptr { return op ? op->Parse() : nullptr; }); data_->num_ops_ = num_ops; } UniformAugment::UniformAugment(const std::vector> &transforms, int32_t num_ops) : data_(std::make_shared()) { (void)std::transform( transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_), [](std::shared_ptr op) -> std::shared_ptr { return op ? op->Parse() : nullptr; }); data_->num_ops_ = num_ops; } UniformAugment::UniformAugment(const std::vector> &transforms, int32_t num_ops) : data_(std::make_shared()) { (void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_), [](TensorTransform &op) -> std::shared_ptr { return op.Parse(); }); data_->num_ops_ = num_ops; } std::shared_ptr UniformAugment::Parse() { return std::make_shared(data_->transforms_, data_->num_ops_); } #endif // not ENABLE_ANDROID } // namespace vision } // namespace dataset } // namespace mindspore