From 1061153af307e1bda6d1df02eb8fabfd264b1b09 Mon Sep 17 00:00:00 2001 From: mohammad Date: Thu, 15 Jul 2021 10:46:16 -0400 Subject: [PATCH] fix CI warnings --- .../minddata/dataset/engine/cache/cache_hw.cc | 4 +- .../source/samplers/distributed_sampler_ir.cc | 2 - .../source/samplers/pk_sampler_ir.cc | 2 - .../source/samplers/prebuilt_sampler_ir.cc | 2 - .../source/samplers/random_sampler_ir.cc | 2 - .../source/samplers/sequential_sampler_ir.cc | 2 - .../samplers/subset_random_sampler_ir.cc | 2 - .../source/samplers/subset_sampler_ir.cc | 2 - .../samplers/weighted_random_sampler_ir.cc | 2 - .../dataset/kernels/ir/vision/affine_ir.cc | 9 +-- .../kernels/ir/vision/auto_contrast_ir.cc | 7 +- .../ir/vision/bounding_box_augment_ir.cc | 4 - .../kernels/ir/vision/center_crop_ir.cc | 6 +- .../dataset/kernels/ir/vision/crop_ir.cc | 9 +-- .../kernels/ir/vision/cutmix_batch_ir.cc | 4 - .../dataset/kernels/ir/vision/cutout_ir.cc | 4 - .../dataset/kernels/ir/vision/decode_ir.cc | 3 - .../dataset/kernels/ir/vision/equalize_ir.cc | 5 -- .../kernels/ir/vision/hwc_to_chw_ir.cc | 4 - .../dataset/kernels/ir/vision/invert_ir.cc | 5 -- .../kernels/ir/vision/mixup_batch_ir.cc | 5 -- .../dataset/kernels/ir/vision/normalize_ir.cc | 3 - .../kernels/ir/vision/normalize_pad_ir.cc | 9 ++- .../dataset/kernels/ir/vision/pad_ir.cc | 53 ++++++------- .../kernels/ir/vision/random_affine_ir.cc | 74 +++++++++++-------- .../ir/vision/random_color_adjust_ir.cc | 31 ++++---- .../kernels/ir/vision/random_color_ir.cc | 4 - .../ir/vision/random_crop_decode_resize_ir.cc | 24 +++--- .../kernels/ir/vision/random_crop_ir.cc | 62 ++++++++-------- .../ir/vision/random_crop_with_bbox_ir.cc | 63 ++++++++-------- .../ir/vision/random_horizontal_flip_ir.cc | 5 -- .../random_horizontal_flip_with_bbox_ir.cc | 5 -- .../kernels/ir/vision/random_posterize_ir.cc | 30 ++++---- .../kernels/ir/vision/random_resize_ir.cc | 15 ++-- .../ir/vision/random_resize_with_bbox_ir.cc | 15 ++-- .../ir/vision/random_resized_crop_ir.cc | 18 +++-- .../random_resized_crop_with_bbox_ir.cc | 20 ++--- .../kernels/ir/vision/random_rotation_ir.cc | 48 ++++++------ .../ir/vision/random_select_subpolicy_ir.cc | 4 - .../kernels/ir/vision/random_sharpness_ir.cc | 14 ++-- .../kernels/ir/vision/random_solarize_ir.cc | 16 ++-- .../ir/vision/random_vertical_flip_ir.cc | 5 -- .../random_vertical_flip_with_bbox_ir.cc | 5 -- .../dataset/kernels/ir/vision/rescale_ir.cc | 5 -- .../dataset/kernels/ir/vision/resize_ir.cc | 13 ++-- .../ir/vision/resize_preserve_ar_ir.cc | 3 - .../kernels/ir/vision/resize_with_bbox_ir.cc | 14 ++-- .../kernels/ir/vision/rgb_to_gray_ir.cc | 3 - .../kernels/ir/vision/rgba_to_bgr_ir.cc | 3 - .../kernels/ir/vision/rgba_to_rgb_ir.cc | 5 -- .../dataset/kernels/ir/vision/rotate_ir.cc | 2 - ...tdvpp_decode_random_crop_resize_jpeg_ir.cc | 26 ++++--- .../vision/softdvpp_decode_resize_jpeg_ir.cc | 18 +++-- .../kernels/ir/vision/swap_red_blue_ir.cc | 4 - .../kernels/ir/vision/uniform_aug_ir.cc | 3 - .../lite/tools/dataset/cropper/build_lib.py | 2 +- mindspore/lite/tools/dataset/cropper/crop.sh | 14 ++-- .../dataset/cropper/cropper_configure.py | 7 +- 58 files changed, 329 insertions(+), 401 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/engine/cache/cache_hw.cc b/mindspore/ccsrc/minddata/dataset/engine/cache/cache_hw.cc index 877ad27205c..22eb02db046 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/cache/cache_hw.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/cache/cache_hw.cc @@ -269,7 +269,9 @@ uint64_t CacheServerHW::GetAvailableMemory() { if (title == "MemAvailable") { std::string::size_type pos1 = line.find_last_of(" "); std::string::size_type pos2 = line.find_last_of(" ", pos1 - 1); - mem_available_in_kb = std::stol(line.substr(pos2, pos1 - pos2)); + if (pos1 != std::string::npos && pos2 != std::string::npos && line.size() > pos1) { + mem_available_in_kb = std::stol(line.substr(pos2, pos1 - pos2)); + } break; } } diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/distributed_sampler_ir.cc b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/distributed_sampler_ir.cc index a7dd98b3fab..29611013d2f 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/distributed_sampler_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/distributed_sampler_ir.cc @@ -30,7 +30,6 @@ namespace mindspore { namespace dataset { - // Constructor DistributedSamplerObj::DistributedSamplerObj(int64_t num_shards, int64_t shard_id, bool shuffle, int64_t num_samples, uint32_t seed, int64_t offset, bool even_dist) @@ -116,6 +115,5 @@ std::shared_ptr DistributedSamplerObj::SamplerCopy() { } int64_t DistributedSamplerObj::ShardId() { return shard_id_; } - } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/pk_sampler_ir.cc b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/pk_sampler_ir.cc index 6564c70246a..b1f8c3275b6 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/pk_sampler_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/pk_sampler_ir.cc @@ -30,7 +30,6 @@ namespace mindspore { namespace dataset { - // Constructor PKSamplerObj::PKSamplerObj(int64_t num_val, bool shuffle, int64_t num_samples) : num_val_(num_val), shuffle_(shuffle), num_samples_(num_samples) {} @@ -92,6 +91,5 @@ std::shared_ptr PKSamplerObj::SamplerCopy() { } return sampler; } - } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.cc b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.cc index 80ce7ba7394..125abe218ff 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.cc @@ -30,7 +30,6 @@ namespace mindspore { namespace dataset { - // Constructor PreBuiltSamplerObj::PreBuiltSamplerObj(std::shared_ptr sampler) : sp_(std::move(sampler)) {} @@ -80,6 +79,5 @@ Status PreBuiltSamplerObj::to_json(nlohmann::json *const out_json) { RETURN_IF_NOT_OK(sp_->to_json(out_json)); return Status::OK(); } - } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/random_sampler_ir.cc b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/random_sampler_ir.cc index beea3c4fce3..86828d900e0 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/random_sampler_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/random_sampler_ir.cc @@ -30,7 +30,6 @@ namespace mindspore { namespace dataset { - // Constructor RandomSamplerObj::RandomSamplerObj(bool replacement, int64_t num_samples, bool reshuffle_each_epoch) : replacement_(replacement), num_samples_(num_samples), reshuffle_each_epoch_(reshuffle_each_epoch) {} @@ -83,6 +82,5 @@ std::shared_ptr RandomSamplerObj::SamplerCopy() { } return sampler; } - } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/sequential_sampler_ir.cc b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/sequential_sampler_ir.cc index 2809ef68f2a..df4ddab65c4 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/sequential_sampler_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/sequential_sampler_ir.cc @@ -30,7 +30,6 @@ namespace mindspore { namespace dataset { - // Constructor SequentialSamplerObj::SequentialSamplerObj(int64_t start_index, int64_t num_samples) : start_index_(start_index), num_samples_(num_samples) {} @@ -86,6 +85,5 @@ std::shared_ptr SequentialSamplerObj::SamplerCopy() { } return sampler; } - } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_random_sampler_ir.cc b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_random_sampler_ir.cc index af38642f4a5..504a4862e12 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_random_sampler_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_random_sampler_ir.cc @@ -30,7 +30,6 @@ namespace mindspore { namespace dataset { - // Constructor SubsetRandomSamplerObj::SubsetRandomSamplerObj(std::vector indices, int64_t num_samples) : SubsetSamplerObj(std::move(indices), num_samples) {} @@ -72,6 +71,5 @@ std::shared_ptr SubsetRandomSamplerObj::SamplerCopy() { } return sampler; } - } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_sampler_ir.cc b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_sampler_ir.cc index aa292c8ff7d..9cde95a3d50 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_sampler_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_sampler_ir.cc @@ -30,7 +30,6 @@ namespace mindspore { namespace dataset { - // Constructor SubsetSamplerObj::SubsetSamplerObj(std::vector indices, int64_t num_samples) : indices_(std::move(indices)), num_samples_(num_samples) {} @@ -81,6 +80,5 @@ std::shared_ptr SubsetSamplerObj::SamplerCopy() { } return sampler; } - } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/weighted_random_sampler_ir.cc b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/weighted_random_sampler_ir.cc index 5b79ebadd94..58aa745f570 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/weighted_random_sampler_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/weighted_random_sampler_ir.cc @@ -21,7 +21,6 @@ namespace mindspore { namespace dataset { - // Constructor WeightedRandomSamplerObj::WeightedRandomSamplerObj(std::vector weights, int64_t num_samples, bool replacement) : weights_(std::move(weights)), num_samples_(num_samples), replacement_(replacement) {} @@ -78,6 +77,5 @@ std::shared_ptr WeightedRandomSamplerObj::SamplerCopy() { } return sampler; } - } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.cc index 25f62863113..4e9bf6986d4 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.cc @@ -23,9 +23,7 @@ namespace mindspore { namespace dataset { - namespace vision { - AffineOperation::AffineOperation(float_t degrees, const std::vector &translation, float scale, const std::vector &shear, InterpolationMode interpolation, const std::vector &fill_value) @@ -42,7 +40,8 @@ std::string AffineOperation::Name() const { return kAffineOperation; } Status AffineOperation::ValidateParams() { // Translate - if (translation_.size() != 2) { + constexpr size_t kExpectedTranslationSize = 2; + if (translation_.size() != kExpectedTranslationSize) { std::string err_msg = "Affine: translate expecting size 2, got: translation.size() = " + std::to_string(translation_.size()); MS_LOG(ERROR) << err_msg; @@ -52,7 +51,8 @@ Status AffineOperation::ValidateParams() { RETURN_IF_NOT_OK(ValidateScalar("Affine", "translate", translation_[1], {-1, 1}, false, false)); // Shear - if (shear_.size() != 2) { + constexpr size_t kExpectedShearSize = 2; + if (shear_.size() != kExpectedShearSize) { std::string err_msg = "Affine: shear_ranges expecting size 2, got: shear.size() = " + std::to_string(shear_.size()); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); @@ -80,7 +80,6 @@ Status AffineOperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_contrast_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_contrast_ir.cc index 25fb45e9852..2732a2b31c0 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_contrast_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_contrast_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // AutoContrastOperation AutoContrastOperation::AutoContrastOperation(float cutoff, std::vector ignore) : cutoff_(cutoff), ignore_(ignore) {} @@ -45,8 +42,9 @@ Status AutoContrastOperation::ValidateParams() { RETURN_STATUS_SYNTAX_ERROR(err_msg); } + constexpr uint32_t kMaxIgnoreSize = 255; for (uint32_t single_ignore : ignore_) { - if (single_ignore > 255) { + if (single_ignore > kMaxIgnoreSize) { std::string err_msg = "AutoContrast: invalid size, ignore has to be between 0 and 255, got: " + std::to_string(single_ignore); MS_LOG(ERROR) << err_msg; @@ -69,7 +67,6 @@ Status AutoContrastOperation::to_json(nlohmann::json *out_json) { return Status::OK(); } #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.cc index 2c4891bbbd2..43909fc12d4 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - BoundingBoxAugmentOperation::BoundingBoxAugmentOperation(std::shared_ptr transform, float ratio) : transform_(transform), ratio_(ratio) {} @@ -57,7 +54,6 @@ Status BoundingBoxAugmentOperation::to_json(nlohmann::json *out_json) { return Status::OK(); } #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/center_crop_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/center_crop_ir.cc index 0bfffb4f2f7..5581505d603 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/center_crop_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/center_crop_ir.cc @@ -23,9 +23,7 @@ namespace mindspore { namespace dataset { - namespace vision { - CenterCropOperation::CenterCropOperation(std::vector size) : size_(size) {} CenterCropOperation::~CenterCropOperation() = default; @@ -42,7 +40,8 @@ std::shared_ptr CenterCropOperation::Build() { int32_t crop_width = size_[0]; // User has specified crop_width. - if (size_.size() == 2) { + constexpr size_t size_two = 2; + if (size_.size() == size_two) { crop_width = size_[1]; } @@ -54,7 +53,6 @@ Status CenterCropOperation::to_json(nlohmann::json *out_json) { (*out_json)["size"] = size_; return Status::OK(); } - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.cc index 7ec531d640c..6e1a550acd1 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.cc @@ -23,9 +23,7 @@ namespace mindspore { namespace dataset { - namespace vision { - CropOperation::CropOperation(std::vector coordinates, std::vector size) : coordinates_(coordinates), size_(size) {} @@ -38,7 +36,8 @@ Status CropOperation::ValidateParams() { // we don't check the coordinates here because we don't have access to image dimensions RETURN_IF_NOT_OK(ValidateVectorSize("Crop", size_)); - if (coordinates_.size() != 2) { + constexpr size_t size_two = 2; + if (coordinates_.size() != size_two) { std::string err_msg = "Crop: coordinates must be a vector of two values"; MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); @@ -56,14 +55,14 @@ std::shared_ptr CropOperation::Build() { height = size_[0]; width = size_[0]; // User has specified crop_width. - if (size_.size() == 2) { + constexpr size_t size_two = 2; + if (size_.size() == size_two) { width = size_[1]; } std::shared_ptr tensor_op = std::make_shared(y, x, height, width); return tensor_op; } - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutmix_batch_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutmix_batch_ir.cc index 8a5aca11acb..c85967aa037 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutmix_batch_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutmix_batch_ir.cc @@ -25,9 +25,7 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID // CutMixBatchOperation CutMixBatchOperation::CutMixBatchOperation(ImageBatchFormat image_batch_format, float alpha, float prob) @@ -56,9 +54,7 @@ Status CutMixBatchOperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutout_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutout_ir.cc index 2adeec64e87..ad856766910 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutout_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutout_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - CutOutOperation::CutOutOperation(int32_t length, int32_t num_patches) : length_(length), num_patches_(num_patches) {} CutOutOperation::~CutOutOperation() = default; @@ -55,7 +52,6 @@ Status CutOutOperation::to_json(nlohmann::json *out_json) { return Status::OK(); } #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/decode_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/decode_ir.cc index e395948b109..29049ef355b 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/decode_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/decode_ir.cc @@ -23,9 +23,7 @@ namespace mindspore { namespace dataset { - namespace vision { - // DecodeOperation DecodeOperation::DecodeOperation(bool rgb) : rgb_(rgb) {} @@ -41,7 +39,6 @@ Status DecodeOperation::to_json(nlohmann::json *out_json) { (*out_json)["rgb"] = rgb_; return Status::OK(); } - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/equalize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/equalize_ir.cc index 05df6d4bb61..2db66759bc7 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/equalize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/equalize_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // EqualizeOperation EqualizeOperation::~EqualizeOperation() = default; @@ -38,9 +35,7 @@ std::string EqualizeOperation::Name() const { return kEqualizeOperation; } Status EqualizeOperation::ValidateParams() { return Status::OK(); } std::shared_ptr EqualizeOperation::Build() { return std::make_shared(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/hwc_to_chw_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/hwc_to_chw_ir.cc index 3907536927d..fafe56045fe 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/hwc_to_chw_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/hwc_to_chw_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // HwcToChwOperation HwcToChwOperation::~HwcToChwOperation() = default; @@ -39,7 +36,6 @@ Status HwcToChwOperation::ValidateParams() { return Status::OK(); } std::shared_ptr HwcToChwOperation::Build() { return std::make_shared(); } #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/invert_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/invert_ir.cc index e5ed71c6793..80ff524aacf 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/invert_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/invert_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // InvertOperation InvertOperation::~InvertOperation() = default; @@ -38,9 +35,7 @@ std::string InvertOperation::Name() const { return kInvertOperation; } Status InvertOperation::ValidateParams() { return Status::OK(); } std::shared_ptr InvertOperation::Build() { return std::make_shared(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/mixup_batch_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/mixup_batch_ir.cc index 4ee9288e6aa..650c17656c9 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/mixup_batch_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/mixup_batch_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // MixUpOperation MixUpBatchOperation::MixUpBatchOperation(float alpha) : alpha_(alpha) {} @@ -48,9 +45,7 @@ Status MixUpBatchOperation::to_json(nlohmann::json *out_json) { (*out_json)["alpha"] = alpha_; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.cc index 5519e6058ae..2a770a0b125 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.cc @@ -23,9 +23,7 @@ namespace mindspore { namespace dataset { - namespace vision { - // NormalizeOperation NormalizeOperation::NormalizeOperation(std::vector mean, std::vector std) : mean_(mean), std_(std) {} @@ -47,7 +45,6 @@ Status NormalizeOperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_pad_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_pad_ir.cc index a55a7c7380e..4ed2de49fa9 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_pad_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_pad_ir.cc @@ -25,9 +25,7 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID // NormalizePadOperation NormalizePadOperation::NormalizePadOperation(const std::vector &mean, const std::vector &std, @@ -49,7 +47,11 @@ Status NormalizePadOperation::ValidateParams() { } std::shared_ptr NormalizePadOperation::Build() { - return std::make_shared(mean_[0], mean_[1], mean_[2], std_[0], std_[1], std_[2], dtype_); + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t dimension_two = 2; + return std::make_shared(mean_[dimension_zero], mean_[dimension_one], mean_[dimension_two], + std_[dimension_zero], std_[dimension_one], std_[dimension_two], dtype_); } Status NormalizePadOperation::to_json(nlohmann::json *out_json) { @@ -61,7 +63,6 @@ Status NormalizePadOperation::to_json(nlohmann::json *out_json) { return Status::OK(); } #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.cc index b7dd3208667..776e237bbfe 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // PadOperation PadOperation::PadOperation(std::vector padding, std::vector fill_value, BorderType padding_mode) : padding_(padding), fill_value_(fill_value), padding_mode_(padding_mode) {} @@ -47,36 +44,43 @@ Status PadOperation::ValidateParams() { } std::shared_ptr PadOperation::Build() { + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t dimension_two = 2; + constexpr size_t dimension_three = 3; + constexpr size_t size_one = 1; + constexpr size_t size_two = 2; + constexpr size_t size_three = 3; int32_t pad_top, pad_bottom, pad_left, pad_right; switch (padding_.size()) { - case 1: - pad_left = padding_[0]; - pad_top = padding_[0]; - pad_right = padding_[0]; - pad_bottom = padding_[0]; + case size_one: + pad_left = padding_[dimension_zero]; + pad_top = padding_[dimension_zero]; + pad_right = padding_[dimension_zero]; + pad_bottom = padding_[dimension_zero]; break; - case 2: - pad_left = padding_[0]; - pad_top = padding_[0]; - pad_right = padding_[1]; - pad_bottom = padding_[1]; + case size_two: + pad_left = padding_[dimension_zero]; + pad_top = padding_[dimension_zero]; + pad_right = padding_[dimension_one]; + pad_bottom = padding_[dimension_one]; break; default: - pad_left = padding_[0]; - pad_top = padding_[1]; - pad_right = padding_[2]; - pad_bottom = padding_[3]; + pad_left = padding_[dimension_zero]; + pad_top = padding_[dimension_one]; + pad_right = padding_[dimension_two]; + pad_bottom = padding_[dimension_three]; } uint8_t fill_r, fill_g, fill_b; - fill_r = fill_value_[0]; - fill_g = fill_value_[0]; - fill_b = fill_value_[0]; + fill_r = fill_value_[dimension_zero]; + fill_g = fill_value_[dimension_zero]; + fill_b = fill_value_[dimension_zero]; - if (fill_value_.size() == 3) { - fill_r = fill_value_[0]; - fill_g = fill_value_[1]; - fill_b = fill_value_[2]; + if (fill_value_.size() == size_three) { + fill_r = fill_value_[dimension_zero]; + fill_g = fill_value_[dimension_one]; + fill_b = fill_value_[dimension_two]; } std::shared_ptr tensor_op = @@ -93,7 +97,6 @@ Status PadOperation::to_json(nlohmann::json *out_json) { return Status::OK(); } #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_affine_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_affine_ir.cc index 8b161829781..aa2fd1fbdbf 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_affine_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_affine_ir.cc @@ -23,9 +23,16 @@ namespace mindspore { namespace dataset { - namespace vision { +constexpr size_t dimension_zero = 0; +constexpr size_t dimension_one = 1; +constexpr size_t dimension_two = 2; +constexpr size_t dimension_three = 3; +constexpr size_t size_two = 2; +constexpr size_t size_three = 3; +constexpr size_t size_four = 4; + // RandomAffineOperation RandomAffineOperation::RandomAffineOperation(const std::vector °rees, const std::vector &translate_range, @@ -47,62 +54,69 @@ std::string RandomAffineOperation::Name() const { return kRandomAffineOperation; Status RandomAffineOperation::ValidateParams() { // Degrees - if (degrees_.size() != 2) { + if (degrees_.size() != size_two) { std::string err_msg = "RandomAffine: degrees expecting size 2, got: degrees.size() = " + std::to_string(degrees_.size()); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } - if (degrees_[0] > degrees_[1]) { - std::string err_msg = - "RandomAffine: minimum of degrees range is greater than maximum: min = " + std::to_string(degrees_[0]) + - ", max = " + std::to_string(degrees_[1]); + if (degrees_[dimension_zero] > degrees_[dimension_one]) { + std::string err_msg = "RandomAffine: minimum of degrees range is greater than maximum: min = " + + std::to_string(degrees_[dimension_zero]) + + ", max = " + std::to_string(degrees_[dimension_one]); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } // Translate - if (translate_range_.size() != 2 && translate_range_.size() != 4) { + if (translate_range_.size() != size_two && translate_range_.size() != size_four) { std::string err_msg = "RandomAffine: translate_range expecting size 2 or 4, got: translate_range.size() = " + std::to_string(translate_range_.size()); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } - if (translate_range_[0] > translate_range_[1]) { + if (translate_range_[dimension_zero] > translate_range_[dimension_one]) { std::string err_msg = "RandomAffine: minimum of translate range on x is greater than maximum: min = " + - std::to_string(translate_range_[0]) + ", max = " + std::to_string(translate_range_[1]); + std::to_string(translate_range_[dimension_zero]) + + ", max = " + std::to_string(translate_range_[dimension_one]); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } - RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[0], {-1, 1}, false, false)); - RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[1], {-1, 1}, false, false)); - if (translate_range_.size() == 4) { - if (translate_range_[2] > translate_range_[3]) { + RETURN_IF_NOT_OK( + ValidateScalar("RandomAffine", "translate", translate_range_[dimension_zero], {-1, 1}, false, false)); + RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[dimension_one], {-1, 1}, false, false)); + if (translate_range_.size() == size_four) { + if (translate_range_[dimension_two] > translate_range_[dimension_three]) { std::string err_msg = "RandomAffine: minimum of translate range on y is greater than maximum: min = " + - std::to_string(translate_range_[2]) + ", max = " + std::to_string(translate_range_[3]); + std::to_string(translate_range_[dimension_two]) + + ", max = " + std::to_string(translate_range_[dimension_three]); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } - RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[2], {-1, 1}, false, false)); - RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[3], {-1, 1}, false, false)); + RETURN_IF_NOT_OK( + ValidateScalar("RandomAffine", "translate", translate_range_[dimension_two], {-1, 1}, false, false)); + RETURN_IF_NOT_OK( + ValidateScalar("RandomAffine", "translate", translate_range_[dimension_three], {-1, 1}, false, false)); } // Scale RETURN_IF_NOT_OK(ValidateVectorScale("RandomAffine", scale_range_)); // Shear - if (shear_ranges_.size() != 2 && shear_ranges_.size() != 4) { + if (shear_ranges_.size() != size_two && shear_ranges_.size() != size_four) { std::string err_msg = "RandomAffine: shear_ranges expecting size 2 or 4, got: shear_ranges.size() = " + std::to_string(shear_ranges_.size()); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } - if (shear_ranges_[0] > shear_ranges_[1]) { + if (shear_ranges_[dimension_zero] > shear_ranges_[dimension_one]) { std::string err_msg = "RandomAffine: minimum of horizontal shear range is greater than maximum: min = " + - std::to_string(shear_ranges_[0]) + ", max = " + std::to_string(shear_ranges_[1]); + std::to_string(shear_ranges_[dimension_zero]) + + ", max = " + std::to_string(shear_ranges_[dimension_one]); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } - if (shear_ranges_.size() == 4 && shear_ranges_[2] > shear_ranges_[3]) { + if (shear_ranges_.size() == size_four && shear_ranges_[dimension_two] > shear_ranges_[dimension_three]) { std::string err_msg = "RandomAffine: minimum of vertical shear range is greater than maximum: min = " + - std::to_string(shear_ranges_[2]) + ", max = " + std::to_string(scale_range_[3]); + std::to_string(shear_ranges_[dimension_two]) + + ", max = " + std::to_string(scale_range_[dimension_three]); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } @@ -112,16 +126,17 @@ Status RandomAffineOperation::ValidateParams() { } std::shared_ptr RandomAffineOperation::Build() { - if (shear_ranges_.size() == 2) { - shear_ranges_.resize(4); + if (shear_ranges_.size() == size_two) { + shear_ranges_.resize(size_four); } - if (translate_range_.size() == 2) { - translate_range_.resize(4); + if (translate_range_.size() == size_two) { + translate_range_.resize(size_four); } - std::vector fill_value = {fill_value_[0], fill_value_[0], fill_value_[0]}; - if (fill_value_.size() == 3) { - fill_value[1] = fill_value_[1]; - fill_value[2] = fill_value_[2]; + std::vector fill_value = {fill_value_[dimension_zero], fill_value_[dimension_zero], + fill_value_[dimension_zero]}; + if (fill_value_.size() == size_three) { + fill_value[dimension_one] = fill_value_[dimension_one]; + fill_value[dimension_two] = fill_value_[dimension_two]; } auto tensor_op = std::make_shared(degrees_, translate_range_, scale_range_, shear_ranges_, @@ -140,7 +155,6 @@ Status RandomAffineOperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_adjust_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_adjust_ir.cc index b68eadcf5b6..2f10c3c7f8a 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_adjust_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_adjust_ir.cc @@ -25,11 +25,13 @@ namespace mindspore { namespace dataset { - namespace vision { -#ifndef ENABLE_ANDROID +constexpr size_t dimension_zero = 0; +constexpr size_t dimension_one = 1; +constexpr size_t size_two = 2; +#ifndef ENABLE_ANDROID // RandomColorAdjustOperation. RandomColorAdjustOperation::RandomColorAdjustOperation(std::vector brightness, std::vector contrast, std::vector saturation, std::vector hue) @@ -56,25 +58,25 @@ Status RandomColorAdjustOperation::ValidateParams() { std::shared_ptr RandomColorAdjustOperation::Build() { float brightness_lb, brightness_ub, contrast_lb, contrast_ub, saturation_lb, saturation_ub, hue_lb, hue_ub; - brightness_lb = brightness_[0]; - brightness_ub = brightness_[0]; + brightness_lb = brightness_[dimension_zero]; + brightness_ub = brightness_[dimension_zero]; - if (brightness_.size() == 2) brightness_ub = brightness_[1]; + if (brightness_.size() == size_two) brightness_ub = brightness_[dimension_one]; - contrast_lb = contrast_[0]; - contrast_ub = contrast_[0]; + contrast_lb = contrast_[dimension_zero]; + contrast_ub = contrast_[dimension_zero]; - if (contrast_.size() == 2) contrast_ub = contrast_[1]; + if (contrast_.size() == size_two) contrast_ub = contrast_[dimension_one]; - saturation_lb = saturation_[0]; - saturation_ub = saturation_[0]; + saturation_lb = saturation_[dimension_zero]; + saturation_ub = saturation_[dimension_zero]; - if (saturation_.size() == 2) saturation_ub = saturation_[1]; + if (saturation_.size() == size_two) saturation_ub = saturation_[dimension_one]; - hue_lb = hue_[0]; - hue_ub = hue_[0]; + hue_lb = hue_[dimension_zero]; + hue_ub = hue_[dimension_zero]; - if (hue_.size() == 2) hue_ub = hue_[1]; + if (hue_.size() == size_two) hue_ub = hue_[dimension_one]; std::shared_ptr tensor_op = std::make_shared( brightness_lb, brightness_ub, contrast_lb, contrast_ub, saturation_lb, saturation_ub, hue_lb, hue_ub); @@ -91,7 +93,6 @@ Status RandomColorAdjustOperation::to_json(nlohmann::json *out_json) { return Status::OK(); } #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_ir.cc index 49a26e162eb..bc74c346103 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_ir.cc @@ -26,9 +26,7 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID // RandomColorOperation. RandomColorOperation::RandomColorOperation(float t_lb, float t_ub) : t_lb_(t_lb), t_ub_(t_ub) { random_op_ = true; } @@ -64,9 +62,7 @@ Status RandomColorOperation::to_json(nlohmann::json *out_json) { (*out_json)["degrees"] = std::vector{t_lb_, t_ub_}; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.cc index bdc7d9b2b54..5a0262ec2cf 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.cc @@ -25,10 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { #ifndef ENABLE_ANDROID - // RandomCropDecodeResizeOperation RandomCropDecodeResizeOperation::RandomCropDecodeResizeOperation(std::vector size, std::vector scale, std::vector ratio, @@ -40,19 +38,23 @@ RandomCropDecodeResizeOperation::~RandomCropDecodeResizeOperation() = default; std::string RandomCropDecodeResizeOperation::Name() const { return kRandomCropDecodeResizeOperation; } std::shared_ptr RandomCropDecodeResizeOperation::Build() { - int32_t crop_height = size_[0]; - int32_t crop_width = size_[0]; + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t size_two = 2; + + int32_t crop_height = size_[dimension_zero]; + int32_t crop_width = size_[dimension_zero]; // User has specified the crop_width value. - if (size_.size() == 2) { - crop_width = size_[1]; + if (size_.size() == size_two) { + crop_width = size_[dimension_one]; } - float scale_lower_bound = scale_[0]; - float scale_upper_bound = scale_[1]; + float scale_lower_bound = scale_[dimension_zero]; + float scale_upper_bound = scale_[dimension_one]; - float aspect_lower_bound = ratio_[0]; - float aspect_upper_bound = ratio_[1]; + float aspect_lower_bound = ratio_[dimension_zero]; + float aspect_upper_bound = ratio_[dimension_one]; auto tensor_op = std::make_shared(crop_height, crop_width, scale_lower_bound, scale_upper_bound, @@ -73,9 +75,7 @@ Status RandomCropDecodeResizeOperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_ir.cc index c6604ea69ef..1b48b4d2e92 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_ir.cc @@ -25,10 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { #ifndef ENABLE_ANDROID - // RandomCropOperation RandomCropOperation::RandomCropOperation(std::vector size, std::vector padding, bool pad_if_needed, std::vector fill_value, BorderType padding_mode) @@ -56,44 +54,52 @@ Status RandomCropOperation::ValidateParams() { } std::shared_ptr RandomCropOperation::Build() { - int32_t crop_height = size_[0]; - int32_t crop_width = size_[0]; + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t dimension_two = 2; + constexpr size_t dimension_three = 3; + constexpr size_t size_one = 1; + constexpr size_t size_two = 2; + constexpr size_t size_three = 3; + + int32_t crop_height = size_[dimension_zero]; + int32_t crop_width = size_[dimension_zero]; // User has specified the crop_width value. - if (size_.size() == 2) { - crop_width = size_[1]; + if (size_.size() == size_two) { + crop_width = size_[dimension_one]; } int32_t pad_top, pad_bottom, pad_left, pad_right; switch (padding_.size()) { - case 1: - pad_left = padding_[0]; - pad_top = padding_[0]; - pad_right = padding_[0]; - pad_bottom = padding_[0]; + case size_one: + pad_left = padding_[dimension_zero]; + pad_top = padding_[dimension_zero]; + pad_right = padding_[dimension_zero]; + pad_bottom = padding_[dimension_zero]; break; - case 2: - pad_left = padding_[0]; - pad_top = padding_[0]; - pad_right = padding_[1]; - pad_bottom = padding_[1]; + case size_two: + pad_left = padding_[dimension_zero]; + pad_top = padding_[dimension_zero]; + pad_right = padding_[dimension_one]; + pad_bottom = padding_[dimension_one]; break; default: - pad_left = padding_[0]; - pad_top = padding_[1]; - pad_right = padding_[2]; - pad_bottom = padding_[3]; + pad_left = padding_[dimension_zero]; + pad_top = padding_[dimension_one]; + pad_right = padding_[dimension_two]; + pad_bottom = padding_[dimension_three]; } uint8_t fill_r, fill_g, fill_b; - fill_r = fill_value_[0]; - fill_g = fill_value_[0]; - fill_b = fill_value_[0]; + fill_r = fill_value_[dimension_zero]; + fill_g = fill_value_[dimension_zero]; + fill_b = fill_value_[dimension_zero]; - if (fill_value_.size() == 3) { - fill_r = fill_value_[0]; - fill_g = fill_value_[1]; - fill_b = fill_value_[2]; + if (fill_value_.size() == size_three) { + fill_r = fill_value_[dimension_zero]; + fill_g = fill_value_[dimension_one]; + fill_b = fill_value_[dimension_two]; } auto tensor_op = std::make_shared(crop_height, crop_width, pad_top, pad_bottom, pad_left, pad_right, @@ -111,9 +117,7 @@ Status RandomCropOperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_with_bbox_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_with_bbox_ir.cc index 651f50c2d1c..aac0c4037e2 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_with_bbox_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_with_bbox_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // RandomCropWithBBoxOperation RandomCropWithBBoxOperation::RandomCropWithBBoxOperation(std::vector size, std::vector padding, bool pad_if_needed, std::vector fill_value, @@ -56,44 +53,52 @@ Status RandomCropWithBBoxOperation::ValidateParams() { } std::shared_ptr RandomCropWithBBoxOperation::Build() { - int32_t crop_height = size_[0]; - int32_t crop_width = size_[0]; + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t dimension_two = 2; + constexpr size_t dimension_three = 3; + constexpr size_t size_one = 1; + constexpr size_t size_two = 2; + constexpr size_t size_three = 3; + + int32_t crop_height = size_[dimension_zero]; + int32_t crop_width = size_[dimension_zero]; // User has specified the crop_width value. - if (size_.size() == 2) { - crop_width = size_[1]; + if (size_.size() == size_two) { + crop_width = size_[dimension_one]; } int32_t pad_top, pad_bottom, pad_left, pad_right; switch (padding_.size()) { - case 1: - pad_left = padding_[0]; - pad_top = padding_[0]; - pad_right = padding_[0]; - pad_bottom = padding_[0]; + case size_one: + pad_left = padding_[dimension_zero]; + pad_top = padding_[dimension_zero]; + pad_right = padding_[dimension_zero]; + pad_bottom = padding_[dimension_zero]; break; - case 2: - pad_left = padding_[0]; - pad_top = padding_[0]; - pad_right = padding_[1]; - pad_bottom = padding_[1]; + case size_two: + pad_left = padding_[dimension_zero]; + pad_top = padding_[dimension_zero]; + pad_right = padding_[dimension_one]; + pad_bottom = padding_[dimension_one]; break; default: - pad_left = padding_[0]; - pad_top = padding_[1]; - pad_right = padding_[2]; - pad_bottom = padding_[3]; + pad_left = padding_[dimension_zero]; + pad_top = padding_[dimension_one]; + pad_right = padding_[dimension_two]; + pad_bottom = padding_[dimension_three]; } uint8_t fill_r, fill_g, fill_b; - fill_r = fill_value_[0]; - fill_g = fill_value_[0]; - fill_b = fill_value_[0]; + fill_r = fill_value_[dimension_zero]; + fill_g = fill_value_[dimension_zero]; + fill_b = fill_value_[dimension_zero]; - if (fill_value_.size() == 3) { - fill_r = fill_value_[0]; - fill_g = fill_value_[1]; - fill_b = fill_value_[2]; + if (fill_value_.size() == size_three) { + fill_r = fill_value_[dimension_zero]; + fill_g = fill_value_[dimension_one]; + fill_b = fill_value_[dimension_two]; } auto tensor_op = @@ -112,9 +117,7 @@ Status RandomCropWithBBoxOperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.cc index 4a14217b0a0..dfbffa155da 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // RandomHorizontalFlipOperation RandomHorizontalFlipOperation::RandomHorizontalFlipOperation(float prob) : TensorOperation(true), probability_(prob) {} @@ -51,9 +48,7 @@ Status RandomHorizontalFlipOperation::to_json(nlohmann::json *out_json) { (*out_json)["prob"] = probability_; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.cc index b5723ad2a75..dcf9cc8ae67 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // RandomHorizontalFlipWithBBoxOperation RandomHorizontalFlipWithBBoxOperation::RandomHorizontalFlipWithBBoxOperation(float probability) : TensorOperation(true), probability_(probability) {} @@ -53,9 +50,7 @@ Status RandomHorizontalFlipWithBBoxOperation::to_json(nlohmann::json *out_json) (*out_json)["prob"] = probability_; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_posterize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_posterize_ir.cc index 5b5681b6d91..37f2f0a8ff6 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_posterize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_posterize_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // RandomPosterizeOperation RandomPosterizeOperation::RandomPosterizeOperation(const std::vector &bit_range) : TensorOperation(true), bit_range_(bit_range) {} @@ -39,25 +36,34 @@ RandomPosterizeOperation::~RandomPosterizeOperation() = default; std::string RandomPosterizeOperation::Name() const { return kRandomPosterizeOperation; } Status RandomPosterizeOperation::ValidateParams() { - if (bit_range_.size() != 2) { + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t size_two = 2; + constexpr uint8_t kMinimumBitValue = 1; + constexpr uint8_t kMaximumBitValue = 8; + + if (bit_range_.size() != size_two) { std::string err_msg = "RandomPosterize: bit_range needs to be of size 2 but is of size: " + std::to_string(bit_range_.size()); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } - if (bit_range_[0] < 1 || bit_range_[0] > 8) { - std::string err_msg = "RandomPosterize: min_bit value is out of range [1-8]: " + std::to_string(bit_range_[0]); + if (bit_range_[dimension_zero] < kMinimumBitValue || bit_range_[dimension_zero] > kMaximumBitValue) { + std::string err_msg = + "RandomPosterize: min_bit value is out of range [1-8]: " + std::to_string(bit_range_[dimension_zero]); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } - if (bit_range_[1] < 1 || bit_range_[1] > 8) { - std::string err_msg = "RandomPosterize: max_bit value is out of range [1-8]: " + std::to_string(bit_range_[1]); + if (bit_range_[dimension_one] < kMinimumBitValue || bit_range_[dimension_one] > kMaximumBitValue) { + std::string err_msg = + "RandomPosterize: max_bit value is out of range [1-8]: " + std::to_string(bit_range_[dimension_one]); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } - if (bit_range_[1] < bit_range_[0]) { - std::string err_msg = "RandomPosterize: max_bit value is less than min_bit: max =" + std::to_string(bit_range_[1]) + - ", min = " + std::to_string(bit_range_[0]); + if (bit_range_[dimension_one] < bit_range_[dimension_zero]) { + std::string err_msg = + "RandomPosterize: max_bit value is less than min_bit: max =" + std::to_string(bit_range_[dimension_one]) + + ", min = " + std::to_string(bit_range_[dimension_zero]); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } @@ -73,9 +79,7 @@ Status RandomPosterizeOperation::to_json(nlohmann::json *out_json) { (*out_json)["bits"] = bit_range_; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_ir.cc index 99c17305e83..1179b5ba8ee 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // RandomResizeOperation RandomResizeOperation::RandomResizeOperation(std::vector size) : TensorOperation(true), size_(size) {} @@ -43,14 +40,18 @@ Status RandomResizeOperation::ValidateParams() { } std::shared_ptr RandomResizeOperation::Build() { + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t size_two = 2; + // If size is a single value, the smaller edge of the image will be // resized to this value with the same image aspect ratio. - int32_t height = size_[0]; + int32_t height = size_[dimension_zero]; int32_t width = 0; // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; + if (size_.size() == size_two) { + width = size_[dimension_one]; } std::shared_ptr tensor_op = std::make_shared(height, width); @@ -61,9 +62,7 @@ Status RandomResizeOperation::to_json(nlohmann::json *out_json) { (*out_json)["size"] = size_; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.cc index 5e63855dc0e..deccaccb861 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // RandomResizeWithBBoxOperation RandomResizeWithBBoxOperation::RandomResizeWithBBoxOperation(std::vector size) : TensorOperation(true), size_(size) {} @@ -44,14 +41,18 @@ Status RandomResizeWithBBoxOperation::ValidateParams() { } std::shared_ptr RandomResizeWithBBoxOperation::Build() { + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t size_two = 2; + // If size is a single value, the smaller edge of the image will be // resized to this value with the same image aspect ratio. - int32_t height = size_[0]; + int32_t height = size_[dimension_zero]; int32_t width = 0; // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; + if (size_.size() == size_two) { + width = size_[dimension_one]; } std::shared_ptr tensor_op = std::make_shared(height, width); @@ -62,9 +63,7 @@ Status RandomResizeWithBBoxOperation::to_json(nlohmann::json *out_json) { (*out_json)["size"] = size_; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_ir.cc index 998ea78b208..bea62f9285a 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_ir.cc @@ -25,7 +25,6 @@ namespace mindspore { namespace dataset { - namespace vision { #ifndef ENABLE_ANDROID RandomResizedCropOperation::RandomResizedCropOperation(const RandomResizedCropOperation &) = default; @@ -63,14 +62,19 @@ Status RandomResizedCropOperation::ValidateParams() { } std::shared_ptr RandomResizedCropOperation::Build() { - int32_t height = size_[0]; - int32_t width = size_[0]; + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t size_two = 2; + + int32_t height = size_[dimension_zero]; + int32_t width = size_[dimension_zero]; // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; + if (size_.size() == size_two) { + width = size_[dimension_one]; } std::shared_ptr tensor_op = std::make_shared( - height, width, scale_[0], scale_[1], ratio_[0], ratio_[1], interpolation_, max_attempts_); + height, width, scale_[dimension_zero], scale_[dimension_one], ratio_[dimension_zero], ratio_[dimension_one], + interpolation_, max_attempts_); return tensor_op; } @@ -84,9 +88,7 @@ Status RandomResizedCropOperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_with_bbox_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_with_bbox_ir.cc index 94a1b050f4a..79c273667d0 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_with_bbox_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_with_bbox_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // RandomResizedCropWithBBoxOperation RandomResizedCropWithBBoxOperation::RandomResizedCropWithBBoxOperation(std::vector size, std::vector scale, @@ -60,14 +57,19 @@ Status RandomResizedCropWithBBoxOperation::ValidateParams() { } std::shared_ptr RandomResizedCropWithBBoxOperation::Build() { - int32_t height = size_[0]; - int32_t width = size_[0]; + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t size_two = 2; + + int32_t height = size_[dimension_zero]; + int32_t width = size_[dimension_zero]; // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; + if (size_.size() == size_two) { + width = size_[dimension_one]; } std::shared_ptr tensor_op = std::make_shared( - height, width, scale_[0], scale_[1], ratio_[0], ratio_[1], interpolation_, max_attempts_); + height, width, scale_[dimension_zero], scale_[dimension_one], ratio_[dimension_zero], ratio_[dimension_one], + interpolation_, max_attempts_); return tensor_op; } @@ -81,9 +83,7 @@ Status RandomResizedCropWithBBoxOperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_rotation_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_rotation_ir.cc index cd3ca25465f..e35bb249923 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_rotation_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_rotation_ir.cc @@ -25,9 +25,14 @@ namespace mindspore { namespace dataset { - namespace vision { #ifndef ENABLE_ANDROID +constexpr size_t dimension_zero = 0; +constexpr size_t dimension_one = 1; +constexpr size_t dimension_two = 2; +constexpr size_t size_one = 1; +constexpr size_t size_two = 2; +constexpr size_t size_three = 3; // Function to create RandomRotationOperation. RandomRotationOperation::RandomRotationOperation(std::vector degrees, InterpolationMode resample, bool expand, @@ -45,26 +50,27 @@ std::string RandomRotationOperation::Name() const { return kRandomRotationOperat Status RandomRotationOperation::ValidateParams() { // degrees - if (degrees_.size() != 2 && degrees_.size() != 1) { + if (degrees_.size() != size_two && degrees_.size() != size_one) { std::string err_msg = "RandomRotation: degrees must be a vector of one or two values, got: " + std::to_string(degrees_.size()); MS_LOG(ERROR) << "RandomRotation: degrees must be a vector of one or two values, got: " << degrees_; RETURN_STATUS_SYNTAX_ERROR(err_msg); } - if ((degrees_.size() == 2) && (degrees_[1] < degrees_[0])) { + if ((degrees_.size() == size_two) && (degrees_[dimension_one] < degrees_[dimension_zero])) { std::string err_msg = "RandomRotation: degrees must be in the format of (min, max), got: (" + - std::to_string(degrees_[0]) + ", " + std::to_string(degrees_[1]) + ")"; + std::to_string(degrees_[dimension_zero]) + ", " + std::to_string(degrees_[dimension_one]) + + ")"; MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); - } else if ((degrees_.size() == 1) && (degrees_[0] < 0)) { + } else if ((degrees_.size() == size_one) && (degrees_[dimension_zero] < 0)) { std::string err_msg = "RandomRotation: if degrees only has one value, it must be greater than or equal to 0, got: " + - std::to_string(degrees_[0]); + std::to_string(degrees_[dimension_zero]); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } // center - if (center_.size() != 0 && center_.size() != 2) { + if (center_.size() != 0 && center_.size() != size_two) { std::string err_msg = "RandomRotation: center must be a vector of two values or empty, got: " + std::to_string(center_.size()); MS_LOG(ERROR) << err_msg; @@ -77,23 +83,23 @@ Status RandomRotationOperation::ValidateParams() { std::shared_ptr RandomRotationOperation::Build() { float start_degree, end_degree; - if (degrees_.size() == 1) { - start_degree = -degrees_[0]; - end_degree = degrees_[0]; - } else if (degrees_.size() == 2) { - start_degree = degrees_[0]; - end_degree = degrees_[1]; + if (degrees_.size() == size_one) { + start_degree = -degrees_[dimension_zero]; + end_degree = degrees_[dimension_zero]; + } else if (degrees_.size() == size_two) { + start_degree = degrees_[dimension_zero]; + end_degree = degrees_[dimension_one]; } uint8_t fill_r, fill_g, fill_b; - fill_r = fill_value_[0]; - fill_g = fill_value_[0]; - fill_b = fill_value_[0]; + fill_r = fill_value_[dimension_zero]; + fill_g = fill_value_[dimension_zero]; + fill_b = fill_value_[dimension_zero]; - if (fill_value_.size() == 3) { - fill_r = fill_value_[0]; - fill_g = fill_value_[1]; - fill_b = fill_value_[2]; + if (fill_value_.size() == size_three) { + fill_r = fill_value_[dimension_zero]; + fill_g = fill_value_[dimension_one]; + fill_b = fill_value_[dimension_two]; } std::shared_ptr tensor_op = std::make_shared( @@ -111,9 +117,7 @@ Status RandomRotationOperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_select_subpolicy_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_select_subpolicy_ir.cc index f3ebb8784ea..d230f3e3982 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_select_subpolicy_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_select_subpolicy_ir.cc @@ -25,10 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { #ifndef ENABLE_ANDROID - // RandomSelectSubpolicyOperation. RandomSelectSubpolicyOperation::RandomSelectSubpolicyOperation( std::vector, double>>> policy) @@ -102,9 +100,7 @@ Status RandomSelectSubpolicyOperation::to_json(nlohmann::json *out_json) { (*out_json)["policy"] = policy_tensor_ops; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_sharpness_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_sharpness_ir.cc index 57564b69448..b547d4b50fa 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_sharpness_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_sharpness_ir.cc @@ -25,10 +25,11 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID +constexpr size_t dimension_zero = 0; +constexpr size_t dimension_one = 1; +constexpr size_t size_two = 2; // Function to create RandomSharpness. RandomSharpnessOperation::RandomSharpnessOperation(std::vector degrees) @@ -39,13 +40,13 @@ RandomSharpnessOperation::~RandomSharpnessOperation() = default; std::string RandomSharpnessOperation::Name() const { return kRandomSharpnessOperation; } Status RandomSharpnessOperation::ValidateParams() { - if (degrees_.size() != 2 || degrees_[0] < 0 || degrees_[1] < 0) { + if (degrees_.size() != size_two || degrees_[dimension_zero] < 0 || degrees_[dimension_one] < 0) { std::string err_msg = "RandomSharpness: degrees must be a vector of two values and greater than or equal to 0."; MS_LOG(ERROR) << "RandomSharpness: degrees must be a vector of two values and greater than or equal to 0, got: " << degrees_; RETURN_STATUS_SYNTAX_ERROR(err_msg); } - if (degrees_[1] < degrees_[0]) { + if (degrees_[dimension_one] < degrees_[dimension_zero]) { std::string err_msg = "RandomSharpness: degrees must be in the format of (min, max)."; MS_LOG(ERROR) << "RandomSharpness: degrees must be in the format of (min, max), got: " << degrees_; RETURN_STATUS_SYNTAX_ERROR(err_msg); @@ -54,7 +55,8 @@ Status RandomSharpnessOperation::ValidateParams() { } std::shared_ptr RandomSharpnessOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(degrees_[0], degrees_[1]); + std::shared_ptr tensor_op = + std::make_shared(degrees_[dimension_zero], degrees_[dimension_one]); return tensor_op; } @@ -62,9 +64,7 @@ Status RandomSharpnessOperation::to_json(nlohmann::json *out_json) { (*out_json)["degrees"] = degrees_; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_solarize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_solarize_ir.cc index c46868fc30c..f46418f196f 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_solarize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_solarize_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // RandomSolarizeOperation. RandomSolarizeOperation::RandomSolarizeOperation(std::vector threshold) : TensorOperation(true), threshold_(threshold) {} @@ -39,21 +36,26 @@ RandomSolarizeOperation::~RandomSolarizeOperation() = default; std::string RandomSolarizeOperation::Name() const { return kRandomSolarizeOperation; } Status RandomSolarizeOperation::ValidateParams() { - if (threshold_.size() != 2) { + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t size_two = 2; + constexpr uint8_t kThresholdMax = 255; + + if (threshold_.size() != size_two) { std::string err_msg = "RandomSolarize: threshold must be a vector of two values, got: " + std::to_string(threshold_.size()); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } for (int32_t i = 0; i < threshold_.size(); ++i) { - if (threshold_[i] < 0 || threshold_[i] > 255) { + if (threshold_[i] < 0 || threshold_[i] > kThresholdMax) { std::string err_msg = "RandomSolarize: threshold has to be between 0 and 255, got:" + std::to_string(threshold_[i]); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } } - if (threshold_[0] > threshold_[1]) { + if (threshold_[dimension_zero] > threshold_[dimension_one]) { std::string err_msg = "RandomSolarize: threshold must be passed in a (min, max) format"; MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); @@ -70,9 +72,7 @@ Status RandomSolarizeOperation::to_json(nlohmann::json *out_json) { (*out_json)["threshold"] = threshold_; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_ir.cc index 9901de8b750..417dfba57c8 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // RandomVerticalFlipOperation RandomVerticalFlipOperation::RandomVerticalFlipOperation(float prob) : TensorOperation(true), probability_(prob) {} @@ -52,9 +49,7 @@ Status RandomVerticalFlipOperation::to_json(nlohmann::json *out_json) { (*out_json)["prob"] = probability_; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_with_bbox_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_with_bbox_ir.cc index 0eb91497892..5b07c4f55fa 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_with_bbox_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_with_bbox_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // RandomVerticalFlipWithBBoxOperation RandomVerticalFlipWithBBoxOperation::RandomVerticalFlipWithBBoxOperation(float prob) : TensorOperation(true), probability_(prob) {} @@ -54,9 +51,7 @@ Status RandomVerticalFlipWithBBoxOperation::to_json(nlohmann::json *out_json) { (*out_json)["prob"] = probability_; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.cc index 9d173f2b698..785d8f3932f 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // RescaleOperation RescaleOperation::RescaleOperation(float rescale, float shift) : rescale_(rescale), shift_(shift) {} @@ -58,9 +55,7 @@ Status RescaleOperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.cc index 550a198dcd5..4cb1e5f8be1 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.cc @@ -23,9 +23,7 @@ namespace mindspore { namespace dataset { - namespace vision { - // ResizeOperation ResizeOperation::ResizeOperation(std::vector size, InterpolationMode interpolation) : size_(size), interpolation_(interpolation) {} @@ -40,14 +38,18 @@ Status ResizeOperation::ValidateParams() { } std::shared_ptr ResizeOperation::Build() { + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t size_two = 2; + // If size is a single value, the smaller edge of the image will be // resized to this value with the same image aspect ratio. - int32_t height = size_[0]; + int32_t height = size_[dimension_zero]; int32_t width = 0; // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; + if (size_.size() == size_two) { + width = size_[dimension_one]; } return std::make_shared(height, width, interpolation_); @@ -60,7 +62,6 @@ Status ResizeOperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_preserve_ar_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_preserve_ar_ir.cc index d38213d9e4f..038b190400e 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_preserve_ar_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_preserve_ar_ir.cc @@ -23,9 +23,7 @@ namespace mindspore { namespace dataset { - namespace vision { - // ResizePreserveAROperation ResizePreserveAROperation::ResizePreserveAROperation(int32_t height, int32_t width, int32_t img_orientation) : height_(height), width_(width), img_orientation_(img_orientation) {} @@ -48,7 +46,6 @@ Status ResizePreserveAROperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.cc index aacf0250b33..f8ca93b2c67 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.cc @@ -25,9 +25,7 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID // ResizeWithBBoxOperation ResizeWithBBoxOperation::ResizeWithBBoxOperation(std::vector size, InterpolationMode interpolation) @@ -43,12 +41,16 @@ Status ResizeWithBBoxOperation::ValidateParams() { } std::shared_ptr ResizeWithBBoxOperation::Build() { - int32_t height = size_[0]; + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t size_two = 2; + + int32_t height = size_[dimension_zero]; int32_t width = 0; // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; + if (size_.size() == size_two) { + width = size_[dimension_one]; } return std::make_shared(height, width, interpolation_); @@ -61,9 +63,7 @@ Status ResizeWithBBoxOperation::to_json(nlohmann::json *out_json) { *out_json = args; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgb_to_gray_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgb_to_gray_ir.cc index 4e07fe41a91..c1c1e19c228 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgb_to_gray_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgb_to_gray_ir.cc @@ -23,9 +23,7 @@ namespace mindspore { namespace dataset { - namespace vision { - RgbToGrayOperation::RgbToGrayOperation() = default; // RGB2GRAYOperation @@ -36,7 +34,6 @@ std::string RgbToGrayOperation::Name() const { return kRgbToGrayOperation; } Status RgbToGrayOperation::ValidateParams() { return Status::OK(); } std::shared_ptr RgbToGrayOperation::Build() { return std::make_shared(); } - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_bgr_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_bgr_ir.cc index 9a2b2ca1158..5dabe205d85 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_bgr_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_bgr_ir.cc @@ -27,9 +27,7 @@ namespace mindspore { namespace dataset { namespace vision { - #ifndef ENABLE_ANDROID - // RgbaToBgrOperation. RgbaToBgrOperation::RgbaToBgrOperation() {} @@ -44,7 +42,6 @@ std::shared_ptr RgbaToBgrOperation::Build() { return tensor_op; } #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_rgb_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_rgb_ir.cc index 1f8dadc216e..7e8eaf26e43 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_rgb_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_rgb_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // RgbaToRgbOperation. RgbaToRgbOperation::RgbaToRgbOperation() {} @@ -43,9 +40,7 @@ std::shared_ptr RgbaToRgbOperation::Build() { std::shared_ptr tensor_op = std::make_shared(); return tensor_op; } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.cc index 3bdac701786..1075226c954 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.cc @@ -20,9 +20,7 @@ namespace mindspore { namespace dataset { - namespace vision { - // RotateOperation RotateOperation::RotateOperation() { rotate_op_ = std::make_shared(0); } diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.cc index 46619a0101e..0f5598d0bfd 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.cc @@ -25,11 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID - // SoftDvppDecodeRandomCropResizeJpegOperation SoftDvppDecodeRandomCropResizeJpegOperation::SoftDvppDecodeRandomCropResizeJpegOperation(std::vector size, std::vector scale, @@ -46,8 +43,10 @@ std::string SoftDvppDecodeRandomCropResizeJpegOperation::Name() const { Status SoftDvppDecodeRandomCropResizeJpegOperation::ValidateParams() { // size RETURN_IF_NOT_OK(ValidateVectorSize("SoftDvppDecodeRandomCropResizeJpeg", size_)); + constexpr int32_t value_one = 1; + constexpr int32_t value_two = 2; for (int32_t i = 0; i < size_.size(); i++) { - if (size_[i] % 2 == 1) { + if (size_[i] % value_two == value_one) { std::string err_msg = "SoftDvppDecodeRandomCropResizeJpeg: size[" + std::to_string(i) + "] must be even values, got: " + std::to_string(size_[i]); MS_LOG(ERROR) << err_msg; @@ -69,15 +68,20 @@ Status SoftDvppDecodeRandomCropResizeJpegOperation::ValidateParams() { } std::shared_ptr SoftDvppDecodeRandomCropResizeJpegOperation::Build() { - int32_t height = size_[0]; - int32_t width = size_[0]; + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t size_two = 2; + + int32_t height = size_[dimension_zero]; + int32_t width = size_[dimension_zero]; // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; + if (size_.size() == size_two) { + width = size_[dimension_one]; } - auto tensor_op = std::make_shared(height, width, scale_[0], scale_[1], - ratio_[0], ratio_[1], max_attempts_); + auto tensor_op = std::make_shared(height, width, scale_[dimension_zero], + scale_[dimension_one], ratio_[dimension_zero], + ratio_[dimension_one], max_attempts_); return tensor_op; } @@ -90,9 +94,7 @@ Status SoftDvppDecodeRandomCropResizeJpegOperation::to_json(nlohmann::json *out_ *out_json = args; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.cc index e45ff9f88e1..750dcc0ecb0 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.cc @@ -25,10 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { #ifndef ENABLE_ANDROID - // SoftDvppDecodeResizeJpegOperation SoftDvppDecodeResizeJpegOperation::SoftDvppDecodeResizeJpegOperation(std::vector size) : size_(size) {} @@ -38,8 +36,10 @@ std::string SoftDvppDecodeResizeJpegOperation::Name() const { return kSoftDvppDe Status SoftDvppDecodeResizeJpegOperation::ValidateParams() { RETURN_IF_NOT_OK(ValidateVectorSize("SoftDvppDecodeResizeJpeg", size_)); + constexpr int32_t value_one = 1; + constexpr int32_t value_two = 2; for (int32_t i = 0; i < size_.size(); i++) { - if (size_[i] % 2 == 1) { + if (size_[i] % value_two == value_one) { std::string err_msg = "SoftDvppDecodeResizeJpeg: size[" + std::to_string(i) + "] must be even values, got: " + std::to_string(size_[i]); MS_LOG(ERROR) << err_msg; @@ -50,14 +50,18 @@ Status SoftDvppDecodeResizeJpegOperation::ValidateParams() { } std::shared_ptr SoftDvppDecodeResizeJpegOperation::Build() { + constexpr size_t dimension_zero = 0; + constexpr size_t dimension_one = 1; + constexpr size_t size_two = 2; + // If size is a single value, the smaller edge of the image will be // resized to this value with the same image aspect ratio. - int32_t height = size_[0]; + int32_t height = size_[dimension_zero]; int32_t width = 0; // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; + if (size_.size() == size_two) { + width = size_[dimension_one]; } std::shared_ptr tensor_op = std::make_shared(height, width); return tensor_op; @@ -67,9 +71,7 @@ Status SoftDvppDecodeResizeJpegOperation::to_json(nlohmann::json *out_json) { (*out_json)["size"] = size_; return Status::OK(); } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/swap_red_blue_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/swap_red_blue_ir.cc index 5209402ab1e..50663853be9 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/swap_red_blue_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/swap_red_blue_ir.cc @@ -25,10 +25,8 @@ namespace mindspore { namespace dataset { - namespace vision { #ifndef ENABLE_ANDROID - // SwapRedBlueOperation. SwapRedBlueOperation::SwapRedBlueOperation() {} @@ -42,9 +40,7 @@ std::shared_ptr SwapRedBlueOperation::Build() { std::shared_ptr tensor_op = std::make_shared(); return tensor_op; } - #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/uniform_aug_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/uniform_aug_ir.cc index 5469998cd71..1bc3938656c 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/uniform_aug_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/uniform_aug_ir.cc @@ -25,9 +25,7 @@ namespace mindspore { namespace dataset { - namespace vision { - #ifndef ENABLE_ANDROID // UniformAugOperation UniformAugOperation::UniformAugOperation(std::vector> transforms, int32_t num_ops) @@ -75,7 +73,6 @@ Status UniformAugOperation::to_json(nlohmann::json *out_json) { return Status::OK(); } #endif - } // namespace vision } // namespace dataset } // namespace mindspore diff --git a/mindspore/lite/tools/dataset/cropper/build_lib.py b/mindspore/lite/tools/dataset/cropper/build_lib.py index d1e97b38442..8d34137bfcc 100644 --- a/mindspore/lite/tools/dataset/cropper/build_lib.py +++ b/mindspore/lite/tools/dataset/cropper/build_lib.py @@ -111,7 +111,7 @@ def main(): associations_dict = load_associations() # get all objects filename - all_object_files = [x[x.rfind('/') + 1:] for x in glob.glob('{}*.o'.format(OBJECTS_DIR))] + all_object_files = [os.path.basename(x) for x in glob.glob('{}*.o'.format(OBJECTS_DIR))] print("All Obj files: {}".format(len(all_object_files))) # find ops in user code diff --git a/mindspore/lite/tools/dataset/cropper/crop.sh b/mindspore/lite/tools/dataset/cropper/crop.sh index 1d459af9849..fa069b4be49 100755 --- a/mindspore/lite/tools/dataset/cropper/crop.sh +++ b/mindspore/lite/tools/dataset/cropper/crop.sh @@ -68,7 +68,7 @@ echo "CWD: $ORIGINAL_PATH" echo "File PATH: $FILE_PATH" -cd $FILE_PATH +cd $FILE_PATH || exit MD_LIB_FILENAME="libminddata-lite.a" @@ -76,7 +76,7 @@ MD_LIB_FILENAME="libminddata-lite.a" MD_LIB_PATH=`find $MINDSPORE_PATH -name "${MD_LIB_FILENAME}" | head -n 1` if [ -z "${MD_LIB_PATH}" ]; then echo -e "\e[31mMindData lite static library could not be found.\e[0m" - cd $ORIGINAL_PATH + cd $ORIGINAL_PATH || exit exit 1 fi @@ -84,7 +84,7 @@ fi # extract all objects of static lib to tmp/ mkdir -p tmp cp $MD_LIB_PATH tmp -cd tmp +cd tmp || exit # extract objects with identical names by prepending (one or more) '_' to their names # (this scruipt supports more than 2 duplicate filenames) DUPLICATES=`ar t "${MD_LIB_FILENAME}" | sort | uniq -d` @@ -115,7 +115,7 @@ cd .. python build_lib.py ${USER_CODES} retVal=$? if [ $retVal -ne 0 ]; then - cd $ORIGINAL_PATH + cd $ORIGINAL_PATH || exit exit 1 fi @@ -144,13 +144,13 @@ echo "Architecture: $TARGET_ARCHITECTURE" if [ "$TARGET_ARCHITECTURE" == "ARM64" ]; then if [ -z "${ANDROID_NDK}" ]; then echo -e "\e[31mPlease set ANDROID_NDK environment variable.\e[0m" - cd $ORIGINAL_PATH + cd $ORIGINAL_PATH || exit exit 1 fi elif [ "$TARGET_ARCHITECTURE" == "ARM32" ]; then if [ -z "${ANDROID_NDK}" ]; then echo -e "\e[31mPlease set ANDROID_NDK environment variable.\e[0m" - cd $ORIGINAL_PATH + cd $ORIGINAL_PATH || exit exit 1 fi # add LIBCLANG_RT_LIB for ARM32 @@ -184,4 +184,4 @@ fi rm -rf tmp/ -cd $ORIGINAL_PATH +cd $ORIGINAL_PATH || exit diff --git a/mindspore/lite/tools/dataset/cropper/cropper_configure.py b/mindspore/lite/tools/dataset/cropper/cropper_configure.py index 3408262a29b..864928dc9d6 100644 --- a/mindspore/lite/tools/dataset/cropper/cropper_configure.py +++ b/mindspore/lite/tools/dataset/cropper/cropper_configure.py @@ -20,6 +20,7 @@ import json import os import queue import re +import shlex import subprocess from mindspore import log as logger @@ -186,7 +187,9 @@ def get_dependencies_of_file(headers_flag, filename): :return: a list of file names [file0.cc, file1.h, file2.h, file3.h] and error string """ command = 'gcc -MM -MG {0} {1} {2}'.format(filename, DEFINE_STR, headers_flag) - stdout, stderr = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() + command_split = shlex.split(command) + stdout, stderr = subprocess.Popen(command_split, shell=False, stdout=subprocess.PIPE, + stderr=subprocess.PIPE).communicate() deps = re.split(r'[\s\\]+', stdout.decode('utf-8').strip(), flags=re.MULTILINE)[1:] return deps, stderr.decode('utf-8') @@ -272,7 +275,7 @@ def get_all_dependencies_of_file(headers_flag, filename): if needs_processing(dep_cc, processed_cc, queue_cc_set): queue_cc.put(dep_cc) queue_cc_set.add(dep_cc) - logger.debug('file: {} | deps: {}'.format(filename[filename.rfind('/') + 1:], len(processed_cc))) + logger.debug('file: {} | deps: {}'.format(os.path.basename(filename), len(processed_cc))) return list(processed_cc), "".join(errors)