diff --git a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/engine/ir/datasetops/source/samplers/bindings.cc b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/engine/ir/datasetops/source/samplers/bindings.cc index fe28193078..e6e617cf88 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/engine/ir/datasetops/source/samplers/bindings.cc +++ b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/engine/ir/datasetops/source/samplers/bindings.cc @@ -21,7 +21,15 @@ #include "minddata/dataset/api/python/pybind_register.h" #include "minddata/dataset/include/dataset/constants.h" #include "minddata/dataset/core/global_context.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/distributed_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/pk_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/random_sampler_ir.h" #include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/sequential_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/subset_random_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/subset_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/weighted_random_sampler_ir.h" namespace mindspore { namespace dataset { diff --git a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/ir/image/bindings.cc b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/ir/image/bindings.cc index fdfd4299a6..a8b87aa21e 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/ir/image/bindings.cc +++ b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/ir/image/bindings.cc @@ -14,11 +14,48 @@ * limitations under the License. */ #include "pybind11/pybind11.h" - #include "minddata/dataset/api/python/pybind_conversion.h" #include "minddata/dataset/api/python/pybind_register.h" #include "minddata/dataset/include/dataset/transforms.h" -#include "minddata/dataset/kernels/ir/vision/vision_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/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_with_bbox_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/uniform_aug_ir.h" namespace mindspore { namespace dataset { diff --git a/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.h b/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.h index a6a33202dd..199549bcbb 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.h +++ b/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.h @@ -33,7 +33,8 @@ #include "minddata/dataset/engine/ir/cache/pre_built_dataset_cache.h" #include "minddata/dataset/engine/ir/datasetops/source/csv_node.h" #include "minddata/dataset/include/dataset/datasets.h" -#include "minddata/dataset/include/dataset/samplers.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.h" #include "minddata/dataset/kernels/ir/data/transforms_ir.h" #include "minddata/dataset/kernels/py_func_op.h" namespace py = pybind11; diff --git a/mindspore/ccsrc/minddata/dataset/api/samplers.cc b/mindspore/ccsrc/minddata/dataset/api/samplers.cc index 632a714d33..b7ec9fd86e 100644 --- a/mindspore/ccsrc/minddata/dataset/api/samplers.cc +++ b/mindspore/ccsrc/minddata/dataset/api/samplers.cc @@ -15,7 +15,15 @@ */ #include "minddata/dataset/include/dataset/samplers.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/distributed_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/pk_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/random_sampler_ir.h" #include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/sequential_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/subset_random_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/subset_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/weighted_random_sampler_ir.h" namespace mindspore { namespace dataset { diff --git a/mindspore/ccsrc/minddata/dataset/api/vision.cc b/mindspore/ccsrc/minddata/dataset/api/vision.cc index 10db15bffb..e810727f7c 100644 --- a/mindspore/ccsrc/minddata/dataset/api/vision.cc +++ b/mindspore/ccsrc/minddata/dataset/api/vision.cc @@ -21,7 +21,52 @@ #endif #include "minddata/dataset/include/dataset/transforms.h" -#include "minddata/dataset/kernels/ir/vision/vision_ir.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" diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/CMakeLists.txt index a5237665e2..df8e489ba7 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/CMakeLists.txt @@ -2,7 +2,15 @@ file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc" set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) set(DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SRC_FILES + distributed_sampler_ir.cc + pk_sampler_ir.cc + prebuilt_sampler_ir.cc + random_sampler_ir.cc samplers_ir.cc + sequential_sampler_ir.cc + subset_random_sampler_ir.cc + subset_sampler_ir.cc + weighted_random_sampler_ir.cc ) add_library(engine-ir-datasetops-source-samplers OBJECT ${DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SRC_FILES}) \ No newline at end of file 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 new file mode 100644 index 0000000000..fa9aafbb69 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/distributed_sampler_ir.cc @@ -0,0 +1,129 @@ +/** + * 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/engine/ir/datasetops/source/samplers/distributed_sampler_ir.h" +#include "minddata/dataset/engine/datasetops/source/sampler/distributed_sampler.h" +#include "minddata/dataset/core/config_manager.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/util/random.h" +#include "minddata/mindrecord/include/shard_distributed_sample.h" +#include "minddata/mindrecord/include/shard_operator.h" +#include "minddata/mindrecord/include/shard_pk_sample.h" +#include "minddata/mindrecord/include/shard_sample.h" +#include "minddata/mindrecord/include/shard_sequential_sample.h" +#include "minddata/mindrecord/include/shard_shuffle.h" +#endif + +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) + : num_shards_(num_shards), + shard_id_(shard_id), + shuffle_(shuffle), + num_samples_(num_samples), + seed_(seed), + offset_(offset), + even_dist_(even_dist) { + // Update the num_shards_ in global context. this number is only used for now by auto_num_worker_pass. User discretion + // is advised. Auto_num_worker_pass is currently an experimental feature which can still work if the num_shards_ isn't + // 100% correct. The reason behind is for now, PreBuildSampler doesn't offer a way to return num_shards. Once + // PreBuildSampler is phased out, this can be cleaned up. + GlobalContext::config_manager()->set_num_shards_for_auto_num_workers(num_shards_); +} + +// Destructor +DistributedSamplerObj::~DistributedSamplerObj() = default; + +Status DistributedSamplerObj::ValidateParams() { + if (num_shards_ <= 0) { + RETURN_STATUS_UNEXPECTED("DistributedSampler: num_shards must be greater than 0, but got: " + + std::to_string(num_shards_)); + } + + if (shard_id_ < 0 || shard_id_ >= num_shards_) { + RETURN_STATUS_UNEXPECTED("DistributedSampler: shard_id must be in range [0, " + std::to_string(num_shards_) + + "), but got: " + std::to_string(shard_id_)); + } + + if (num_samples_ < 0) { + RETURN_STATUS_UNEXPECTED("DistributedSampler: num_samples must be greater than or equal to 0, but got: " + + std::to_string(num_samples_)); + } + + if (offset_ > num_shards_) { + RETURN_STATUS_UNEXPECTED("DistributedSampler: offset must be no more than num_shards(" + + std::to_string(num_shards_) + "), but got: " + std::to_string(offset_)); + } + + return Status::OK(); +} + +Status DistributedSamplerObj::SamplerBuild(std::shared_ptr *sampler) { + // runtime sampler object + *sampler = std::make_shared(num_samples_, num_shards_, shard_id_, shuffle_, seed_, + offset_, even_dist_); + Status s = BuildChildren(sampler); + sampler = s.IsOk() ? sampler : nullptr; + return s; +} + +#ifndef ENABLE_ANDROID +std::shared_ptr DistributedSamplerObj::BuildForMindDataset() { + // runtime mindrecord sampler object + auto mind_sampler = std::make_shared(num_shards_, shard_id_, shuffle_, seed_, + num_samples_, offset_); + return mind_sampler; +} +#endif + +Status DistributedSamplerObj::to_json(nlohmann::json *const out_json) { + nlohmann::json args; + args["sampler_name"] = "DistributedSampler"; + args["num_shards"] = num_shards_; + args["shard_id"] = shard_id_; + args["shuffle"] = shuffle_; + args["num_samples"] = num_samples_; + args["offset"] = offset_; + if (!children_.empty()) { + std::vector children_args; + for (auto child : children_) { + nlohmann::json child_arg; + RETURN_IF_NOT_OK(child->to_json(&child_arg)); + children_args.push_back(child_arg); + } + args["child_sampler"] = children_args; + } + *out_json = args; + return Status::OK(); +} +std::shared_ptr DistributedSamplerObj::SamplerCopy() { + auto sampler = + std::make_shared(num_shards_, shard_id_, shuffle_, num_samples_, seed_, offset_, even_dist_); + for (const auto &child : children_) { + Status rc = sampler->AddChildSampler(child); + if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; + } + return sampler; +} + +int64_t DistributedSamplerObj::ShardId() { return shard_id_; } + +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/distributed_sampler_ir.h b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/distributed_sampler_ir.h new file mode 100644 index 0000000000..6a957e8312 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/distributed_sampler_ir.h @@ -0,0 +1,77 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_DISTRIBUTED_SAMPLER_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_DISTRIBUTED_SAMPLER_IR_H_ + +#include +#include +#include +#include +#include +#include + +#include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" +#include "include/api/status.h" +#ifndef ENABLE_ANDROID +#include "minddata/mindrecord/include/shard_operator.h" +#endif + +namespace mindspore { +namespace dataset { + +// Internal Sampler class forward declaration +class SamplerRT; + +class DistributedSamplerObj : public SamplerObj { + public: + DistributedSamplerObj(int64_t num_shards, int64_t shard_id, bool shuffle, int64_t num_samples, uint32_t seed, + int64_t offset, bool even_dist); + + ~DistributedSamplerObj(); + + Status SamplerBuild(std::shared_ptr *sampler) override; + + std::shared_ptr SamplerCopy() override; + +#ifndef ENABLE_ANDROID + std::shared_ptr BuildForMindDataset() override; +#endif + + /// \brief Get the arguments of node + /// \param[out] out_json JSON string of all attributes + /// \return Status of the function + Status to_json(nlohmann::json *const out_json) override; + + Status ValidateParams() override; + + /// \brief Function to get the shard id of sampler + /// \return The shard id of sampler + int64_t ShardId() override; + + private: + int64_t num_shards_; + int64_t shard_id_; + bool shuffle_; + int64_t num_samples_; + uint32_t seed_; + int64_t offset_; + bool even_dist_; +}; + +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_DISTRIBUTED_SAMPLER_IR_H_ 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 new file mode 100644 index 0000000000..09bde109e9 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/pk_sampler_ir.cc @@ -0,0 +1,105 @@ +/** + * 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/engine/ir/datasetops/source/samplers/pk_sampler_ir.h" +#include "minddata/dataset/engine/datasetops/source/sampler/pk_sampler.h" +#include "minddata/dataset/core/config_manager.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/util/random.h" +#include "minddata/mindrecord/include/shard_distributed_sample.h" +#include "minddata/mindrecord/include/shard_operator.h" +#include "minddata/mindrecord/include/shard_pk_sample.h" +#include "minddata/mindrecord/include/shard_sample.h" +#include "minddata/mindrecord/include/shard_sequential_sample.h" +#include "minddata/mindrecord/include/shard_shuffle.h" +#endif + +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) {} + +// Destructor +PKSamplerObj::~PKSamplerObj() = default; + +Status PKSamplerObj::ValidateParams() { + if (num_val_ <= 0) { + RETURN_STATUS_UNEXPECTED("PKSampler: num_val must be greater than 0, but got: " + std::to_string(num_val_)); + } + + if (num_samples_ < 0) { + RETURN_STATUS_UNEXPECTED("PKSampler: num_samples must be greater than or equal to 0, but got: " + + std::to_string(num_samples_)); + } + return Status::OK(); +} + +Status PKSamplerObj::to_json(nlohmann::json *const out_json) { + nlohmann::json args; + args["sampler_name"] = "PKSampler"; + args["num_val"] = num_val_; + args["shuffle"] = shuffle_; + args["num_samples"] = num_samples_; + if (!children_.empty()) { + std::vector children_args; + for (auto child : children_) { + nlohmann::json child_arg; + RETURN_IF_NOT_OK(child->to_json(&child_arg)); + children_args.push_back(child_arg); + } + args["child_sampler"] = children_args; + } + *out_json = args; + return Status::OK(); +} + +Status PKSamplerObj::SamplerBuild(std::shared_ptr *sampler) { + // runtime sampler object + *sampler = std::make_shared(num_samples_, num_val_, shuffle_); + Status s = BuildChildren(sampler); + sampler = s.IsOk() ? sampler : nullptr; + return s; +} + +#ifndef ENABLE_ANDROID +std::shared_ptr PKSamplerObj::BuildForMindDataset() { + // runtime mindrecord sampler object + std::shared_ptr mind_sampler; + if (shuffle_ == true) { + mind_sampler = std::make_shared("label", num_val_, std::numeric_limits::max(), + GetSeed(), num_samples_); + } else { + mind_sampler = std::make_shared("label", num_val_, num_samples_); + } + + return mind_sampler; +} +#endif + +std::shared_ptr PKSamplerObj::SamplerCopy() { + auto sampler = std::make_shared(num_val_, shuffle_, num_samples_); + for (const auto &child : children_) { + Status rc = sampler->AddChildSampler(child); + if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; + } + return sampler; +} + +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/pk_sampler_ir.h b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/pk_sampler_ir.h new file mode 100644 index 0000000000..eb8f6222bd --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/pk_sampler_ir.h @@ -0,0 +1,68 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_PK_SAMPLER_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_PK_SAMPLER_IR_H_ + +#include +#include +#include +#include +#include +#include + +#include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" +#include "include/api/status.h" +#ifndef ENABLE_ANDROID +#include "minddata/mindrecord/include/shard_operator.h" +#endif + +namespace mindspore { +namespace dataset { + +// Internal Sampler class forward declaration +class SamplerRT; + +class PKSamplerObj : public SamplerObj { + public: + PKSamplerObj(int64_t num_val, bool shuffle, int64_t num_samples); + + ~PKSamplerObj(); + + Status SamplerBuild(std::shared_ptr *sampler) override; + + std::shared_ptr SamplerCopy() override; + +#ifndef ENABLE_ANDROID + std::shared_ptr BuildForMindDataset() override; +#endif + + /// \brief Get the arguments of node + /// \param[out] out_json JSON string of all attributes + /// \return Status of the function + Status to_json(nlohmann::json *const out_json) override; + + Status ValidateParams() override; + + private: + int64_t num_val_; + bool shuffle_; + int64_t num_samples_; +}; + +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_PK_SAMPLER_IR_H_ 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 new file mode 100644 index 0000000000..80ce7ba739 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.cc @@ -0,0 +1,85 @@ +/** + * 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/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.h" +#include "minddata/dataset/engine/datasetops/source/sampler/sampler.h" +#include "minddata/dataset/core/config_manager.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/util/random.h" +#include "minddata/mindrecord/include/shard_distributed_sample.h" +#include "minddata/mindrecord/include/shard_operator.h" +#include "minddata/mindrecord/include/shard_pk_sample.h" +#include "minddata/mindrecord/include/shard_sample.h" +#include "minddata/mindrecord/include/shard_sequential_sample.h" +#include "minddata/mindrecord/include/shard_shuffle.h" +#endif + +namespace mindspore { +namespace dataset { + +// Constructor +PreBuiltSamplerObj::PreBuiltSamplerObj(std::shared_ptr sampler) : sp_(std::move(sampler)) {} + +// Destructor +PreBuiltSamplerObj::~PreBuiltSamplerObj() = default; + +#ifndef ENABLE_ANDROID +PreBuiltSamplerObj::PreBuiltSamplerObj(std::shared_ptr sampler) + : sp_minddataset_(std::move(sampler)) {} +#endif + +Status PreBuiltSamplerObj::ValidateParams() { return Status::OK(); } + +Status PreBuiltSamplerObj::SamplerBuild(std::shared_ptr *const sampler) { + Status s = BuildChildren(&sp_); + if (s.IsOk()) + *sampler = sp_; + else + *sampler = nullptr; + return s; +} + +#ifndef ENABLE_ANDROID +std::shared_ptr PreBuiltSamplerObj::BuildForMindDataset() { return sp_minddataset_; } +#endif + +std::shared_ptr PreBuiltSamplerObj::SamplerCopy() { +#ifndef ENABLE_ANDROID + if (sp_minddataset_ != nullptr) { + auto sampler = std::make_shared(sp_minddataset_); + for (const auto &child : children_) { + Status rc = sampler->AddChildSampler(child); + if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; + } + return sampler; + } +#endif + auto sampler = std::make_shared(sp_); + for (const auto &child : children_) { + Status rc = sampler->AddChildSampler(child); + if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; + } + return sampler; +} + +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/prebuilt_sampler_ir.h b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.h new file mode 100644 index 0000000000..8b76f37d81 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.h @@ -0,0 +1,68 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_PREBUILT_SAMPLER_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_PREBUILT_SAMPLER_IR_H_ + +#include +#include +#include +#include +#include + +#include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" +#include "include/api/status.h" +#ifndef ENABLE_ANDROID +#include "minddata/mindrecord/include/shard_operator.h" +#endif + +namespace mindspore { +namespace dataset { + +// Internal Sampler class forward declaration +class SamplerRT; + +class PreBuiltSamplerObj : public SamplerObj { + public: + explicit PreBuiltSamplerObj(std::shared_ptr sampler); +#ifndef ENABLE_ANDROID + explicit PreBuiltSamplerObj(std::shared_ptr sampler); +#endif + + ~PreBuiltSamplerObj(); + + Status SamplerBuild(std::shared_ptr *const sampler) override; + +#ifndef ENABLE_ANDROID + std::shared_ptr BuildForMindDataset() override; +#endif + + std::shared_ptr SamplerCopy() override; + + Status ValidateParams() override; + + Status to_json(nlohmann::json *const out_json) override; + + private: + std::shared_ptr sp_; +#ifndef ENABLE_ANDROID + std::shared_ptr sp_minddataset_; +#endif +}; + +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_PREBUILT_SAMPLER_IR_H_ 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 new file mode 100644 index 0000000000..c20ab46e44 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/random_sampler_ir.cc @@ -0,0 +1,96 @@ +/** + * 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/engine/ir/datasetops/source/samplers/random_sampler_ir.h" +#include "minddata/dataset/engine/datasetops/source/sampler/random_sampler.h" +#include "minddata/dataset/core/config_manager.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/util/random.h" +#include "minddata/mindrecord/include/shard_distributed_sample.h" +#include "minddata/mindrecord/include/shard_operator.h" +#include "minddata/mindrecord/include/shard_pk_sample.h" +#include "minddata/mindrecord/include/shard_sample.h" +#include "minddata/mindrecord/include/shard_sequential_sample.h" +#include "minddata/mindrecord/include/shard_shuffle.h" +#endif + +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) {} + +// Destructor +RandomSamplerObj::~RandomSamplerObj() = default; + +Status RandomSamplerObj::ValidateParams() { + if (num_samples_ < 0) { + RETURN_STATUS_UNEXPECTED("RandomSampler: num_samples must be greater than or equal to 0, but got: " + + std::to_string(num_samples_)); + } + return Status::OK(); +} + +Status RandomSamplerObj::to_json(nlohmann::json *const out_json) { + nlohmann::json args; + args["sampler_name"] = "RandomSampler"; + args["replacement"] = replacement_; + args["num_samples"] = num_samples_; + args["reshuffle_each_epoch"] = reshuffle_each_epoch_; + if (!children_.empty()) { + std::vector children_args; + for (auto child : children_) { + nlohmann::json child_arg; + RETURN_IF_NOT_OK(child->to_json(&child_arg)); + children_args.push_back(child_arg); + } + args["child_sampler"] = children_args; + } + *out_json = args; + return Status::OK(); +} + +Status RandomSamplerObj::SamplerBuild(std::shared_ptr *sampler) { + // runtime sampler object + *sampler = std::make_shared(num_samples_, replacement_, reshuffle_each_epoch_); + Status s = BuildChildren(sampler); + sampler = s.IsOk() ? sampler : nullptr; + return s; +} + +#ifndef ENABLE_ANDROID +std::shared_ptr RandomSamplerObj::BuildForMindDataset() { + // runtime mindrecord sampler object + auto mind_sampler = + std::make_shared(GetSeed(), num_samples_, replacement_, reshuffle_each_epoch_); + + return mind_sampler; +} +#endif + +std::shared_ptr RandomSamplerObj::SamplerCopy() { + auto sampler = std::make_shared(replacement_, num_samples_, reshuffle_each_epoch_); + for (const auto &child : children_) { + Status rc = sampler->AddChildSampler(child); + if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; + } + return sampler; +} + +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/random_sampler_ir.h b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/random_sampler_ir.h new file mode 100644 index 0000000000..e43089353f --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/random_sampler_ir.h @@ -0,0 +1,68 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_RANDOM_SAMPLER_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_RANDOM_SAMPLER_IR_H_ + +#include +#include +#include +#include +#include +#include + +#include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" +#include "include/api/status.h" +#ifndef ENABLE_ANDROID +#include "minddata/mindrecord/include/shard_operator.h" +#endif + +namespace mindspore { +namespace dataset { + +// Internal Sampler class forward declaration +class SamplerRT; + +class RandomSamplerObj : public SamplerObj { + public: + RandomSamplerObj(bool replacement, int64_t num_samples, bool reshuffle_each_epoch = true); + + ~RandomSamplerObj(); + + Status SamplerBuild(std::shared_ptr *sampler) override; + + std::shared_ptr SamplerCopy() override; + +#ifndef ENABLE_ANDROID + std::shared_ptr BuildForMindDataset() override; +#endif + + /// \brief Get the arguments of node + /// \param[out] out_json JSON string of all attributes + /// \return Status of the function + Status to_json(nlohmann::json *const out_json) override; + + Status ValidateParams() override; + + private: + bool replacement_; + int64_t num_samples_; + bool reshuffle_each_epoch_; +}; + +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_RANDOM_SAMPLER_IR_H_ diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.cc b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.cc index 8c6870b1ea..a6e48f79ca 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.cc @@ -15,26 +15,9 @@ */ #include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" - -#include "minddata/dataset/core/config_manager.h" -#include "minddata/dataset/engine/datasetops/source/sampler/distributed_sampler.h" -#include "minddata/dataset/engine/datasetops/source/sampler/pk_sampler.h" -#include "minddata/dataset/engine/datasetops/source/sampler/random_sampler.h" #include "minddata/dataset/engine/datasetops/source/sampler/sampler.h" -#include "minddata/dataset/engine/datasetops/source/sampler/sequential_sampler.h" -#include "minddata/dataset/engine/datasetops/source/sampler/subset_random_sampler.h" -#include "minddata/dataset/engine/datasetops/source/sampler/subset_sampler.h" -#include "minddata/dataset/engine/datasetops/source/sampler/weighted_random_sampler.h" -#ifndef ENABLE_ANDROID -#include "minddata/dataset/util/random.h" -#include "minddata/mindrecord/include/shard_distributed_sample.h" -#include "minddata/mindrecord/include/shard_operator.h" -#include "minddata/mindrecord/include/shard_pk_sample.h" -#include "minddata/mindrecord/include/shard_sample.h" -#include "minddata/mindrecord/include/shard_sequential_sample.h" -#include "minddata/mindrecord/include/shard_shuffle.h" -#endif +#include "minddata/dataset/core/config_manager.h" namespace mindspore { namespace dataset { @@ -42,6 +25,9 @@ namespace dataset { // Constructor SamplerObj::SamplerObj() {} +// Destructor +SamplerObj::~SamplerObj() = default; + Status SamplerObj::BuildChildren(std::shared_ptr *const sampler) { for (auto child : children_) { std::shared_ptr sampler_rt = nullptr; @@ -72,492 +58,5 @@ Status SamplerObj::AddChildSampler(std::shared_ptr child) { return Status::OK(); } -/* ####################################### Derived Sampler classes ################################# */ - -// DistributedSampler -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) - : num_shards_(num_shards), - shard_id_(shard_id), - shuffle_(shuffle), - num_samples_(num_samples), - seed_(seed), - offset_(offset), - even_dist_(even_dist) { - // Update the num_shards_ in global context. this number is only used for now by auto_num_worker_pass. User discretion - // is advised. Auto_num_worker_pass is currently an experimental feature which can still work if the num_shards_ isn't - // 100% correct. The reason behind is for now, PreBuildSampler doesn't offer a way to return num_shards. Once - // PreBuildSampler is phased out, this can be cleaned up. - GlobalContext::config_manager()->set_num_shards_for_auto_num_workers(num_shards_); -} - -Status DistributedSamplerObj::ValidateParams() { - if (num_shards_ <= 0) { - RETURN_STATUS_UNEXPECTED("DistributedSampler: num_shards must be greater than 0, but got: " + - std::to_string(num_shards_)); - } - - if (shard_id_ < 0 || shard_id_ >= num_shards_) { - RETURN_STATUS_UNEXPECTED("DistributedSampler: shard_id must be in range [0, " + std::to_string(num_shards_) + - "), but got: " + std::to_string(shard_id_)); - } - - if (num_samples_ < 0) { - RETURN_STATUS_UNEXPECTED("DistributedSampler: num_samples must be greater than or equal to 0, but got: " + - std::to_string(num_samples_)); - } - - if (offset_ > num_shards_) { - RETURN_STATUS_UNEXPECTED("DistributedSampler: offset must be no more than num_shards(" + - std::to_string(num_shards_) + "), but got: " + std::to_string(offset_)); - } - - return Status::OK(); -} - -Status DistributedSamplerObj::SamplerBuild(std::shared_ptr *sampler) { - // runtime sampler object - *sampler = std::make_shared(num_samples_, num_shards_, shard_id_, shuffle_, seed_, - offset_, even_dist_); - Status s = BuildChildren(sampler); - sampler = s.IsOk() ? sampler : nullptr; - return s; -} - -#ifndef ENABLE_ANDROID -std::shared_ptr DistributedSamplerObj::BuildForMindDataset() { - // runtime mindrecord sampler object - auto mind_sampler = std::make_shared(num_shards_, shard_id_, shuffle_, seed_, - num_samples_, offset_); - return mind_sampler; -} -#endif - -Status DistributedSamplerObj::to_json(nlohmann::json *const out_json) { - nlohmann::json args; - args["sampler_name"] = "DistributedSampler"; - args["num_shards"] = num_shards_; - args["shard_id"] = shard_id_; - args["shuffle"] = shuffle_; - args["num_samples"] = num_samples_; - args["offset"] = offset_; - if (!children_.empty()) { - std::vector children_args; - for (auto child : children_) { - nlohmann::json child_arg; - RETURN_IF_NOT_OK(child->to_json(&child_arg)); - children_args.push_back(child_arg); - } - args["child_sampler"] = children_args; - } - *out_json = args; - return Status::OK(); -} -std::shared_ptr DistributedSamplerObj::SamplerCopy() { - auto sampler = - std::make_shared(num_shards_, shard_id_, shuffle_, num_samples_, seed_, offset_, even_dist_); - for (const auto &child : children_) { - Status rc = sampler->AddChildSampler(child); - if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; - } - return sampler; -} - -// PKSampler -PKSamplerObj::PKSamplerObj(int64_t num_val, bool shuffle, int64_t num_samples) - : num_val_(num_val), shuffle_(shuffle), num_samples_(num_samples) {} - -Status PKSamplerObj::ValidateParams() { - if (num_val_ <= 0) { - RETURN_STATUS_UNEXPECTED("PKSampler: num_val must be greater than 0, but got: " + std::to_string(num_val_)); - } - - if (num_samples_ < 0) { - RETURN_STATUS_UNEXPECTED("PKSampler: num_samples must be greater than or equal to 0, but got: " + - std::to_string(num_samples_)); - } - return Status::OK(); -} - -Status PKSamplerObj::to_json(nlohmann::json *const out_json) { - nlohmann::json args; - args["sampler_name"] = "PKSampler"; - args["num_val"] = num_val_; - args["shuffle"] = shuffle_; - args["num_samples"] = num_samples_; - if (!children_.empty()) { - std::vector children_args; - for (auto child : children_) { - nlohmann::json child_arg; - RETURN_IF_NOT_OK(child->to_json(&child_arg)); - children_args.push_back(child_arg); - } - args["child_sampler"] = children_args; - } - *out_json = args; - return Status::OK(); -} - -Status PKSamplerObj::SamplerBuild(std::shared_ptr *sampler) { - // runtime sampler object - *sampler = std::make_shared(num_samples_, num_val_, shuffle_); - Status s = BuildChildren(sampler); - sampler = s.IsOk() ? sampler : nullptr; - return s; -} - -#ifndef ENABLE_ANDROID -std::shared_ptr PKSamplerObj::BuildForMindDataset() { - // runtime mindrecord sampler object - std::shared_ptr mind_sampler; - if (shuffle_ == true) { - mind_sampler = std::make_shared("label", num_val_, std::numeric_limits::max(), - GetSeed(), num_samples_); - } else { - mind_sampler = std::make_shared("label", num_val_, num_samples_); - } - - return mind_sampler; -} -#endif - -std::shared_ptr PKSamplerObj::SamplerCopy() { - auto sampler = std::make_shared(num_val_, shuffle_, num_samples_); - for (const auto &child : children_) { - Status rc = sampler->AddChildSampler(child); - if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; - } - return sampler; -} - -// PreBuiltOperation -PreBuiltSamplerObj::PreBuiltSamplerObj(std::shared_ptr sampler) : sp_(std::move(sampler)) {} - -#ifndef ENABLE_ANDROID -PreBuiltSamplerObj::PreBuiltSamplerObj(std::shared_ptr sampler) - : sp_minddataset_(std::move(sampler)) {} -#endif - -Status PreBuiltSamplerObj::ValidateParams() { return Status::OK(); } - -Status PreBuiltSamplerObj::SamplerBuild(std::shared_ptr *const sampler) { - Status s = BuildChildren(&sp_); - if (s.IsOk()) - *sampler = sp_; - else - *sampler = nullptr; - return s; -} - -#ifndef ENABLE_ANDROID -std::shared_ptr PreBuiltSamplerObj::BuildForMindDataset() { return sp_minddataset_; } -#endif - -std::shared_ptr PreBuiltSamplerObj::SamplerCopy() { -#ifndef ENABLE_ANDROID - if (sp_minddataset_ != nullptr) { - auto sampler = std::make_shared(sp_minddataset_); - for (const auto &child : children_) { - Status rc = sampler->AddChildSampler(child); - if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; - } - return sampler; - } -#endif - auto sampler = std::make_shared(sp_); - for (const auto &child : children_) { - Status rc = sampler->AddChildSampler(child); - if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; - } - return sampler; -} - -Status PreBuiltSamplerObj::to_json(nlohmann::json *const out_json) { - RETURN_IF_NOT_OK(sp_->to_json(out_json)); - return Status::OK(); -} - -// RandomSampler -RandomSamplerObj::RandomSamplerObj(bool replacement, int64_t num_samples, bool reshuffle_each_epoch) - : replacement_(replacement), num_samples_(num_samples), reshuffle_each_epoch_(reshuffle_each_epoch) {} - -Status RandomSamplerObj::ValidateParams() { - if (num_samples_ < 0) { - RETURN_STATUS_UNEXPECTED("RandomSampler: num_samples must be greater than or equal to 0, but got: " + - std::to_string(num_samples_)); - } - return Status::OK(); -} - -Status RandomSamplerObj::to_json(nlohmann::json *const out_json) { - nlohmann::json args; - args["sampler_name"] = "RandomSampler"; - args["replacement"] = replacement_; - args["num_samples"] = num_samples_; - args["reshuffle_each_epoch"] = reshuffle_each_epoch_; - if (!children_.empty()) { - std::vector children_args; - for (auto child : children_) { - nlohmann::json child_arg; - RETURN_IF_NOT_OK(child->to_json(&child_arg)); - children_args.push_back(child_arg); - } - args["child_sampler"] = children_args; - } - *out_json = args; - return Status::OK(); -} - -Status RandomSamplerObj::SamplerBuild(std::shared_ptr *sampler) { - // runtime sampler object - *sampler = std::make_shared(num_samples_, replacement_, reshuffle_each_epoch_); - Status s = BuildChildren(sampler); - sampler = s.IsOk() ? sampler : nullptr; - return s; -} - -#ifndef ENABLE_ANDROID -std::shared_ptr RandomSamplerObj::BuildForMindDataset() { - // runtime mindrecord sampler object - auto mind_sampler = - std::make_shared(GetSeed(), num_samples_, replacement_, reshuffle_each_epoch_); - - return mind_sampler; -} -#endif - -std::shared_ptr RandomSamplerObj::SamplerCopy() { - auto sampler = std::make_shared(replacement_, num_samples_, reshuffle_each_epoch_); - for (const auto &child : children_) { - Status rc = sampler->AddChildSampler(child); - if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; - } - return sampler; -} - -// SequentialSampler -SequentialSamplerObj::SequentialSamplerObj(int64_t start_index, int64_t num_samples) - : start_index_(start_index), num_samples_(num_samples) {} - -Status SequentialSamplerObj::ValidateParams() { - if (num_samples_ < 0) { - RETURN_STATUS_UNEXPECTED("SequentialSampler: num_samples must be greater than or equal to 0, but got: " + - std::to_string(num_samples_)); - } - - if (start_index_ < 0) { - RETURN_STATUS_UNEXPECTED("SequentialSampler: start_index_ must be greater than or equal to 0, but got: " + - std::to_string(start_index_)); - } - - return Status::OK(); -} - -Status SequentialSamplerObj::to_json(nlohmann::json *const out_json) { - nlohmann::json args; - args["sampler_name"] = "SequentialSampler"; - args["start_index"] = start_index_; - args["num_samples"] = num_samples_; - if (!children_.empty()) { - std::vector children_args; - for (auto child : children_) { - nlohmann::json child_arg; - RETURN_IF_NOT_OK(child->to_json(&child_arg)); - children_args.push_back(child_arg); - } - args["child_sampler"] = children_args; - } - *out_json = args; - return Status::OK(); -} - -Status SequentialSamplerObj::SamplerBuild(std::shared_ptr *sampler) { - // runtime sampler object - *sampler = std::make_shared(num_samples_, start_index_); - Status s = BuildChildren(sampler); - sampler = s.IsOk() ? sampler : nullptr; - return s; -} - -#ifndef ENABLE_ANDROID -std::shared_ptr SequentialSamplerObj::BuildForMindDataset() { - // runtime mindrecord sampler object - auto mind_sampler = std::make_shared(num_samples_, start_index_); - - return mind_sampler; -} -#endif -std::shared_ptr SequentialSamplerObj::SamplerCopy() { - auto sampler = std::make_shared(start_index_, num_samples_); - for (const auto &child : children_) { - Status rc = sampler->AddChildSampler(child); - if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; - } - return sampler; -} -// SubsetSampler -SubsetSamplerObj::SubsetSamplerObj(std::vector indices, int64_t num_samples) - : indices_(std::move(indices)), num_samples_(num_samples) {} - -Status SubsetSamplerObj::ValidateParams() { - if (num_samples_ < 0) { - RETURN_STATUS_UNEXPECTED("SubsetRandomSampler: num_samples must be greater than or equal to 0, but got: " + - std::to_string(num_samples_)); - } - - return Status::OK(); -} - -Status SubsetSamplerObj::SamplerBuild(std::shared_ptr *sampler) { - // runtime sampler object - *sampler = std::make_shared(num_samples_, indices_); - Status s = BuildChildren(sampler); - sampler = s.IsOk() ? sampler : nullptr; - return s; -} - -#ifndef ENABLE_ANDROID -std::shared_ptr SubsetSamplerObj::BuildForMindDataset() { - // runtime mindrecord sampler object - auto mind_sampler = std::make_shared(indices_); - - return mind_sampler; -} -#endif -Status SubsetSamplerObj::to_json(nlohmann::json *const out_json) { - nlohmann::json args; - args["sampler_name"] = "SubsetSampler"; - args["indices"] = indices_; - args["num_samples"] = num_samples_; - if (!children_.empty()) { - std::vector children_args; - for (auto child : children_) { - nlohmann::json child_arg; - RETURN_IF_NOT_OK(child->to_json(&child_arg)); - children_args.push_back(child_arg); - } - args["child_sampler"] = children_args; - } - *out_json = args; - return Status::OK(); -} -std::shared_ptr SubsetSamplerObj::SamplerCopy() { - auto sampler = std::make_shared(indices_, num_samples_); - for (const auto &child : children_) { - Status rc = sampler->AddChildSampler(child); - if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; - } - return sampler; -} - -// SubsetRandomSampler -SubsetRandomSamplerObj::SubsetRandomSamplerObj(std::vector indices, int64_t num_samples) - : SubsetSamplerObj(std::move(indices), num_samples) {} - -Status SubsetRandomSamplerObj::SamplerBuild(std::shared_ptr *sampler) { - // runtime sampler object - *sampler = std::make_shared(num_samples_, indices_); - Status s = BuildChildren(sampler); - sampler = s.IsOk() ? sampler : nullptr; - return s; -} - -#ifndef ENABLE_ANDROID -std::shared_ptr SubsetRandomSamplerObj::BuildForMindDataset() { - // runtime mindrecord sampler object - auto mind_sampler = std::make_shared(indices_, GetSeed()); - - return mind_sampler; -} -#endif - -Status SubsetRandomSamplerObj::to_json(nlohmann::json *const out_json) { - nlohmann::json args; - args["sampler_name"] = "SubsetRandomSampler"; - args["indices"] = indices_; - args["num_samples"] = num_samples_; - if (!children_.empty()) { - std::vector children_args; - for (auto child : children_) { - nlohmann::json child_arg; - RETURN_IF_NOT_OK(child->to_json(&child_arg)); - children_args.push_back(child_arg); - } - args["child_sampler"] = children_args; - } - *out_json = args; - return Status::OK(); -} -std::shared_ptr SubsetRandomSamplerObj::SamplerCopy() { - auto sampler = std::make_shared(indices_, num_samples_); - for (const auto &child : children_) { - Status rc = sampler->AddChildSampler(child); - if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; - } - return sampler; -} - -// WeightedRandomSampler -WeightedRandomSamplerObj::WeightedRandomSamplerObj(std::vector weights, int64_t num_samples, bool replacement) - : weights_(std::move(weights)), num_samples_(num_samples), replacement_(replacement) {} - -Status WeightedRandomSamplerObj::ValidateParams() { - if (weights_.empty()) { - RETURN_STATUS_UNEXPECTED("WeightedRandomSampler: weights vector must not be empty"); - } - int32_t zero_elem = 0; - for (int32_t i = 0; i < weights_.size(); ++i) { - if (weights_[i] < 0) { - RETURN_STATUS_UNEXPECTED("WeightedRandomSampler: weights vector must not contain negative number, got: " + - std::to_string(weights_[i])); - } - if (weights_[i] == 0.0) { - zero_elem++; - } - } - if (zero_elem == weights_.size()) { - RETURN_STATUS_UNEXPECTED("WeightedRandomSampler: elements of weights vector must not be all zero"); - } - if (num_samples_ < 0) { - RETURN_STATUS_UNEXPECTED("WeightedRandomSampler: num_samples must be greater than or equal to 0, but got: " + - std::to_string(num_samples_)); - } - return Status::OK(); -} - -Status WeightedRandomSamplerObj::to_json(nlohmann::json *const out_json) { - nlohmann::json args; - args["sampler_name"] = "WeightedRandomSampler"; - args["weights"] = weights_; - args["num_samples"] = num_samples_; - args["replacement"] = replacement_; - if (!children_.empty()) { - std::vector children_args; - for (auto child : children_) { - nlohmann::json child_arg; - RETURN_IF_NOT_OK(child->to_json(&child_arg)); - children_args.push_back(child_arg); - } - args["child_sampler"] = children_args; - } - *out_json = args; - return Status::OK(); -} - -Status WeightedRandomSamplerObj::SamplerBuild(std::shared_ptr *sampler) { - *sampler = std::make_shared(num_samples_, weights_, replacement_); - Status s = BuildChildren(sampler); - sampler = s.IsOk() ? sampler : nullptr; - return s; -} -std::shared_ptr WeightedRandomSamplerObj::SamplerCopy() { - auto sampler = std::make_shared(weights_, num_samples_, replacement_); - for (const auto &child : children_) { - Status rc = sampler->AddChildSampler(child); - if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; - } - return sampler; -} - } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h index 49362b8bb7..136d8bab61 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h @@ -41,7 +41,7 @@ class SamplerObj { SamplerObj(); /// \brief Destructor - ~SamplerObj() = default; + ~SamplerObj(); /// \brief Pure virtual function for derived class to implement parameters validation /// \return The Status code of the function. It returns OK status if parameters are valid. @@ -85,219 +85,6 @@ class SamplerObj { std::vector> children_; }; -/* ####################################### Derived Sampler classes ################################# */ -class DistributedSamplerObj : public SamplerObj { - public: - DistributedSamplerObj(int64_t num_shards, int64_t shard_id, bool shuffle, int64_t num_samples, uint32_t seed, - int64_t offset, bool even_dist); - - ~DistributedSamplerObj() = default; - - Status SamplerBuild(std::shared_ptr *sampler) override; - - std::shared_ptr SamplerCopy() override; - -#ifndef ENABLE_ANDROID - std::shared_ptr BuildForMindDataset() override; -#endif - - /// \brief Get the arguments of node - /// \param[out] out_json JSON string of all attributes - /// \return Status of the function - Status to_json(nlohmann::json *const out_json) override; - - Status ValidateParams() override; - - /// \brief Function to get the shard id of sampler - /// \return The shard id of sampler - int64_t ShardId() override { return shard_id_; } - - private: - int64_t num_shards_; - int64_t shard_id_; - bool shuffle_; - int64_t num_samples_; - uint32_t seed_; - int64_t offset_; - bool even_dist_; -}; - -class PKSamplerObj : public SamplerObj { - public: - PKSamplerObj(int64_t num_val, bool shuffle, int64_t num_samples); - - ~PKSamplerObj() = default; - - Status SamplerBuild(std::shared_ptr *sampler) override; - - std::shared_ptr SamplerCopy() override; - -#ifndef ENABLE_ANDROID - std::shared_ptr BuildForMindDataset() override; -#endif - - /// \brief Get the arguments of node - /// \param[out] out_json JSON string of all attributes - /// \return Status of the function - Status to_json(nlohmann::json *const out_json) override; - - Status ValidateParams() override; - - private: - int64_t num_val_; - bool shuffle_; - int64_t num_samples_; -}; - -class PreBuiltSamplerObj : public SamplerObj { - public: - explicit PreBuiltSamplerObj(std::shared_ptr sampler); -#ifndef ENABLE_ANDROID - explicit PreBuiltSamplerObj(std::shared_ptr sampler); -#endif - - ~PreBuiltSamplerObj() = default; - - Status SamplerBuild(std::shared_ptr *const sampler) override; - -#ifndef ENABLE_ANDROID - std::shared_ptr BuildForMindDataset() override; -#endif - - std::shared_ptr SamplerCopy() override; - - Status ValidateParams() override; - - Status to_json(nlohmann::json *const out_json) override; - - private: - std::shared_ptr sp_; -#ifndef ENABLE_ANDROID - std::shared_ptr sp_minddataset_; -#endif -}; - -class RandomSamplerObj : public SamplerObj { - public: - RandomSamplerObj(bool replacement, int64_t num_samples, bool reshuffle_each_epoch = true); - - ~RandomSamplerObj() = default; - - Status SamplerBuild(std::shared_ptr *sampler) override; - - std::shared_ptr SamplerCopy() override; - -#ifndef ENABLE_ANDROID - std::shared_ptr BuildForMindDataset() override; -#endif - - /// \brief Get the arguments of node - /// \param[out] out_json JSON string of all attributes - /// \return Status of the function - Status to_json(nlohmann::json *const out_json) override; - - Status ValidateParams() override; - - private: - bool replacement_; - int64_t num_samples_; - bool reshuffle_each_epoch_; -}; - -class SequentialSamplerObj : public SamplerObj { - public: - SequentialSamplerObj(int64_t start_index, int64_t num_samples); - - ~SequentialSamplerObj() = default; - - Status SamplerBuild(std::shared_ptr *sampler) override; - - std::shared_ptr SamplerCopy() override; - -#ifndef ENABLE_ANDROID - std::shared_ptr BuildForMindDataset() override; -#endif - - /// \brief Get the arguments of node - /// \param[out] out_json JSON string of all attributes - /// \return Status of the function - Status to_json(nlohmann::json *const out_json) override; - - Status ValidateParams() override; - - private: - int64_t start_index_; - int64_t num_samples_; -}; - -class SubsetSamplerObj : public SamplerObj { - public: - SubsetSamplerObj(std::vector indices, int64_t num_samples); - - ~SubsetSamplerObj() = default; - - Status SamplerBuild(std::shared_ptr *sampler) override; - - std::shared_ptr SamplerCopy() override; - -#ifndef ENABLE_ANDROID - std::shared_ptr BuildForMindDataset() override; -#endif - - /// \brief Get the arguments of node - /// \param[out] out_json JSON string of all attributes - /// \return Status of the function - Status to_json(nlohmann::json *const out_json) override; - - Status ValidateParams() override; - - protected: - const std::vector indices_; - int64_t num_samples_; -}; - -class SubsetRandomSamplerObj : public SubsetSamplerObj { - public: - SubsetRandomSamplerObj(std::vector indices, int64_t num_samples); - - ~SubsetRandomSamplerObj() = default; - - Status to_json(nlohmann::json *const out_json) override; - - Status SamplerBuild(std::shared_ptr *sampler) override; - - std::shared_ptr SamplerCopy() override; - -#ifndef ENABLE_ANDROID - std::shared_ptr BuildForMindDataset() override; -#endif - - private: -}; - -class WeightedRandomSamplerObj : public SamplerObj { - public: - explicit WeightedRandomSamplerObj(std::vector weights, int64_t num_samples = 0, bool replacement = true); - - ~WeightedRandomSamplerObj() = default; - - Status SamplerBuild(std::shared_ptr *sampler) override; - - std::shared_ptr SamplerCopy() override; - - /// \brief Get the arguments of node - /// \param[out] out_json JSON string of all attributes - /// \return Status of the function - Status to_json(nlohmann::json *const out_json) override; - - Status ValidateParams() override; - - private: - const std::vector weights_; - int64_t num_samples_; - bool replacement_; -}; - } // namespace dataset } // namespace mindspore #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SAMPLERS_IR_H_ 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 new file mode 100644 index 0000000000..ba64a9fc6d --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/sequential_sampler_ir.cc @@ -0,0 +1,99 @@ +/** + * 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/engine/ir/datasetops/source/samplers/sequential_sampler_ir.h" +#include "minddata/dataset/engine/datasetops/source/sampler/sequential_sampler.h" +#include "minddata/dataset/core/config_manager.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/util/random.h" +#include "minddata/mindrecord/include/shard_distributed_sample.h" +#include "minddata/mindrecord/include/shard_operator.h" +#include "minddata/mindrecord/include/shard_pk_sample.h" +#include "minddata/mindrecord/include/shard_sample.h" +#include "minddata/mindrecord/include/shard_sequential_sample.h" +#include "minddata/mindrecord/include/shard_shuffle.h" +#endif + +namespace mindspore { +namespace dataset { + +// Constructor +SequentialSamplerObj::SequentialSamplerObj(int64_t start_index, int64_t num_samples) + : start_index_(start_index), num_samples_(num_samples) {} + +// Destructor +SequentialSamplerObj::~SequentialSamplerObj() = default; + +Status SequentialSamplerObj::ValidateParams() { + if (num_samples_ < 0) { + RETURN_STATUS_UNEXPECTED("SequentialSampler: num_samples must be greater than or equal to 0, but got: " + + std::to_string(num_samples_)); + } + + if (start_index_ < 0) { + RETURN_STATUS_UNEXPECTED("SequentialSampler: start_index_ must be greater than or equal to 0, but got: " + + std::to_string(start_index_)); + } + + return Status::OK(); +} + +Status SequentialSamplerObj::to_json(nlohmann::json *const out_json) { + nlohmann::json args; + args["sampler_name"] = "SequentialSampler"; + args["start_index"] = start_index_; + args["num_samples"] = num_samples_; + if (!children_.empty()) { + std::vector children_args; + for (auto child : children_) { + nlohmann::json child_arg; + RETURN_IF_NOT_OK(child->to_json(&child_arg)); + children_args.push_back(child_arg); + } + args["child_sampler"] = children_args; + } + *out_json = args; + return Status::OK(); +} + +Status SequentialSamplerObj::SamplerBuild(std::shared_ptr *sampler) { + // runtime sampler object + *sampler = std::make_shared(num_samples_, start_index_); + Status s = BuildChildren(sampler); + sampler = s.IsOk() ? sampler : nullptr; + return s; +} + +#ifndef ENABLE_ANDROID +std::shared_ptr SequentialSamplerObj::BuildForMindDataset() { + // runtime mindrecord sampler object + auto mind_sampler = std::make_shared(num_samples_, start_index_); + + return mind_sampler; +} +#endif +std::shared_ptr SequentialSamplerObj::SamplerCopy() { + auto sampler = std::make_shared(start_index_, num_samples_); + for (const auto &child : children_) { + Status rc = sampler->AddChildSampler(child); + if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; + } + return sampler; +} + +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/sequential_sampler_ir.h b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/sequential_sampler_ir.h new file mode 100644 index 0000000000..0ad0cd1f4b --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/sequential_sampler_ir.h @@ -0,0 +1,67 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SEQUENTIAL_SAMPLER_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SEQUENTIAL_SAMPLER_IR_H_ + +#include +#include +#include +#include +#include +#include + +#include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" +#include "include/api/status.h" +#ifndef ENABLE_ANDROID +#include "minddata/mindrecord/include/shard_operator.h" +#endif + +namespace mindspore { +namespace dataset { + +// Internal Sampler class forward declaration +class SamplerRT; + +class SequentialSamplerObj : public SamplerObj { + public: + SequentialSamplerObj(int64_t start_index, int64_t num_samples); + + ~SequentialSamplerObj(); + + Status SamplerBuild(std::shared_ptr *sampler) override; + + std::shared_ptr SamplerCopy() override; + +#ifndef ENABLE_ANDROID + std::shared_ptr BuildForMindDataset() override; +#endif + + /// \brief Get the arguments of node + /// \param[out] out_json JSON string of all attributes + /// \return Status of the function + Status to_json(nlohmann::json *const out_json) override; + + Status ValidateParams() override; + + private: + int64_t start_index_; + int64_t num_samples_; +}; + +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SEQUENTIAL_SAMPLER_IR_H_ 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 new file mode 100644 index 0000000000..a38d7bb56f --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_random_sampler_ir.cc @@ -0,0 +1,85 @@ +/** + * 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/engine/ir/datasetops/source/samplers/subset_random_sampler_ir.h" +#include "minddata/dataset/engine/datasetops/source/sampler/subset_random_sampler.h" +#include "minddata/dataset/core/config_manager.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/util/random.h" +#include "minddata/mindrecord/include/shard_distributed_sample.h" +#include "minddata/mindrecord/include/shard_operator.h" +#include "minddata/mindrecord/include/shard_pk_sample.h" +#include "minddata/mindrecord/include/shard_sample.h" +#include "minddata/mindrecord/include/shard_sequential_sample.h" +#include "minddata/mindrecord/include/shard_shuffle.h" +#endif + +namespace mindspore { +namespace dataset { + +// Constructor +SubsetRandomSamplerObj::SubsetRandomSamplerObj(std::vector indices, int64_t num_samples) + : SubsetSamplerObj(std::move(indices), num_samples) {} + +// Destructor +SubsetRandomSamplerObj::~SubsetRandomSamplerObj() = default; + +Status SubsetRandomSamplerObj::SamplerBuild(std::shared_ptr *sampler) { + // runtime sampler object + *sampler = std::make_shared(num_samples_, indices_); + Status s = BuildChildren(sampler); + sampler = s.IsOk() ? sampler : nullptr; + return s; +} + +#ifndef ENABLE_ANDROID +std::shared_ptr SubsetRandomSamplerObj::BuildForMindDataset() { + // runtime mindrecord sampler object + auto mind_sampler = std::make_shared(indices_, GetSeed()); + + return mind_sampler; +} +#endif + +Status SubsetRandomSamplerObj::to_json(nlohmann::json *const out_json) { + nlohmann::json args; + args["sampler_name"] = "SubsetRandomSampler"; + args["indices"] = indices_; + args["num_samples"] = num_samples_; + if (!children_.empty()) { + std::vector children_args; + for (auto child : children_) { + nlohmann::json child_arg; + RETURN_IF_NOT_OK(child->to_json(&child_arg)); + children_args.push_back(child_arg); + } + args["child_sampler"] = children_args; + } + *out_json = args; + return Status::OK(); +} +std::shared_ptr SubsetRandomSamplerObj::SamplerCopy() { + auto sampler = std::make_shared(indices_, num_samples_); + for (const auto &child : children_) { + Status rc = sampler->AddChildSampler(child); + if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; + } + return sampler; +} + +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_random_sampler_ir.h b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_random_sampler_ir.h new file mode 100644 index 0000000000..8360d7575c --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_random_sampler_ir.h @@ -0,0 +1,61 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SUBSET_RANDOM_SAMPLER_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SUBSET_RANDOM_SAMPLER_IR_H_ + +#include +#include +#include +#include +#include +#include + +#include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/subset_sampler_ir.h" +#include "include/api/status.h" +#ifndef ENABLE_ANDROID +#include "minddata/mindrecord/include/shard_operator.h" +#endif + +namespace mindspore { +namespace dataset { + +// Internal Sampler class forward declaration +class SamplerRT; + +class SubsetRandomSamplerObj : public SubsetSamplerObj { + public: + SubsetRandomSamplerObj(std::vector indices, int64_t num_samples); + + ~SubsetRandomSamplerObj(); + + Status to_json(nlohmann::json *const out_json) override; + + Status SamplerBuild(std::shared_ptr *sampler) override; + + std::shared_ptr SamplerCopy() override; + +#ifndef ENABLE_ANDROID + std::shared_ptr BuildForMindDataset() override; +#endif + + private: +}; + +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SUBSET_RANDOM_SAMPLER_IR_H_ 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 new file mode 100644 index 0000000000..1639fd2085 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_sampler_ir.cc @@ -0,0 +1,93 @@ +/** + * 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/engine/ir/datasetops/source/samplers/subset_sampler_ir.h" +#include "minddata/dataset/engine/datasetops/source/sampler/subset_sampler.h" +#include "minddata/dataset/core/config_manager.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/util/random.h" +#include "minddata/mindrecord/include/shard_distributed_sample.h" +#include "minddata/mindrecord/include/shard_operator.h" +#include "minddata/mindrecord/include/shard_pk_sample.h" +#include "minddata/mindrecord/include/shard_sample.h" +#include "minddata/mindrecord/include/shard_sequential_sample.h" +#include "minddata/mindrecord/include/shard_shuffle.h" +#endif + +namespace mindspore { +namespace dataset { + +// Constructor +SubsetSamplerObj::SubsetSamplerObj(std::vector indices, int64_t num_samples) + : indices_(std::move(indices)), num_samples_(num_samples) {} + +// Destructor +SubsetSamplerObj::~SubsetSamplerObj() = default; + +Status SubsetSamplerObj::ValidateParams() { + if (num_samples_ < 0) { + RETURN_STATUS_UNEXPECTED("SubsetRandomSampler: num_samples must be greater than or equal to 0, but got: " + + std::to_string(num_samples_)); + } + + return Status::OK(); +} + +Status SubsetSamplerObj::SamplerBuild(std::shared_ptr *sampler) { + // runtime sampler object + *sampler = std::make_shared(num_samples_, indices_); + Status s = BuildChildren(sampler); + sampler = s.IsOk() ? sampler : nullptr; + return s; +} + +#ifndef ENABLE_ANDROID +std::shared_ptr SubsetSamplerObj::BuildForMindDataset() { + // runtime mindrecord sampler object + auto mind_sampler = std::make_shared(indices_); + + return mind_sampler; +} +#endif +Status SubsetSamplerObj::to_json(nlohmann::json *const out_json) { + nlohmann::json args; + args["sampler_name"] = "SubsetSampler"; + args["indices"] = indices_; + args["num_samples"] = num_samples_; + if (!children_.empty()) { + std::vector children_args; + for (auto child : children_) { + nlohmann::json child_arg; + RETURN_IF_NOT_OK(child->to_json(&child_arg)); + children_args.push_back(child_arg); + } + args["child_sampler"] = children_args; + } + *out_json = args; + return Status::OK(); +} +std::shared_ptr SubsetSamplerObj::SamplerCopy() { + auto sampler = std::make_shared(indices_, num_samples_); + for (const auto &child : children_) { + Status rc = sampler->AddChildSampler(child); + if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; + } + return sampler; +} + +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_sampler_ir.h b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_sampler_ir.h new file mode 100644 index 0000000000..e72e344c67 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/subset_sampler_ir.h @@ -0,0 +1,67 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SUBSET_SAMPLER_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SUBSET_SAMPLER_IR_H_ + +#include +#include +#include +#include +#include +#include + +#include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" +#include "include/api/status.h" +#ifndef ENABLE_ANDROID +#include "minddata/mindrecord/include/shard_operator.h" +#endif + +namespace mindspore { +namespace dataset { + +// Internal Sampler class forward declaration +class SamplerRT; + +class SubsetSamplerObj : public SamplerObj { + public: + SubsetSamplerObj(std::vector indices, int64_t num_samples); + + ~SubsetSamplerObj(); + + Status SamplerBuild(std::shared_ptr *sampler) override; + + std::shared_ptr SamplerCopy() override; + +#ifndef ENABLE_ANDROID + std::shared_ptr BuildForMindDataset() override; +#endif + + /// \brief Get the arguments of node + /// \param[out] out_json JSON string of all attributes + /// \return Status of the function + Status to_json(nlohmann::json *const out_json) override; + + Status ValidateParams() override; + + protected: + const std::vector indices_; + int64_t num_samples_; +}; + +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SUBSET_SAMPLER_IR_H_ 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 new file mode 100644 index 0000000000..7f8276943f --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/weighted_random_sampler_ir.cc @@ -0,0 +1,91 @@ +/** + * 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/engine/ir/datasetops/source/samplers/weighted_random_sampler_ir.h" +#include "minddata/dataset/engine/datasetops/source/sampler/weighted_random_sampler.h" + +#include "minddata/dataset/core/config_manager.h" + +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) {} + +// Destructor +WeightedRandomSamplerObj::~WeightedRandomSamplerObj() = default; + +Status WeightedRandomSamplerObj::ValidateParams() { + if (weights_.empty()) { + RETURN_STATUS_UNEXPECTED("WeightedRandomSampler: weights vector must not be empty"); + } + int32_t zero_elem = 0; + for (int32_t i = 0; i < weights_.size(); ++i) { + if (weights_[i] < 0) { + RETURN_STATUS_UNEXPECTED("WeightedRandomSampler: weights vector must not contain negative number, got: " + + std::to_string(weights_[i])); + } + if (weights_[i] == 0.0) { + zero_elem++; + } + } + if (zero_elem == weights_.size()) { + RETURN_STATUS_UNEXPECTED("WeightedRandomSampler: elements of weights vector must not be all zero"); + } + if (num_samples_ < 0) { + RETURN_STATUS_UNEXPECTED("WeightedRandomSampler: num_samples must be greater than or equal to 0, but got: " + + std::to_string(num_samples_)); + } + return Status::OK(); +} + +Status WeightedRandomSamplerObj::to_json(nlohmann::json *const out_json) { + nlohmann::json args; + args["sampler_name"] = "WeightedRandomSampler"; + args["weights"] = weights_; + args["num_samples"] = num_samples_; + args["replacement"] = replacement_; + if (!children_.empty()) { + std::vector children_args; + for (auto child : children_) { + nlohmann::json child_arg; + RETURN_IF_NOT_OK(child->to_json(&child_arg)); + children_args.push_back(child_arg); + } + args["child_sampler"] = children_args; + } + *out_json = args; + return Status::OK(); +} + +Status WeightedRandomSamplerObj::SamplerBuild(std::shared_ptr *sampler) { + *sampler = std::make_shared(num_samples_, weights_, replacement_); + Status s = BuildChildren(sampler); + sampler = s.IsOk() ? sampler : nullptr; + return s; +} +std::shared_ptr WeightedRandomSamplerObj::SamplerCopy() { + auto sampler = std::make_shared(weights_, num_samples_, replacement_); + for (const auto &child : children_) { + Status rc = sampler->AddChildSampler(child); + if (rc.IsError()) MS_LOG(ERROR) << "Error in copying the sampler. Message: " << rc; + } + return sampler; +} + +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/weighted_random_sampler_ir.h b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/weighted_random_sampler_ir.h new file mode 100644 index 0000000000..9661c32199 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/engine/ir/datasetops/source/samplers/weighted_random_sampler_ir.h @@ -0,0 +1,64 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_WEIGHTED_RANDOM_SAMPLER_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_WEIGHTED_RANDOM_SAMPLER_IR_H_ + +#include +#include +#include +#include +#include +#include + +#include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" +#include "include/api/status.h" +#ifndef ENABLE_ANDROID +#include "minddata/mindrecord/include/shard_operator.h" +#endif + +namespace mindspore { +namespace dataset { + +// Internal Sampler class forward declaration +class SamplerRT; + +class WeightedRandomSamplerObj : public SamplerObj { + public: + explicit WeightedRandomSamplerObj(std::vector weights, int64_t num_samples = 0, bool replacement = true); + + ~WeightedRandomSamplerObj(); + + Status SamplerBuild(std::shared_ptr *sampler) override; + + std::shared_ptr SamplerCopy() override; + + /// \brief Get the arguments of node + /// \param[out] out_json JSON string of all attributes + /// \return Status of the function + Status to_json(nlohmann::json *const out_json) override; + + Status ValidateParams() override; + + private: + const std::vector weights_; + int64_t num_samples_; + bool replacement_; +}; + +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_WEIGHTED_RANDOM_SAMPLER_IR_H_ diff --git a/mindspore/ccsrc/minddata/dataset/engine/opt/optional/tensor_op_fusion_pass.cc b/mindspore/ccsrc/minddata/dataset/engine/opt/optional/tensor_op_fusion_pass.cc index 23e6e7839b..e934dc4d2e 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/opt/optional/tensor_op_fusion_pass.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/opt/optional/tensor_op_fusion_pass.cc @@ -24,7 +24,9 @@ #include "minddata/dataset/kernels/image/random_crop_and_resize_op.h" #include "minddata/dataset/kernels/image/random_crop_decode_resize_op.h" #include "minddata/dataset/kernels/ir/data/transforms_ir.h" -#include "minddata/dataset/kernels/ir/vision/vision_ir.h" +#include "minddata/dataset/kernels/ir/vision/decode_ir.h" +#include "minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.h" +#include "minddata/dataset/kernels/ir/vision/random_resized_crop_ir.h" namespace mindspore { namespace dataset { diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/CMakeLists.txt index 58973ac38f..863fe6a045 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/CMakeLists.txt @@ -2,7 +2,52 @@ file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc" set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) set(DATASET_KERNELS_IR_VISION_SRC_FILES - vision_ir.cc + affine_ir.cc + auto_contrast_ir.cc + bounding_box_augment_ir.cc + center_crop_ir.cc + crop_ir.cc + cutmix_batch_ir.cc + cutout_ir.cc + decode_ir.cc + equalize_ir.cc + hwc_to_chw_ir.cc + invert_ir.cc + mixup_batch_ir.cc + normalize_ir.cc + normalize_pad_ir.cc + pad_ir.cc + random_affine_ir.cc + random_color_adjust_ir.cc + random_color_ir.cc + random_crop_decode_resize_ir.cc + random_crop_ir.cc + random_crop_with_bbox_ir.cc + random_horizontal_flip_ir.cc + random_horizontal_flip_with_bbox_ir.cc + random_posterize_ir.cc + random_resized_crop_ir.cc + random_resized_crop_with_bbox_ir.cc + random_resize_ir.cc + random_resize_with_bbox_ir.cc + random_rotation_ir.cc + random_select_subpolicy_ir.cc + random_sharpness_ir.cc + random_solarize_ir.cc + random_vertical_flip_ir.cc + random_vertical_flip_with_bbox_ir.cc + rescale_ir.cc + resize_ir.cc + resize_preserve_ar_ir.cc + resize_with_bbox_ir.cc + rgba_to_bgr_ir.cc + rgba_to_rgb_ir.cc + rgb_to_gray_ir.cc + rotate_ir.cc + softdvpp_decode_random_crop_resize_jpeg_ir.cc + softdvpp_decode_resize_jpeg_ir.cc + swap_red_blue_ir.cc + uniform_aug_ir.cc ) if(ENABLE_ACL) diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.cc new file mode 100644 index 0000000000..25f6286311 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.cc @@ -0,0 +1,86 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/affine_ir.h" + +#include "minddata/dataset/kernels/image/affine_op.h" + +#include "minddata/dataset/kernels/ir/validators.h" + +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) + : degrees_(degrees), + translation_(translation), + scale_(scale), + shear_(shear), + interpolation_(interpolation), + fill_value_(fill_value) {} + +AffineOperation::~AffineOperation() = default; + +std::string AffineOperation::Name() const { return kAffineOperation; } + +Status AffineOperation::ValidateParams() { + // Translate + if (translation_.size() != 2) { + std::string err_msg = + "Affine: translate expecting size 2, got: translation.size() = " + std::to_string(translation_.size()); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + RETURN_IF_NOT_OK(ValidateScalar("Affine", "translate", translation_[0], {-1, 1}, false, false)); + RETURN_IF_NOT_OK(ValidateScalar("Affine", "translate", translation_[1], {-1, 1}, false, false)); + + // Shear + if (shear_.size() != 2) { + 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); + } + // Fill Value + RETURN_IF_NOT_OK(ValidateVectorFillvalue("Affine", fill_value_)); + + return Status::OK(); +} + +std::shared_ptr AffineOperation::Build() { + std::shared_ptr tensor_op = + std::make_shared(degrees_, translation_, scale_, shear_, interpolation_, fill_value_); + return tensor_op; +} + +Status AffineOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["degrees"] = degrees_; + args["translate"] = translation_; + args["scale"] = scale_; + args["shear"] = shear_; + args["resample"] = interpolation_; + args["fill_value"] = fill_value_; + *out_json = args; + return Status::OK(); +} + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.h new file mode 100644 index 0000000000..66bd355dd8 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.h @@ -0,0 +1,66 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_AFFINE_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_AFFINE_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kAffineOperation[] = "Affine"; + +class AffineOperation : public TensorOperation { + public: + explicit AffineOperation(float_t degrees, const std::vector &translation, float scale, + const std::vector &shear, InterpolationMode interpolation, + const std::vector &fill_value); + + ~AffineOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + float degrees_; + std::vector translation_; + float scale_; + std::vector shear_; + InterpolationMode interpolation_; + std::vector fill_value_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_AFFINE_IR_H_ 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 new file mode 100644 index 0000000000..25fb45e985 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_contrast_ir.cc @@ -0,0 +1,75 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/auto_contrast_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/auto_contrast_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// AutoContrastOperation +AutoContrastOperation::AutoContrastOperation(float cutoff, std::vector ignore) + : cutoff_(cutoff), ignore_(ignore) {} + +AutoContrastOperation::~AutoContrastOperation() = default; + +std::string AutoContrastOperation::Name() const { return kAutoContrastOperation; } + +Status AutoContrastOperation::ValidateParams() { + if (cutoff_ < 0 || cutoff_ > 100) { + std::string err_msg = "AutoContrast: cutoff has to be between 0 and 100, got: " + std::to_string(cutoff_); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + + for (uint32_t single_ignore : ignore_) { + if (single_ignore > 255) { + 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; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + } + return Status::OK(); +} + +std::shared_ptr AutoContrastOperation::Build() { + std::shared_ptr tensor_op = std::make_shared(cutoff_, ignore_); + return tensor_op; +} + +Status AutoContrastOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["cutoff"] = cutoff_; + args["ignore"] = ignore_; + *out_json = args; + return Status::OK(); +} +#endif + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_contrast_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_contrast_ir.h new file mode 100644 index 0000000000..c850a1bd74 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_contrast_ir.h @@ -0,0 +1,60 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_AUTO_CONTRAST_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_AUTO_CONTRAST_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kAutoContrastOperation[] = "AutoContrast"; + +class AutoContrastOperation : public TensorOperation { + public: + explicit AutoContrastOperation(float cutoff, std::vector ignore); + + ~AutoContrastOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + float cutoff_; + std::vector ignore_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_AUTO_CONTRAST_IR_H_ 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 new file mode 100644 index 0000000000..2c4891bbbd --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.cc @@ -0,0 +1,63 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/bounding_box_augment_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +BoundingBoxAugmentOperation::BoundingBoxAugmentOperation(std::shared_ptr transform, float ratio) + : transform_(transform), ratio_(ratio) {} + +BoundingBoxAugmentOperation::~BoundingBoxAugmentOperation() = default; + +std::string BoundingBoxAugmentOperation::Name() const { return kBoundingBoxAugmentOperation; } + +Status BoundingBoxAugmentOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateVectorTransforms("BoundingBoxAugment", {transform_})); + RETURN_IF_NOT_OK(ValidateScalar("BoundingBoxAugment", "ratio", ratio_, {0.0, 1.0}, false, false)); + return Status::OK(); +} + +std::shared_ptr BoundingBoxAugmentOperation::Build() { + std::shared_ptr tensor_op = std::make_shared(transform_->Build(), ratio_); + return tensor_op; +} + +Status BoundingBoxAugmentOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args, transform_args; + RETURN_IF_NOT_OK(transform_->to_json(&transform_args)); + args["transform"] = transform_args; + args["ratio"] = ratio_; + *out_json = args; + return Status::OK(); +} +#endif + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.h new file mode 100644 index 0000000000..2d9fbd9940 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.h @@ -0,0 +1,60 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_BOUNDING_BOX_AUGMENT_IR_H__ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_BOUNDING_BOX_AUGMENT_IR_H__ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kBoundingBoxAugmentOperation[] = "BoundingBoxAugment"; + +class BoundingBoxAugmentOperation : public TensorOperation { + public: + explicit BoundingBoxAugmentOperation(std::shared_ptr transform, float ratio); + + ~BoundingBoxAugmentOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::shared_ptr transform_; + float ratio_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_BOUNDING_BOX_AUGMENT_IR_H__ 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 new file mode 100644 index 0000000000..0bfffb4f2f --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/center_crop_ir.cc @@ -0,0 +1,60 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/center_crop_ir.h" + +#include "minddata/dataset/kernels/image/center_crop_op.h" + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +CenterCropOperation::CenterCropOperation(std::vector size) : size_(size) {} + +CenterCropOperation::~CenterCropOperation() = default; + +std::string CenterCropOperation::Name() const { return kCenterCropOperation; } + +Status CenterCropOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateVectorSize("CenterCrop", size_)); + return Status::OK(); +} + +std::shared_ptr CenterCropOperation::Build() { + int32_t crop_height = size_[0]; + int32_t crop_width = size_[0]; + + // User has specified crop_width. + if (size_.size() == 2) { + crop_width = size_[1]; + } + + std::shared_ptr tensor_op = std::make_shared(crop_height, crop_width); + return tensor_op; +} + +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/center_crop_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/center_crop_ir.h new file mode 100644 index 0000000000..52ad5ba3f6 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/center_crop_ir.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_CENTER_CROP_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_CENTER_CROP_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kCenterCropOperation[] = "CenterCrop"; + +class CenterCropOperation : public TensorOperation { + public: + explicit CenterCropOperation(std::vector size); + + ~CenterCropOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector size_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_CENTER_CROP_IR_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.cc new file mode 100644 index 0000000000..4cc4fe6a16 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.cc @@ -0,0 +1,69 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/crop_ir.h" + +#include "minddata/dataset/kernels/image/crop_op.h" + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +CropOperation::CropOperation(std::vector coordinates, std::vector size) + : coordinates_(coordinates), size_(size) {} + +CropOperation::~CropOperation() = default; + +std::string CropOperation::Name() const { return kCropOperation; } + +Status CropOperation::ValidateParams() { + // We have to limit crop size due to library restrictions, optimized to only iterate over size_ once + // 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) { + std::string err_msg = "Crop: coordinates must be a vector of two values"; + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + RETURN_IF_NOT_OK(ValidateVectorNonNegative("Crop", "coordinates", coordinates_)); + return Status::OK(); +} + +std::shared_ptr CropOperation::Build() { + int32_t x, y, height, width; + + x = coordinates_[0]; + y = coordinates_[1]; + + height = size_[0]; + width = size_[0]; + // User has specified crop_width. + if (size_.size() == 2) { + width = size_[1]; + } + + std::shared_ptr tensor_op = std::make_shared(x, y, height, width); + return tensor_op; +} + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.h new file mode 100644 index 0000000000..824165cfdc --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.h @@ -0,0 +1,58 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_CROP_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_CROP_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kCropOperation[] = "Crop"; + +class CropOperation : public TensorOperation { + public: + CropOperation(std::vector coordinates, std::vector size); + + ~CropOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + private: + std::vector coordinates_; + std::vector size_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_CROP_IR_H_ 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 new file mode 100644 index 0000000000..8a5aca11ac --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutmix_batch_ir.cc @@ -0,0 +1,64 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/cutmix_batch_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/cutmix_batch_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID +// CutMixBatchOperation +CutMixBatchOperation::CutMixBatchOperation(ImageBatchFormat image_batch_format, float alpha, float prob) + : image_batch_format_(image_batch_format), alpha_(alpha), prob_(prob) {} + +CutMixBatchOperation::~CutMixBatchOperation() = default; + +std::string CutMixBatchOperation::Name() const { return kCutMixBatchOperation; } + +Status CutMixBatchOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateFloatScalarPositive("CutMixBatch", "alpha", alpha_)); + RETURN_IF_NOT_OK(ValidateProbability("CutMixBatch", prob_)); + return Status::OK(); +} + +std::shared_ptr CutMixBatchOperation::Build() { + std::shared_ptr tensor_op = std::make_shared(image_batch_format_, alpha_, prob_); + return tensor_op; +} + +Status CutMixBatchOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["image_batch_format"] = image_batch_format_; + args["alpha"] = alpha_; + args["prob"] = prob_; + *out_json = args; + return Status::OK(); +} + +#endif + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutmix_batch_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutmix_batch_ir.h new file mode 100644 index 0000000000..7eb79582d2 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutmix_batch_ir.h @@ -0,0 +1,61 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_CUTMIX_BATCH_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_CUTMIX_BATCH_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kCutMixBatchOperation[] = "CutMixBatch"; + +class CutMixBatchOperation : public TensorOperation { + public: + explicit CutMixBatchOperation(ImageBatchFormat image_batch_format, float alpha, float prob); + + ~CutMixBatchOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + float alpha_; + float prob_; + ImageBatchFormat image_batch_format_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_CUTMIX_BATCH_IR_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutout_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutout_ir.cc new file mode 100644 index 0000000000..2adeec64e8 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutout_ir.cc @@ -0,0 +1,61 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/cutout_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/cut_out_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +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; + +std::string CutOutOperation::Name() const { return kCutOutOperation; } + +Status CutOutOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateIntScalarPositive("CutOut", "length", length_)); + RETURN_IF_NOT_OK(ValidateIntScalarPositive("CutOut", "num_patches", num_patches_)); + return Status::OK(); +} + +std::shared_ptr CutOutOperation::Build() { + std::shared_ptr tensor_op = std::make_shared(length_, length_, num_patches_, false, 0, 0, 0); + return tensor_op; +} + +Status CutOutOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["length"] = length_; + args["num_patches"] = num_patches_; + *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.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutout_ir.h new file mode 100644 index 0000000000..1701d4fad5 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutout_ir.h @@ -0,0 +1,60 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_CUTOUT_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_CUTOUT_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kCutOutOperation[] = "CutOut"; + +class CutOutOperation : public TensorOperation { + public: + explicit CutOutOperation(int32_t length, int32_t num_patches); + + ~CutOutOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + int32_t length_; + int32_t num_patches_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_CUTOUT_IR_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/decode_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/decode_ir.cc new file mode 100644 index 0000000000..e395948b10 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/decode_ir.cc @@ -0,0 +1,47 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/decode_ir.h" + +#include "minddata/dataset/kernels/image/decode_op.h" + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +// DecodeOperation +DecodeOperation::DecodeOperation(bool rgb) : rgb_(rgb) {} + +DecodeOperation::~DecodeOperation() = default; + +std::string DecodeOperation::Name() const { return kDecodeOperation; } + +Status DecodeOperation::ValidateParams() { return Status::OK(); } + +std::shared_ptr DecodeOperation::Build() { return std::make_shared(rgb_); } + +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/decode_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/decode_ir.h new file mode 100644 index 0000000000..d0adb47fd3 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/decode_ir.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_DECODE_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_DECODE_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kDecodeOperation[] = "Decode"; + +class DecodeOperation : public TensorOperation { + public: + explicit DecodeOperation(bool rgb); + + ~DecodeOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + bool rgb_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_DECODE_IR_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/equalize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/equalize_ir.cc new file mode 100644 index 0000000000..05df6d4bb6 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/equalize_ir.cc @@ -0,0 +1,46 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/equalize_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/equalize_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// EqualizeOperation +EqualizeOperation::~EqualizeOperation() = default; + +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/equalize_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/equalize_ir.h new file mode 100644 index 0000000000..9ff1ccf7cb --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/equalize_ir.h @@ -0,0 +1,52 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_EQUALIZE_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_EQUALIZE_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kEqualizeOperation[] = "Equalize"; + +class EqualizeOperation : public TensorOperation { + public: + ~EqualizeOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_EQUALIZE_IR_H_ 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 new file mode 100644 index 0000000000..3907536927 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/hwc_to_chw_ir.cc @@ -0,0 +1,45 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/hwc_to_chw_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/hwc_to_chw_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// HwcToChwOperation +HwcToChwOperation::~HwcToChwOperation() = default; + +std::string HwcToChwOperation::Name() const { return kHwcToChwOperation; } + +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/hwc_to_chw_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/hwc_to_chw_ir.h new file mode 100644 index 0000000000..87440f3fb8 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/hwc_to_chw_ir.h @@ -0,0 +1,52 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_HWC_TO_CHW_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_HWC_TO_CHW_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kHwcToChwOperation[] = "HwcToChw"; + +class HwcToChwOperation : public TensorOperation { + public: + ~HwcToChwOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_HWC_TO_CHW_IR_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/invert_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/invert_ir.cc new file mode 100644 index 0000000000..e5ed71c679 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/invert_ir.cc @@ -0,0 +1,46 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/invert_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/invert_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// InvertOperation +InvertOperation::~InvertOperation() = default; + +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/invert_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/invert_ir.h new file mode 100644 index 0000000000..606ad99707 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/invert_ir.h @@ -0,0 +1,52 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_INVERT_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_INVERT_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kInvertOperation[] = "Invert"; + +class InvertOperation : public TensorOperation { + public: + ~InvertOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_INVERT_IR_H_ 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 new file mode 100644 index 0000000000..4ee9288e6a --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/mixup_batch_ir.cc @@ -0,0 +1,56 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/mixup_batch_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/mixup_batch_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// MixUpOperation +MixUpBatchOperation::MixUpBatchOperation(float alpha) : alpha_(alpha) {} + +MixUpBatchOperation::~MixUpBatchOperation() = default; + +std::string MixUpBatchOperation::Name() const { return kMixUpBatchOperation; } + +Status MixUpBatchOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateFloatScalarPositive("MixUpBatch", "alpha", alpha_)); + return Status::OK(); +} + +std::shared_ptr MixUpBatchOperation::Build() { return std::make_shared(alpha_); } + +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/mixup_batch_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/mixup_batch_ir.h new file mode 100644 index 0000000000..9141d0ec89 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/mixup_batch_ir.h @@ -0,0 +1,58 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_MIXUP_BATCH_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_MIXUP_BATCH_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kMixUpBatchOperation[] = "MixUpBatch"; + +class MixUpBatchOperation : public TensorOperation { + public: + explicit MixUpBatchOperation(float alpha); + + ~MixUpBatchOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + float alpha_; +}; +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_MIXUP_BATCH_IR_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.cc new file mode 100644 index 0000000000..918342b013 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.cc @@ -0,0 +1,55 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/normalize_ir.h" + +#include "minddata/dataset/kernels/image/normalize_op.h" + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +// NormalizeOperation +NormalizeOperation::NormalizeOperation(std::vector mean, std::vector std) : mean_(mean), std_(std) {} + +NormalizeOperation::~NormalizeOperation() = default; + +std::string NormalizeOperation::Name() const { return kNormalizeOperation; } + +Status NormalizeOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateVectorMeanStd("Normalize", mean_, std_)); + return Status::OK(); +} + +std::shared_ptr NormalizeOperation::Build() { + return std::make_shared(mean_[0], mean_[1], mean_[2], std_[0], std_[1], std_[2]); +} + +Status NormalizeOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["mean"] = mean_; + args["std"] = std_; + *out_json = args; + return Status::OK(); +} + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.h new file mode 100644 index 0000000000..cd17b53c38 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.h @@ -0,0 +1,60 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_NORMALIZE_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_NORMALIZE_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kNormalizeOperation[] = "Normalize"; + +class NormalizeOperation : public TensorOperation { + public: + NormalizeOperation(std::vector mean, std::vector std); + + ~NormalizeOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector mean_; + std::vector std_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_NORMALIZE_IR_H_ 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 new file mode 100644 index 0000000000..a55a7c7380 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_pad_ir.cc @@ -0,0 +1,67 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/normalize_pad_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/normalize_pad_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID +// NormalizePadOperation +NormalizePadOperation::NormalizePadOperation(const std::vector &mean, const std::vector &std, + const std::string &dtype) + : mean_(mean), std_(std), dtype_(dtype) {} + +NormalizePadOperation::~NormalizePadOperation() = default; + +std::string NormalizePadOperation::Name() const { return kNormalizePadOperation; } + +Status NormalizePadOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateVectorMeanStd("NormalizePad", mean_, std_)); + if (dtype_ != "float32" && dtype_ != "float16") { + std::string err_msg = "NormalizePad: dtype must be float32 or float16, but got: " + dtype_; + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + return Status::OK(); +} + +std::shared_ptr NormalizePadOperation::Build() { + return std::make_shared(mean_[0], mean_[1], mean_[2], std_[0], std_[1], std_[2], dtype_); +} + +Status NormalizePadOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["mean"] = mean_; + args["std"] = std_; + args["dtype"] = dtype_; + *out_json = args; + return Status::OK(); +} +#endif + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_pad_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_pad_ir.h new file mode 100644 index 0000000000..4859bbce5e --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_pad_ir.h @@ -0,0 +1,60 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_NORMALIZE_PAD_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_NORMALIZE_PAD_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kNormalizePadOperation[] = "NormalizePad"; + +class NormalizePadOperation : public TensorOperation { + public: + NormalizePadOperation(const std::vector &mean, const std::vector &std, const std::string &dtype); + + ~NormalizePadOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector mean_; + std::vector std_; + std::string dtype_; +}; +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_NORMALIZE_PAD_IR_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.cc new file mode 100644 index 0000000000..b7dd320866 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.cc @@ -0,0 +1,99 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/pad_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/pad_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +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) {} + +PadOperation::~PadOperation() = default; + +std::string PadOperation::Name() const { return kPadOperation; } + +Status PadOperation::ValidateParams() { + // padding + RETURN_IF_NOT_OK(ValidateVectorPadding("Pad", padding_)); + // fill_value + RETURN_IF_NOT_OK(ValidateVectorFillvalue("Pad", fill_value_)); + return Status::OK(); +} + +std::shared_ptr PadOperation::Build() { + 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]; + break; + case 2: + pad_left = padding_[0]; + pad_top = padding_[0]; + pad_right = padding_[1]; + pad_bottom = padding_[1]; + break; + default: + pad_left = padding_[0]; + pad_top = padding_[1]; + pad_right = padding_[2]; + pad_bottom = padding_[3]; + } + uint8_t fill_r, fill_g, fill_b; + + fill_r = fill_value_[0]; + fill_g = fill_value_[0]; + fill_b = fill_value_[0]; + + if (fill_value_.size() == 3) { + fill_r = fill_value_[0]; + fill_g = fill_value_[1]; + fill_b = fill_value_[2]; + } + + std::shared_ptr tensor_op = + std::make_shared(pad_top, pad_bottom, pad_left, pad_right, padding_mode_, fill_r, fill_g, fill_b); + return tensor_op; +} + +Status PadOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["padding"] = padding_; + args["fill_value"] = fill_value_; + args["padding_mode"] = padding_mode_; + *out_json = args; + return Status::OK(); +} +#endif + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.h new file mode 100644 index 0000000000..051edc3be9 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.h @@ -0,0 +1,61 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_PAD_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_PAD_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kPadOperation[] = "Pad"; + +class PadOperation : public TensorOperation { + public: + PadOperation(std::vector padding, std::vector fill_value, BorderType padding_mode); + + ~PadOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector padding_; + std::vector fill_value_; + BorderType padding_mode_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_PAD_IR_H_ 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 new file mode 100644 index 0000000000..8b16182978 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_affine_ir.cc @@ -0,0 +1,146 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_affine_ir.h" + +#include "minddata/dataset/kernels/image/random_affine_op.h" + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +// RandomAffineOperation +RandomAffineOperation::RandomAffineOperation(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) { + random_op_ = true; +} + +RandomAffineOperation::~RandomAffineOperation() = default; + +std::string RandomAffineOperation::Name() const { return kRandomAffineOperation; } + +Status RandomAffineOperation::ValidateParams() { + // Degrees + if (degrees_.size() != 2) { + 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]); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + // Translate + if (translate_range_.size() != 2 && translate_range_.size() != 4) { + 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]) { + 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]); + 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]) { + 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]); + 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)); + } + // Scale + RETURN_IF_NOT_OK(ValidateVectorScale("RandomAffine", scale_range_)); + // Shear + if (shear_ranges_.size() != 2 && shear_ranges_.size() != 4) { + 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]) { + 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]); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + if (shear_ranges_.size() == 4 && shear_ranges_[2] > shear_ranges_[3]) { + 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]); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + // Fill Value + RETURN_IF_NOT_OK(ValidateVectorFillvalue("RandomAffine", fill_value_)); + return Status::OK(); +} + +std::shared_ptr RandomAffineOperation::Build() { + if (shear_ranges_.size() == 2) { + shear_ranges_.resize(4); + } + if (translate_range_.size() == 2) { + translate_range_.resize(4); + } + 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]; + } + + auto tensor_op = std::make_shared(degrees_, translate_range_, scale_range_, shear_ranges_, + interpolation_, fill_value); + return tensor_op; +} + +Status RandomAffineOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["degrees"] = degrees_; + args["translate"] = translate_range_; + args["scale"] = scale_range_; + args["shear"] = shear_ranges_; + args["resample"] = interpolation_; + args["fill_value"] = fill_value_; + *out_json = args; + return Status::OK(); +} + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_affine_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_affine_ir.h new file mode 100644 index 0000000000..57c816a97b --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_affine_ir.h @@ -0,0 +1,66 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_AFFINE_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_AFFINE_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomAffineOperation[] = "RandomAffine"; + +class RandomAffineOperation : public TensorOperation { + public: + RandomAffineOperation(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); + + ~RandomAffineOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + 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_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_AFFINE_IR_H_ 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 new file mode 100644 index 0000000000..b68eadcf5b --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_adjust_ir.cc @@ -0,0 +1,97 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_color_adjust_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_color_adjust_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// RandomColorAdjustOperation. +RandomColorAdjustOperation::RandomColorAdjustOperation(std::vector brightness, std::vector contrast, + std::vector saturation, std::vector hue) + : brightness_(brightness), contrast_(contrast), saturation_(saturation), hue_(hue) { + random_op_ = true; +} + +RandomColorAdjustOperation::~RandomColorAdjustOperation() = default; + +std::string RandomColorAdjustOperation::Name() const { return kRandomColorAdjustOperation; } + +Status RandomColorAdjustOperation::ValidateParams() { + // brightness + RETURN_IF_NOT_OK(ValidateVectorColorAttribute("RandomColorAdjust", "brightness", brightness_, {0})); + // contrast + RETURN_IF_NOT_OK(ValidateVectorColorAttribute("RandomColorAdjust", "contrast", contrast_, {0})); + // saturation + RETURN_IF_NOT_OK(ValidateVectorColorAttribute("RandomColorAdjust", "saturation", saturation_, {0})); + // hue + RETURN_IF_NOT_OK(ValidateVectorColorAttribute("RandomColorAdjust", "hue", hue_, {-0.5, 0.5})); + return Status::OK(); +} + +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]; + + if (brightness_.size() == 2) brightness_ub = brightness_[1]; + + contrast_lb = contrast_[0]; + contrast_ub = contrast_[0]; + + if (contrast_.size() == 2) contrast_ub = contrast_[1]; + + saturation_lb = saturation_[0]; + saturation_ub = saturation_[0]; + + if (saturation_.size() == 2) saturation_ub = saturation_[1]; + + hue_lb = hue_[0]; + hue_ub = hue_[0]; + + if (hue_.size() == 2) hue_ub = hue_[1]; + + std::shared_ptr tensor_op = std::make_shared( + brightness_lb, brightness_ub, contrast_lb, contrast_ub, saturation_lb, saturation_ub, hue_lb, hue_ub); + return tensor_op; +} + +Status RandomColorAdjustOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["brightness"] = brightness_; + args["contrast"] = contrast_; + args["saturation"] = saturation_; + args["hue"] = hue_; + *out_json = args; + return Status::OK(); +} +#endif + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_adjust_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_adjust_ir.h new file mode 100644 index 0000000000..c637219a08 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_adjust_ir.h @@ -0,0 +1,63 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_COLOR_ADJUST_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_COLOR_ADJUST_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomColorAdjustOperation[] = "RandomColorAdjust"; + +class RandomColorAdjustOperation : public TensorOperation { + public: + RandomColorAdjustOperation(std::vector brightness, std::vector contrast, std::vector saturation, + std::vector hue); + + ~RandomColorAdjustOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector brightness_; + std::vector contrast_; + std::vector saturation_; + std::vector hue_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_COLOR_ADJUST_IR_H_ 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 new file mode 100644 index 0000000000..49a26e162e --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_ir.cc @@ -0,0 +1,72 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_color_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_color_op.h" + +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +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; } + +RandomColorOperation::~RandomColorOperation() = default; + +std::string RandomColorOperation::Name() const { return kRandomColorOperation; } + +Status RandomColorOperation::ValidateParams() { + if (t_lb_ < 0 || t_ub_ < 0) { + std::string err_msg = + "RandomColor: lower bound or upper bound must be greater than or equal to 0, got t_lb: " + std::to_string(t_lb_) + + ", t_ub: " + std::to_string(t_ub_); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + if (t_lb_ > t_ub_) { + std::string err_msg = + "RandomColor: lower bound must be less or equal to upper bound, got t_lb: " + std::to_string(t_lb_) + + ", t_ub: " + std::to_string(t_ub_); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + return Status::OK(); +} + +std::shared_ptr RandomColorOperation::Build() { + std::shared_ptr tensor_op = std::make_shared(t_lb_, t_ub_); + return tensor_op; +} + +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_color_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_ir.h new file mode 100644 index 0000000000..756bca03d6 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_ir.h @@ -0,0 +1,60 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_COLOR_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_COLOR_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomColorOperation[] = "RandomColor"; + +class RandomColorOperation : public TensorOperation { + public: + RandomColorOperation(float t_lb, float t_ub); + + ~RandomColorOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + float t_lb_; + float t_ub_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_COLOR_IR_H_ 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 new file mode 100644 index 0000000000..bdc7d9b2b5 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.cc @@ -0,0 +1,81 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_crop_decode_resize_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { +#ifndef ENABLE_ANDROID + +// RandomCropDecodeResizeOperation +RandomCropDecodeResizeOperation::RandomCropDecodeResizeOperation(std::vector size, std::vector scale, + std::vector ratio, + InterpolationMode interpolation, int32_t max_attempts) + : RandomResizedCropOperation(size, scale, ratio, interpolation, max_attempts) {} + +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]; + + // User has specified the crop_width value. + if (size_.size() == 2) { + crop_width = size_[1]; + } + + float scale_lower_bound = scale_[0]; + float scale_upper_bound = scale_[1]; + + float aspect_lower_bound = ratio_[0]; + float aspect_upper_bound = ratio_[1]; + + auto tensor_op = + std::make_shared(crop_height, crop_width, scale_lower_bound, scale_upper_bound, + aspect_lower_bound, aspect_upper_bound, interpolation_, max_attempts_); + return tensor_op; +} + +RandomCropDecodeResizeOperation::RandomCropDecodeResizeOperation(const RandomResizedCropOperation &base) + : RandomResizedCropOperation(base) {} + +Status RandomCropDecodeResizeOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["size"] = size_; + args["scale"] = scale_; + args["ratio"] = ratio_; + args["interpolation"] = interpolation_; + args["max_attempts"] = max_attempts_; + *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_decode_resize_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.h new file mode 100644 index 0000000000..fd634ac083 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.h @@ -0,0 +1,58 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_CROP_DECODE_RESIZE_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_CROP_DECODE_RESIZE_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" +#include "minddata/dataset/kernels/ir/vision/random_resized_crop_ir.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomCropDecodeResizeOperation[] = "RandomCropDecodeResize"; + +class RandomCropDecodeResizeOperation : public RandomResizedCropOperation { + public: + RandomCropDecodeResizeOperation(std::vector size, std::vector scale, std::vector ratio, + InterpolationMode interpolation, int32_t max_attempts); + + explicit RandomCropDecodeResizeOperation(const RandomResizedCropOperation &base); + + ~RandomCropDecodeResizeOperation(); + + std::shared_ptr Build() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_CROP_DECODE_RESIZE_IR_H_ 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 new file mode 100644 index 0000000000..e008322d59 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_ir.cc @@ -0,0 +1,119 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_crop_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_crop_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +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) + : TensorOperation(true), + size_(size), + padding_(padding), + pad_if_needed_(pad_if_needed), + fill_value_(fill_value), + padding_mode_(padding_mode) { + random_op_ = true; +} + +RandomCropOperation::~RandomCropOperation() = default; + +std::string RandomCropOperation::Name() const { return kRandomCropOperation; } + +Status RandomCropOperation::ValidateParams() { + // size + RETURN_IF_NOT_OK(ValidateVectorSize("RandomCrop", size_)); + // padding + RETURN_IF_NOT_OK(ValidateVectorPadding("RandomCrop", padding_)); + // fill_value + RETURN_IF_NOT_OK(ValidateVectorFillvalue("RandomCrop", fill_value_)); + return Status::OK(); +} + +std::shared_ptr RandomCropOperation::Build() { + int32_t crop_height = size_[0]; + int32_t crop_width = size_[0]; + + // User has specified the crop_width value. + if (size_.size() == 2) { + crop_width = size_[1]; + } + + 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]; + break; + case 2: + pad_left = padding_[0]; + pad_top = padding_[0]; + pad_right = padding_[1]; + pad_bottom = padding_[1]; + break; + default: + pad_left = padding_[0]; + pad_top = padding_[1]; + pad_right = padding_[2]; + pad_bottom = padding_[3]; + } + + uint8_t fill_r, fill_g, fill_b; + fill_r = fill_value_[0]; + fill_g = fill_value_[0]; + fill_b = fill_value_[0]; + + if (fill_value_.size() == 3) { + fill_r = fill_value_[0]; + fill_g = fill_value_[1]; + fill_b = fill_value_[2]; + } + + auto tensor_op = std::make_shared(crop_height, crop_width, pad_top, pad_bottom, pad_left, pad_right, + padding_mode_, pad_if_needed_, fill_r, fill_g, fill_b); + return tensor_op; +} + +Status RandomCropOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["size"] = size_; + args["padding"] = padding_; + args["pad_if_needed"] = pad_if_needed_; + args["fill_value"] = fill_value_; + args["padding_mode"] = padding_mode_; + *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.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_ir.h new file mode 100644 index 0000000000..959e29d7d7 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_ir.h @@ -0,0 +1,64 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_CROP_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_CROP_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomCropOperation[] = "RandomCrop"; + +class RandomCropOperation : public TensorOperation { + public: + RandomCropOperation(std::vector size, std::vector padding, bool pad_if_needed, + std::vector fill_value, BorderType padding_mode); + + ~RandomCropOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector size_; + std::vector padding_; + bool pad_if_needed_; + std::vector fill_value_; + BorderType padding_mode_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_CROP_IR_H_ 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 new file mode 100644 index 0000000000..8ebd2dbac3 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_with_bbox_ir.cc @@ -0,0 +1,120 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_crop_with_bbox_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_crop_with_bbox_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +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, + BorderType padding_mode) + : TensorOperation(true), + size_(size), + padding_(padding), + pad_if_needed_(pad_if_needed), + fill_value_(fill_value), + padding_mode_(padding_mode) {} + +RandomCropWithBBoxOperation::~RandomCropWithBBoxOperation() = default; + +std::string RandomCropWithBBoxOperation::Name() const { return kRandomCropWithBBoxOperation; } + +Status RandomCropWithBBoxOperation::ValidateParams() { + // size + RETURN_IF_NOT_OK(ValidateVectorSize("RandomCropWithBBox", size_)); + // padding + RETURN_IF_NOT_OK(ValidateVectorPadding("RandomCropWithBBox", padding_)); + // fill_value + RETURN_IF_NOT_OK(ValidateVectorFillvalue("RandomCropWithBBox", fill_value_)); + return Status::OK(); +} + +std::shared_ptr RandomCropWithBBoxOperation::Build() { + int32_t crop_height = size_[0]; + int32_t crop_width = size_[0]; + + // User has specified the crop_width value. + if (size_.size() == 2) { + crop_width = size_[1]; + } + + 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]; + break; + case 2: + pad_left = padding_[0]; + pad_top = padding_[0]; + pad_right = padding_[1]; + pad_bottom = padding_[1]; + break; + default: + pad_left = padding_[0]; + pad_top = padding_[1]; + pad_right = padding_[2]; + pad_bottom = padding_[3]; + } + + uint8_t fill_r, fill_g, fill_b; + fill_r = fill_value_[0]; + fill_g = fill_value_[0]; + fill_b = fill_value_[0]; + + if (fill_value_.size() == 3) { + fill_r = fill_value_[0]; + fill_g = fill_value_[1]; + fill_b = fill_value_[2]; + } + + auto tensor_op = + std::make_shared(crop_height, crop_width, pad_top, pad_bottom, pad_left, pad_right, + padding_mode_, pad_if_needed_, fill_r, fill_g, fill_b); + return tensor_op; +} + +Status RandomCropWithBBoxOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["size"] = size_; + args["padding"] = padding_; + args["pad_if_needed"] = pad_if_needed_; + args["fill_value"] = fill_value_; + args["padding_mode"] = padding_mode_; + *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.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_with_bbox_ir.h new file mode 100644 index 0000000000..d5af466f9f --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_with_bbox_ir.h @@ -0,0 +1,64 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_CROP_WITH_BBOX_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_CROP_WITH_BBOX_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomCropWithBBoxOperation[] = "RandomCropWithBBox"; + +class RandomCropWithBBoxOperation : public TensorOperation { + public: + RandomCropWithBBoxOperation(std::vector size, std::vector padding, bool pad_if_needed, + std::vector fill_value, BorderType padding_mode); + + ~RandomCropWithBBoxOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector size_; + std::vector padding_; + bool pad_if_needed_; + std::vector fill_value_; + BorderType padding_mode_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_CROP_WITH_BBOX_IR_H_ 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 new file mode 100644 index 0000000000..d694e7b959 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.cc @@ -0,0 +1,60 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_horizontal_flip_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// RandomHorizontalFlipOperation +RandomHorizontalFlipOperation::RandomHorizontalFlipOperation(float probability) + : TensorOperation(true), probability_(probability) {} + +RandomHorizontalFlipOperation::~RandomHorizontalFlipOperation() = default; + +std::string RandomHorizontalFlipOperation::Name() const { return kRandomHorizontalFlipOperation; } + +Status RandomHorizontalFlipOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateProbability("RandomHorizontalFlip", probability_)); + return Status::OK(); +} + +std::shared_ptr RandomHorizontalFlipOperation::Build() { + std::shared_ptr tensor_op = std::make_shared(probability_); + return tensor_op; +} + +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_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.h new file mode 100644 index 0000000000..e053a8ebcf --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_HORIZONTAL_FLIP_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_HORIZONTAL_FLIP_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomHorizontalFlipOperation[] = "RandomHorizontalFlip"; + +class RandomHorizontalFlipOperation : public TensorOperation { + public: + explicit RandomHorizontalFlipOperation(float probability); + + ~RandomHorizontalFlipOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + float probability_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_HORIZONTAL_FLIP_IR_H_ 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 new file mode 100644 index 0000000000..b5723ad2a7 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.cc @@ -0,0 +1,61 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_horizontal_flip_with_bbox_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// RandomHorizontalFlipWithBBoxOperation +RandomHorizontalFlipWithBBoxOperation::RandomHorizontalFlipWithBBoxOperation(float probability) + : TensorOperation(true), probability_(probability) {} + +RandomHorizontalFlipWithBBoxOperation::~RandomHorizontalFlipWithBBoxOperation() = default; + +std::string RandomHorizontalFlipWithBBoxOperation::Name() const { return kRandomHorizontalFlipWithBBoxOperation; } + +Status RandomHorizontalFlipWithBBoxOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateProbability("RandomHorizontalFlipWithBBox", probability_)); + return Status::OK(); +} + +std::shared_ptr RandomHorizontalFlipWithBBoxOperation::Build() { + std::shared_ptr tensor_op = + std::make_shared(probability_); + return tensor_op; +} + +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_horizontal_flip_with_bbox_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.h new file mode 100644 index 0000000000..4c977a1ae7 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_HORIZONTAL_FLIP_WITH_BBOX_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_HORIZONTAL_FLIP_WITH_BBOX_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomHorizontalFlipWithBBoxOperation[] = "RandomHorizontalFlipWithBBox"; + +class RandomHorizontalFlipWithBBoxOperation : public TensorOperation { + public: + explicit RandomHorizontalFlipWithBBoxOperation(float probability); + + ~RandomHorizontalFlipWithBBoxOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + float probability_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_HORIZONTAL_FLIP_WITH_BBOX_IR_H_ 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 new file mode 100644 index 0000000000..5b5681b6d9 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_posterize_ir.cc @@ -0,0 +1,81 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_posterize_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_posterize_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// RandomPosterizeOperation +RandomPosterizeOperation::RandomPosterizeOperation(const std::vector &bit_range) + : TensorOperation(true), bit_range_(bit_range) {} + +RandomPosterizeOperation::~RandomPosterizeOperation() = default; + +std::string RandomPosterizeOperation::Name() const { return kRandomPosterizeOperation; } + +Status RandomPosterizeOperation::ValidateParams() { + if (bit_range_.size() != 2) { + 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]); + 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]); + 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]); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + return Status::OK(); +} + +std::shared_ptr RandomPosterizeOperation::Build() { + std::shared_ptr tensor_op = std::make_shared(bit_range_); + return tensor_op; +} + +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_posterize_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_posterize_ir.h new file mode 100644 index 0000000000..a09a80c8a0 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_posterize_ir.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_POSTERIZE_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_POSTERIZE_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomPosterizeOperation[] = "RandomPosterize"; + +class RandomPosterizeOperation : public TensorOperation { + public: + explicit RandomPosterizeOperation(const std::vector &bit_range); + + ~RandomPosterizeOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector bit_range_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_POSTERIZE_IR_H_ 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 new file mode 100644 index 0000000000..99c17305e8 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_ir.cc @@ -0,0 +1,69 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_resize_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_resize_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// RandomResizeOperation +RandomResizeOperation::RandomResizeOperation(std::vector size) : TensorOperation(true), size_(size) {} + +RandomResizeOperation::~RandomResizeOperation() = default; + +std::string RandomResizeOperation::Name() const { return kRandomResizeOperation; } + +Status RandomResizeOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateVectorSize("RandomResize", size_)); + return Status::OK(); +} + +std::shared_ptr RandomResizeOperation::Build() { + // 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 width = 0; + + // User specified the width value. + if (size_.size() == 2) { + width = size_[1]; + } + + std::shared_ptr tensor_op = std::make_shared(height, width); + return tensor_op; +} + +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_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_ir.h new file mode 100644 index 0000000000..9bc1804653 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_ir.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZE_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZE_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomResizeOperation[] = "RandomResize"; + +class RandomResizeOperation : public TensorOperation { + public: + explicit RandomResizeOperation(std::vector size); + + ~RandomResizeOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector size_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZE_IR_H_ 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 new file mode 100644 index 0000000000..5e63855dc0 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.cc @@ -0,0 +1,70 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_resize_with_bbox_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// RandomResizeWithBBoxOperation +RandomResizeWithBBoxOperation::RandomResizeWithBBoxOperation(std::vector size) + : TensorOperation(true), size_(size) {} + +RandomResizeWithBBoxOperation::~RandomResizeWithBBoxOperation() = default; + +std::string RandomResizeWithBBoxOperation::Name() const { return kRandomResizeWithBBoxOperation; } + +Status RandomResizeWithBBoxOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateVectorSize("RandomResizeWithBBox", size_)); + return Status::OK(); +} + +std::shared_ptr RandomResizeWithBBoxOperation::Build() { + // 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 width = 0; + + // User specified the width value. + if (size_.size() == 2) { + width = size_[1]; + } + + std::shared_ptr tensor_op = std::make_shared(height, width); + return tensor_op; +} + +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_resize_with_bbox_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.h new file mode 100644 index 0000000000..7fa6f07586 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZE_WITH_BBOX_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZE_WITH_BBOX_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomResizeWithBBoxOperation[] = "RandomResizeWithBBox"; + +class RandomResizeWithBBoxOperation : public TensorOperation { + public: + explicit RandomResizeWithBBoxOperation(std::vector size); + + ~RandomResizeWithBBoxOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector size_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZE_WITH_BBOX_IR_H_ 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 new file mode 100644 index 0000000000..998ea78b20 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_ir.cc @@ -0,0 +1,92 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_resized_crop_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_crop_and_resize_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { +#ifndef ENABLE_ANDROID +RandomResizedCropOperation::RandomResizedCropOperation(const RandomResizedCropOperation &) = default; + +// RandomResizedCropOperation +RandomResizedCropOperation::RandomResizedCropOperation(std::vector size, std::vector scale, + std::vector ratio, InterpolationMode interpolation, + int32_t max_attempts) + : TensorOperation(true), + size_(size), + scale_(scale), + ratio_(ratio), + interpolation_(interpolation), + max_attempts_(max_attempts) {} + +RandomResizedCropOperation::~RandomResizedCropOperation() = default; + +std::string RandomResizedCropOperation::Name() const { return kRandomResizedCropOperation; } + +Status RandomResizedCropOperation::ValidateParams() { + // size + RETURN_IF_NOT_OK(ValidateVectorSize(Name(), size_)); + // scale + RETURN_IF_NOT_OK(ValidateVectorScale(Name(), scale_)); + // ratio + RETURN_IF_NOT_OK(ValidateVectorRatio(Name(), ratio_)); + // max_attempts + if (max_attempts_ < 1) { + std::string err_msg = + Name() + ": max_attempts must be greater than or equal to 1, got: " + std::to_string(max_attempts_); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + return Status::OK(); +} + +std::shared_ptr RandomResizedCropOperation::Build() { + int32_t height = size_[0]; + int32_t width = size_[0]; + // User specified the width value. + if (size_.size() == 2) { + width = size_[1]; + } + std::shared_ptr tensor_op = std::make_shared( + height, width, scale_[0], scale_[1], ratio_[0], ratio_[1], interpolation_, max_attempts_); + return tensor_op; +} + +Status RandomResizedCropOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["size"] = size_; + args["scale"] = scale_; + args["ratio"] = ratio_; + args["interpolation_"] = interpolation_; + args["max_attempts"] = max_attempts_; + *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_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_ir.h new file mode 100644 index 0000000000..67d9fffa53 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_ir.h @@ -0,0 +1,67 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZED_CROP_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZED_CROP_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomResizedCropOperation[] = "RandomResizedCrop"; + +class RandomResizedCropOperation : public TensorOperation { + public: + RandomResizedCropOperation(std::vector size, std::vector scale, std::vector ratio, + InterpolationMode interpolation, int32_t max_attempts); + + /// \brief default copy constructor + explicit RandomResizedCropOperation(const RandomResizedCropOperation &); + + ~RandomResizedCropOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + protected: + std::vector size_; + std::vector scale_; + std::vector ratio_; + InterpolationMode interpolation_; + int32_t max_attempts_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZED_CROP_IR_H_ 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 new file mode 100644 index 0000000000..94a1b050f4 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_with_bbox_ir.cc @@ -0,0 +1,89 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_resized_crop_with_bbox_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_crop_and_resize_with_bbox_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// RandomResizedCropWithBBoxOperation +RandomResizedCropWithBBoxOperation::RandomResizedCropWithBBoxOperation(std::vector size, + std::vector scale, + std::vector ratio, + InterpolationMode interpolation, + int32_t max_attempts) + : size_(size), scale_(scale), ratio_(ratio), interpolation_(interpolation), max_attempts_(max_attempts) {} + +RandomResizedCropWithBBoxOperation::~RandomResizedCropWithBBoxOperation() = default; + +std::string RandomResizedCropWithBBoxOperation::Name() const { return kRandomResizedCropWithBBoxOperation; } + +Status RandomResizedCropWithBBoxOperation::ValidateParams() { + // size + RETURN_IF_NOT_OK(ValidateVectorSize("RandomResizedCropWithBBox", size_)); + // scale + RETURN_IF_NOT_OK(ValidateVectorScale("RandomResizedCropWithBBox", scale_)); + // ratio + RETURN_IF_NOT_OK(ValidateVectorRatio("RandomResizedCropWithBBox", ratio_)); + // max_attempts + if (max_attempts_ < 1) { + std::string err_msg = "RandomResizedCropWithBBox: max_attempts must be greater than or equal to 1, got: " + + std::to_string(max_attempts_); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + return Status::OK(); +} + +std::shared_ptr RandomResizedCropWithBBoxOperation::Build() { + int32_t height = size_[0]; + int32_t width = size_[0]; + // User specified the width value. + if (size_.size() == 2) { + width = size_[1]; + } + std::shared_ptr tensor_op = std::make_shared( + height, width, scale_[0], scale_[1], ratio_[0], ratio_[1], interpolation_, max_attempts_); + return tensor_op; +} + +Status RandomResizedCropWithBBoxOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["size"] = size_; + args["scale"] = scale_; + args["ratio"] = ratio_; + args["interpolation_"] = interpolation_; + args["max_attempts"] = max_attempts_; + *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.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_with_bbox_ir.h new file mode 100644 index 0000000000..22255cd4a3 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_with_bbox_ir.h @@ -0,0 +1,66 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZED_CROP_WITH_BBOX_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZED_CROP_WITH_BBOX_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" +#include "minddata/dataset/kernels/ir/vision/random_resized_crop_ir.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomResizedCropWithBBoxOperation[] = "RandomResizedCropWithBBoxOperation"; + +class RandomResizedCropWithBBoxOperation : public TensorOperation { + public: + explicit RandomResizedCropWithBBoxOperation(std::vector size, std::vector scale, + std::vector ratio, InterpolationMode interpolation, + int32_t max_attempts); + + ~RandomResizedCropWithBBoxOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector size_; + std::vector scale_; + std::vector ratio_; + InterpolationMode interpolation_; + int32_t max_attempts_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZED_CROP_WITH_BBOX_IR_H_ 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 new file mode 100644 index 0000000000..b203b50f5f --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_rotation_ir.cc @@ -0,0 +1,120 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_rotation_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_rotation_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { +#ifndef ENABLE_ANDROID + +// Function to create RandomRotationOperation. +RandomRotationOperation::RandomRotationOperation(std::vector degrees, InterpolationMode interpolation_mode, + bool expand, std::vector center, + std::vector fill_value) + : TensorOperation(true), + degrees_(degrees), + interpolation_mode_(interpolation_mode), + expand_(expand), + center_(center), + fill_value_(fill_value) {} + +RandomRotationOperation::~RandomRotationOperation() = default; + +std::string RandomRotationOperation::Name() const { return kRandomRotationOperation; } + +Status RandomRotationOperation::ValidateParams() { + // degrees + if (degrees_.size() != 2 && degrees_.size() != 1) { + 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])) { + 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]) + ")"; + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } else if ((degrees_.size() == 1) && (degrees_[0] < 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]); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + // center + if (center_.empty() || center_.size() != 2) { + std::string err_msg = + "RandomRotation: center must be a vector of two values, got: " + std::to_string(center_.size()); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + // fill_value + RETURN_IF_NOT_OK(ValidateVectorFillvalue("RandomRotation", fill_value_)); + return Status::OK(); +} + +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]; + } + + uint8_t fill_r, fill_g, fill_b; + fill_r = fill_value_[0]; + fill_g = fill_value_[0]; + fill_b = fill_value_[0]; + + if (fill_value_.size() == 3) { + fill_r = fill_value_[0]; + fill_g = fill_value_[1]; + fill_b = fill_value_[2]; + } + + std::shared_ptr tensor_op = std::make_shared( + start_degree, end_degree, center_[0], center_[1], interpolation_mode_, expand_, fill_r, fill_g, fill_b); + return tensor_op; +} + +Status RandomRotationOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["degrees"] = degrees_; + args["resample"] = interpolation_mode_; + args["expand"] = expand_; + args["center"] = center_; + args["fill_value"] = fill_value_; + *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.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_rotation_ir.h new file mode 100644 index 0000000000..3d492f896a --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_rotation_ir.h @@ -0,0 +1,64 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_ROTATION_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_ROTATION_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomRotationOperation[] = "RandomRotation"; + +class RandomRotationOperation : public TensorOperation { + public: + RandomRotationOperation(std::vector degrees, InterpolationMode interpolation_mode, bool expand, + std::vector center, std::vector fill_value); + + ~RandomRotationOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector degrees_; + InterpolationMode interpolation_mode_; + std::vector center_; + bool expand_; + std::vector fill_value_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_ROTATION_IR_H_ 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 new file mode 100644 index 0000000000..f3ebb8784e --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_select_subpolicy_ir.cc @@ -0,0 +1,110 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_select_subpolicy_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_select_subpolicy_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { +#ifndef ENABLE_ANDROID + +// RandomSelectSubpolicyOperation. +RandomSelectSubpolicyOperation::RandomSelectSubpolicyOperation( + std::vector, double>>> policy) + : TensorOperation(true), policy_(policy) {} + +RandomSelectSubpolicyOperation::~RandomSelectSubpolicyOperation() = default; + +std::string RandomSelectSubpolicyOperation::Name() const { return kRandomSelectSubpolicyOperation; } + +Status RandomSelectSubpolicyOperation::ValidateParams() { + if (policy_.empty()) { + std::string err_msg = "RandomSelectSubpolicy: policy must not be empty"; + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + for (int32_t i = 0; i < policy_.size(); i++) { + if (policy_[i].empty()) { + std::string err_msg = "RandomSelectSubpolicy: policy[" + std::to_string(i) + "] must not be empty"; + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + for (int32_t j = 0; j < policy_[i].size(); j++) { + if (policy_[i][j].first == nullptr) { + std::string transform_pos = "[" + std::to_string(i) + "]" + "[" + std::to_string(j) + "]"; + std::string err_msg = "RandomSelectSubpolicy: transform in policy" + transform_pos + " must not be null"; + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } else { + RETURN_IF_NOT_OK(policy_[i][j].first->ValidateParams()); + } + if (policy_[i][j].second < 0.0 || policy_[i][j].second > 1.0) { + std::string transform_pos = "[" + std::to_string(i) + "]" + "[" + std::to_string(j) + "]"; + std::string err_msg = "RandomSelectSubpolicy: probability of transform in policy" + transform_pos + + " must be between 0.0 and 1.0, got: " + std::to_string(policy_[i][j].second); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + } + } + return Status::OK(); +} + +std::shared_ptr RandomSelectSubpolicyOperation::Build() { + std::vector policy_tensor_ops; + for (int32_t i = 0; i < policy_.size(); i++) { + Subpolicy sub_policy_tensor_ops; + for (int32_t j = 0; j < policy_[i].size(); j++) { + sub_policy_tensor_ops.push_back(std::make_pair(policy_[i][j].first->Build(), policy_[i][j].second)); + } + policy_tensor_ops.push_back(sub_policy_tensor_ops); + } + std::shared_ptr tensor_op = std::make_shared(policy_tensor_ops); + return tensor_op; +} + +Status RandomSelectSubpolicyOperation::to_json(nlohmann::json *out_json) { + auto policy_tensor_ops = nlohmann::json::array(); + for (int32_t i = 0; i < policy_.size(); i++) { + auto sub_policy_tensor_ops = nlohmann::json::array(); + for (int32_t j = 0; j < policy_[i].size(); j++) { + nlohmann::json policy, args; + auto tensor_op = policy_[i][j].first; + RETURN_IF_NOT_OK(tensor_op->to_json(&args)); + policy["tensor_op"]["tensor_op_params"] = args; + policy["tensor_op"]["tensor_op_name"] = tensor_op->Name(); + policy["prob"] = policy_[i][j].second; + sub_policy_tensor_ops.push_back(policy); + } + policy_tensor_ops.push_back(sub_policy_tensor_ops); + } + (*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_select_subpolicy_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_select_subpolicy_ir.h new file mode 100644 index 0000000000..672767ca50 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_select_subpolicy_ir.h @@ -0,0 +1,60 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_SELECT_SUBPOLICY_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_SELECT_SUBPOLICY_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomSelectSubpolicyOperation[] = "RandomSelectSubpolicy"; + +class RandomSelectSubpolicyOperation : public TensorOperation { + public: + explicit RandomSelectSubpolicyOperation( + std::vector, double>>> policy); + + ~RandomSelectSubpolicyOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector, double>>> policy_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_SELECT_SUBPOLICY_IR_H_ 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 new file mode 100644 index 0000000000..57564b6944 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_sharpness_ir.cc @@ -0,0 +1,70 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_sharpness_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_sharpness_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// Function to create RandomSharpness. +RandomSharpnessOperation::RandomSharpnessOperation(std::vector degrees) + : TensorOperation(true), degrees_(degrees) {} + +RandomSharpnessOperation::~RandomSharpnessOperation() = default; + +std::string RandomSharpnessOperation::Name() const { return kRandomSharpnessOperation; } + +Status RandomSharpnessOperation::ValidateParams() { + if (degrees_.size() != 2 || degrees_[0] < 0 || degrees_[1] < 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]) { + 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); + } + return Status::OK(); +} + +std::shared_ptr RandomSharpnessOperation::Build() { + std::shared_ptr tensor_op = std::make_shared(degrees_[0], degrees_[1]); + return tensor_op; +} + +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_sharpness_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_sharpness_ir.h new file mode 100644 index 0000000000..204bba66b5 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_sharpness_ir.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_SHARPNESS_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_SHARPNESS_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomSharpnessOperation[] = "RandomSharpness"; + +class RandomSharpnessOperation : public TensorOperation { + public: + explicit RandomSharpnessOperation(std::vector degrees); + + ~RandomSharpnessOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector degrees_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_SHARPNESS_IR_H_ 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 new file mode 100644 index 0000000000..c46868fc30 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_solarize_ir.cc @@ -0,0 +1,78 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_solarize_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_solarize_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// RandomSolarizeOperation. +RandomSolarizeOperation::RandomSolarizeOperation(std::vector threshold) + : TensorOperation(true), threshold_(threshold) {} + +RandomSolarizeOperation::~RandomSolarizeOperation() = default; + +std::string RandomSolarizeOperation::Name() const { return kRandomSolarizeOperation; } + +Status RandomSolarizeOperation::ValidateParams() { + if (threshold_.size() != 2) { + 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) { + 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]) { + 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); + } + return Status::OK(); +} + +std::shared_ptr RandomSolarizeOperation::Build() { + std::shared_ptr tensor_op = std::make_shared(threshold_); + return tensor_op; +} + +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_solarize_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_solarize_ir.h new file mode 100644 index 0000000000..c067d3467e --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_solarize_ir.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_SOLARIZE_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_SOLARIZE_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomSolarizeOperation[] = "RandomSolarize"; + +class RandomSolarizeOperation : public TensorOperation { + public: + explicit RandomSolarizeOperation(std::vector threshold); + + ~RandomSolarizeOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector threshold_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_SOLARIZE_IR_H_ 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 new file mode 100644 index 0000000000..6022223c83 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_ir.cc @@ -0,0 +1,61 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_vertical_flip_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_vertical_flip_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// RandomVerticalFlipOperation +RandomVerticalFlipOperation::RandomVerticalFlipOperation(float probability) + : TensorOperation(true), probability_(probability) {} + +RandomVerticalFlipOperation::~RandomVerticalFlipOperation() = default; + +std::string RandomVerticalFlipOperation::Name() const { return kRandomVerticalFlipOperation; } + +Status RandomVerticalFlipOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateProbability("RandomVerticalFlip", probability_)); + + return Status::OK(); +} + +std::shared_ptr RandomVerticalFlipOperation::Build() { + std::shared_ptr tensor_op = std::make_shared(probability_); + return tensor_op; +} + +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_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_ir.h new file mode 100644 index 0000000000..20c97c28e4 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_ir.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_VERTICAL_FLIP_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_VERTICAL_FLIP_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomVerticalFlipOperation[] = "RandomVerticalFlip"; + +class RandomVerticalFlipOperation : public TensorOperation { + public: + explicit RandomVerticalFlipOperation(float probability); + + ~RandomVerticalFlipOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + float probability_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_VERTICAL_FLIP_IR_H_ 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 new file mode 100644 index 0000000000..2719848278 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_with_bbox_ir.cc @@ -0,0 +1,62 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/random_vertical_flip_with_bbox_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/random_vertical_flip_with_bbox_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// RandomVerticalFlipWithBBoxOperation +RandomVerticalFlipWithBBoxOperation::RandomVerticalFlipWithBBoxOperation(float probability) + : TensorOperation(true), probability_(probability) {} + +RandomVerticalFlipWithBBoxOperation::~RandomVerticalFlipWithBBoxOperation() = default; + +std::string RandomVerticalFlipWithBBoxOperation::Name() const { return kRandomVerticalFlipWithBBoxOperation; } + +Status RandomVerticalFlipWithBBoxOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateProbability("RandomVerticalFlipWithBBox", probability_)); + + return Status::OK(); +} + +std::shared_ptr RandomVerticalFlipWithBBoxOperation::Build() { + std::shared_ptr tensor_op = + std::make_shared(probability_); + return tensor_op; +} + +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/random_vertical_flip_with_bbox_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_with_bbox_ir.h new file mode 100644 index 0000000000..b9687c5989 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_with_bbox_ir.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_VERTICAL_FLIP_WITH_BBOX_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_VERTICAL_FLIP_WITH_BBOX_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRandomVerticalFlipWithBBoxOperation[] = "RandomVerticalFlipWithBBox"; + +class RandomVerticalFlipWithBBoxOperation : public TensorOperation { + public: + explicit RandomVerticalFlipWithBBoxOperation(float probability); + + ~RandomVerticalFlipWithBBoxOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + float probability_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_VERTICAL_FLIP_WITH_BBOX_IR_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.cc new file mode 100644 index 0000000000..9d173f2b69 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.cc @@ -0,0 +1,66 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/rescale_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/rescale_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// RescaleOperation +RescaleOperation::RescaleOperation(float rescale, float shift) : rescale_(rescale), shift_(shift) {} + +RescaleOperation::~RescaleOperation() = default; + +std::string RescaleOperation::Name() const { return kRescaleOperation; } + +Status RescaleOperation::ValidateParams() { + if (rescale_ < 0) { + std::string err_msg = "Rescale: rescale must be greater than or equal to 0, got: " + std::to_string(rescale_); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + return Status::OK(); +} + +std::shared_ptr RescaleOperation::Build() { + std::shared_ptr tensor_op = std::make_shared(rescale_, shift_); + return tensor_op; +} + +Status RescaleOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["rescale"] = rescale_; + args["shift"] = shift_; + *out_json = args; + return Status::OK(); +} + +#endif + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.h new file mode 100644 index 0000000000..376b2dcc5c --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.h @@ -0,0 +1,60 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RESCALE_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RESCALE_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRescaleOperation[] = "Rescale"; + +class RescaleOperation : public TensorOperation { + public: + explicit RescaleOperation(float rescale, float shift); + + ~RescaleOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + float rescale_; + float shift_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RESCALE_IR_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.cc new file mode 100644 index 0000000000..550a198dcd --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.cc @@ -0,0 +1,66 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/resize_ir.h" + +#include "minddata/dataset/kernels/image/resize_op.h" + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +// ResizeOperation +ResizeOperation::ResizeOperation(std::vector size, InterpolationMode interpolation) + : size_(size), interpolation_(interpolation) {} + +ResizeOperation::~ResizeOperation() = default; + +std::string ResizeOperation::Name() const { return kResizeOperation; } + +Status ResizeOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateVectorSize("Resize", size_)); + return Status::OK(); +} + +std::shared_ptr ResizeOperation::Build() { + // 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 width = 0; + + // User specified the width value. + if (size_.size() == 2) { + width = size_[1]; + } + + return std::make_shared(height, width, interpolation_); +} + +Status ResizeOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["size"] = size_; + args["interpolation"] = interpolation_; + *out_json = args; + return Status::OK(); +} + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.h new file mode 100644 index 0000000000..5481ca0ddf --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.h @@ -0,0 +1,60 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RESIZE_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RESIZE_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kResizeOperation[] = "Resize"; + +class ResizeOperation : public TensorOperation { + public: + explicit ResizeOperation(std::vector size, InterpolationMode interpolation_mode); + + ~ResizeOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector size_; + InterpolationMode interpolation_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RESIZE_IR_H_ 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 new file mode 100644 index 0000000000..d38213d9e4 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_preserve_ar_ir.cc @@ -0,0 +1,54 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/resize_preserve_ar_ir.h" + +#include "minddata/dataset/kernels/image/resize_preserve_ar_op.h" + +#include "minddata/dataset/kernels/ir/validators.h" + +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) {} + +ResizePreserveAROperation::~ResizePreserveAROperation() = default; + +std::string ResizePreserveAROperation::Name() const { return kResizePreserveAROperation; } + +Status ResizePreserveAROperation::ValidateParams() { return Status::OK(); } + +std::shared_ptr ResizePreserveAROperation::Build() { + return std::make_shared(height_, width_, img_orientation_); +} + +Status ResizePreserveAROperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["height"] = height_; + args["width"] = width_; + args["img_orientation"] = img_orientation_; + *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.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_preserve_ar_ir.h new file mode 100644 index 0000000000..49191dee77 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_preserve_ar_ir.h @@ -0,0 +1,61 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RESIZE_PRESERVE_AR_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RESIZE_PRESERVE_AR_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kResizePreserveAROperation[] = "ResizePreserveAR"; + +class ResizePreserveAROperation : public TensorOperation { + public: + ResizePreserveAROperation(int32_t height, int32_t width, int32_t img_orientation); + + ~ResizePreserveAROperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + int32_t height_; + int32_t width_; + int32_t img_orientation_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RESIZE_PRESERVE_AR_IR_H_ 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 new file mode 100644 index 0000000000..aacf0250b3 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.cc @@ -0,0 +1,69 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/resize_with_bbox_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID +// ResizeWithBBoxOperation +ResizeWithBBoxOperation::ResizeWithBBoxOperation(std::vector size, InterpolationMode interpolation) + : size_(size), interpolation_(interpolation) {} + +ResizeWithBBoxOperation::~ResizeWithBBoxOperation() = default; + +std::string ResizeWithBBoxOperation::Name() const { return kResizeWithBBoxOperation; } + +Status ResizeWithBBoxOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateVectorSize("ResizeWithBBox", size_)); + return Status::OK(); +} + +std::shared_ptr ResizeWithBBoxOperation::Build() { + int32_t height = size_[0]; + int32_t width = 0; + + // User specified the width value. + if (size_.size() == 2) { + width = size_[1]; + } + + return std::make_shared(height, width, interpolation_); +} + +Status ResizeWithBBoxOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["size"] = size_; + args["interpolation"] = interpolation_; + *out_json = args; + return Status::OK(); +} + +#endif + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.h new file mode 100644 index 0000000000..6f003504d4 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.h @@ -0,0 +1,60 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RESIZE_WITH_BBOX_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RESIZE_WITH_BBOX_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kResizeWithBBoxOperation[] = "ResizeWithBBox"; + +class ResizeWithBBoxOperation : public TensorOperation { + public: + explicit ResizeWithBBoxOperation(std::vector size, InterpolationMode interpolation_mode); + + ~ResizeWithBBoxOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector size_; + InterpolationMode interpolation_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RESIZE_WITH_BBOX_IR_H_ 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 new file mode 100644 index 0000000000..4e07fe41a9 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgb_to_gray_ir.cc @@ -0,0 +1,42 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/rgb_to_gray_ir.h" + +#include "minddata/dataset/kernels/image/rgb_to_gray_op.h" + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +RgbToGrayOperation::RgbToGrayOperation() = default; + +// RGB2GRAYOperation +RgbToGrayOperation::~RgbToGrayOperation() = default; + +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/rgb_to_gray_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgb_to_gray_ir.h new file mode 100644 index 0000000000..f1a0135923 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgb_to_gray_ir.h @@ -0,0 +1,54 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RGB_TO_GRAY_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RGB_TO_GRAY_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRgbToGrayOperation[] = "RgbToGray"; + +class RgbToGrayOperation : public TensorOperation { + public: + RgbToGrayOperation(); + + ~RgbToGrayOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RGB_TO_GRAY_IR_H_ 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 new file mode 100644 index 0000000000..9a2b2ca115 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_bgr_ir.cc @@ -0,0 +1,50 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/rgba_to_bgr_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/rgba_to_bgr_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// RgbaToBgrOperation. +RgbaToBgrOperation::RgbaToBgrOperation() {} + +RgbaToBgrOperation::~RgbaToBgrOperation() = default; + +std::string RgbaToBgrOperation::Name() const { return kRgbaToBgrOperation; } + +Status RgbaToBgrOperation::ValidateParams() { return Status::OK(); } + +std::shared_ptr RgbaToBgrOperation::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/rgba_to_bgr_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_bgr_ir.h new file mode 100644 index 0000000000..5b68b91581 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_bgr_ir.h @@ -0,0 +1,54 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RGBA_TO_BGR_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RGBA_TO_BGR_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRgbaToBgrOperation[] = "RgbaToBgr"; + +class RgbaToBgrOperation : public TensorOperation { + public: + RgbaToBgrOperation(); + + ~RgbaToBgrOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RGBA_TO_BGR_IR_H_ 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 new file mode 100644 index 0000000000..1f8dadc216 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_rgb_ir.cc @@ -0,0 +1,51 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/rgba_to_rgb_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/rgba_to_rgb_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// RgbaToRgbOperation. +RgbaToRgbOperation::RgbaToRgbOperation() {} + +RgbaToRgbOperation::~RgbaToRgbOperation() = default; + +std::string RgbaToRgbOperation::Name() const { return kRgbaToRgbOperation; } + +Status RgbaToRgbOperation::ValidateParams() { return Status::OK(); } + +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/rgba_to_rgb_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_rgb_ir.h new file mode 100644 index 0000000000..e6e1484e8e --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rgba_to_rgb_ir.h @@ -0,0 +1,54 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RGBA_TO_RGB_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RGBA_TO_RGB_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRgbaToRgbOperation[] = "RgbaToRgb"; + +class RgbaToRgbOperation : public TensorOperation { + public: + RgbaToRgbOperation(); + + ~RgbaToRgbOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RGBA_TO_RGB_IR_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.cc new file mode 100644 index 0000000000..dd2a5bace8 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.cc @@ -0,0 +1,46 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/rotate_ir.h" + +#include "minddata/dataset/kernels/image/rotate_op.h" + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +// RotateOperation +RotateOperation::RotateOperation() { rotate_op = std::make_shared(0); } + +RotateOperation::~RotateOperation() = default; + +std::string RotateOperation::Name() const { return kRotateOperation; } + +Status RotateOperation::ValidateParams() { return Status::OK(); } + +std::shared_ptr RotateOperation::Build() { return rotate_op; } + +void RotateOperation::setAngle(uint64_t angle_id) { + std::dynamic_pointer_cast(rotate_op)->setAngle(angle_id); +} + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.h new file mode 100644 index 0000000000..283cd43666 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_ROTATE_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_ROTATE_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kRotateOperation[] = "Rotate"; + +class RotateOperation : public TensorOperation { + public: + RotateOperation(); + + ~RotateOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + void setAngle(uint64_t angle_id); + + private: + std::shared_ptr rotate_op; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_ROTATE_IR_H_ 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 new file mode 100644 index 0000000000..46619a0101 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.cc @@ -0,0 +1,98 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_random_crop_resize_jpeg_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID + +// SoftDvppDecodeRandomCropResizeJpegOperation +SoftDvppDecodeRandomCropResizeJpegOperation::SoftDvppDecodeRandomCropResizeJpegOperation(std::vector size, + std::vector scale, + std::vector ratio, + int32_t max_attempts) + : size_(size), scale_(scale), ratio_(ratio), max_attempts_(max_attempts) {} + +SoftDvppDecodeRandomCropResizeJpegOperation::~SoftDvppDecodeRandomCropResizeJpegOperation() = default; + +std::string SoftDvppDecodeRandomCropResizeJpegOperation::Name() const { + return kSoftDvppDecodeRandomCropResizeJpegOperation; +} + +Status SoftDvppDecodeRandomCropResizeJpegOperation::ValidateParams() { + // size + RETURN_IF_NOT_OK(ValidateVectorSize("SoftDvppDecodeRandomCropResizeJpeg", size_)); + for (int32_t i = 0; i < size_.size(); i++) { + if (size_[i] % 2 == 1) { + 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; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + } + // scale + RETURN_IF_NOT_OK(ValidateVectorScale("SoftDvppDecodeRandomCropResizeJpeg", scale_)); + // ratio + RETURN_IF_NOT_OK(ValidateVectorRatio("SoftDvppDecodeRandomCropResizeJpeg", ratio_)); + // max_attempts + if (max_attempts_ < 1) { + std::string err_msg = "SoftDvppDecodeRandomCropResizeJpeg: max_attempts must be greater than or equal to 1, got: " + + std::to_string(max_attempts_); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + return Status::OK(); +} + +std::shared_ptr SoftDvppDecodeRandomCropResizeJpegOperation::Build() { + int32_t height = size_[0]; + int32_t width = size_[0]; + // User specified the width value. + if (size_.size() == 2) { + width = size_[1]; + } + + auto tensor_op = std::make_shared(height, width, scale_[0], scale_[1], + ratio_[0], ratio_[1], max_attempts_); + return tensor_op; +} + +Status SoftDvppDecodeRandomCropResizeJpegOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + args["size"] = size_; + args["scale"] = scale_; + args["ratio"] = ratio_; + args["max_attempts"] = max_attempts_; + *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_random_crop_resize_jpeg_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.h new file mode 100644 index 0000000000..0c2cf64ac4 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.h @@ -0,0 +1,63 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_SOFTDVPP_DECODE_RANDOM_CROP_RESIZE_JPEG_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_SOFTDVPP_DECODE_RANDOM_CROP_RESIZE_JPEG_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kSoftDvppDecodeRandomCropResizeJpegOperation[] = "SoftDvppDecodeRandomCropResizeJpeg"; + +class SoftDvppDecodeRandomCropResizeJpegOperation : public TensorOperation { + public: + explicit SoftDvppDecodeRandomCropResizeJpegOperation(std::vector size, std::vector scale, + std::vector ratio, int32_t max_attempts); + + ~SoftDvppDecodeRandomCropResizeJpegOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector size_; + std::vector scale_; + std::vector ratio_; + int32_t max_attempts_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_SOFTDVPP_DECODE_RANDOM_CROP_RESIZE_JPEG_IR_H_ 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 new file mode 100644 index 0000000000..e45ff9f88e --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.cc @@ -0,0 +1,75 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_resize_jpeg_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { +#ifndef ENABLE_ANDROID + +// SoftDvppDecodeResizeJpegOperation +SoftDvppDecodeResizeJpegOperation::SoftDvppDecodeResizeJpegOperation(std::vector size) : size_(size) {} + +SoftDvppDecodeResizeJpegOperation::~SoftDvppDecodeResizeJpegOperation() = default; + +std::string SoftDvppDecodeResizeJpegOperation::Name() const { return kSoftDvppDecodeResizeJpegOperation; } + +Status SoftDvppDecodeResizeJpegOperation::ValidateParams() { + RETURN_IF_NOT_OK(ValidateVectorSize("SoftDvppDecodeResizeJpeg", size_)); + for (int32_t i = 0; i < size_.size(); i++) { + if (size_[i] % 2 == 1) { + 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; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + } + return Status::OK(); +} + +std::shared_ptr SoftDvppDecodeResizeJpegOperation::Build() { + // 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 width = 0; + + // User specified the width value. + if (size_.size() == 2) { + width = size_[1]; + } + std::shared_ptr tensor_op = std::make_shared(height, width); + return tensor_op; +} + +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/softdvpp_decode_resize_jpeg_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.h new file mode 100644 index 0000000000..5b82b14932 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.h @@ -0,0 +1,59 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_SOFTDVPP_DECODE_RESIZE_JPEG_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_SOFTDVPP_DECODE_RESIZE_JPEG_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kSoftDvppDecodeResizeJpegOperation[] = "SoftDvppDecodeResizeJpeg"; + +class SoftDvppDecodeResizeJpegOperation : public TensorOperation { + public: + explicit SoftDvppDecodeResizeJpegOperation(std::vector size); + + ~SoftDvppDecodeResizeJpegOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector size_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_SOFTDVPP_DECODE_RESIZE_JPEG_IR_H_ 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 new file mode 100644 index 0000000000..5209402ab1 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/swap_red_blue_ir.cc @@ -0,0 +1,50 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/swap_red_blue_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/swap_red_blue_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { +#ifndef ENABLE_ANDROID + +// SwapRedBlueOperation. +SwapRedBlueOperation::SwapRedBlueOperation() {} + +SwapRedBlueOperation::~SwapRedBlueOperation() = default; + +std::string SwapRedBlueOperation::Name() const { return kSwapRedBlueOperation; } + +Status SwapRedBlueOperation::ValidateParams() { return Status::OK(); } + +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/swap_red_blue_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/swap_red_blue_ir.h new file mode 100644 index 0000000000..0256147272 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/swap_red_blue_ir.h @@ -0,0 +1,54 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_SWAP_RED_BLUE_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_SWAP_RED_BLUE_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kSwapRedBlueOperation[] = "SwapRedBlue"; + +class SwapRedBlueOperation : public TensorOperation { + public: + SwapRedBlueOperation(); + + ~SwapRedBlueOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_SWAP_RED_BLUE_IR_H_ 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 new file mode 100644 index 0000000000..5469998cd7 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/uniform_aug_ir.cc @@ -0,0 +1,81 @@ +/** + * 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 + +#include "minddata/dataset/kernels/ir/vision/uniform_aug_ir.h" + +#ifndef ENABLE_ANDROID +#include "minddata/dataset/kernels/image/uniform_aug_op.h" +#endif + +#include "minddata/dataset/kernels/ir/validators.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +#ifndef ENABLE_ANDROID +// UniformAugOperation +UniformAugOperation::UniformAugOperation(std::vector> transforms, int32_t num_ops) + : transforms_(transforms), num_ops_(num_ops) {} + +UniformAugOperation::~UniformAugOperation() = default; + +std::string UniformAugOperation::Name() const { return kUniformAugOperation; } + +Status UniformAugOperation::ValidateParams() { + // transforms + RETURN_IF_NOT_OK(ValidateVectorTransforms("UniformAug", transforms_)); + if (num_ops_ > transforms_.size()) { + std::string err_msg = + "UniformAug: num_ops must be less than or equal to transforms size, but got: " + std::to_string(num_ops_); + MS_LOG(ERROR) << err_msg; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + // num_ops + RETURN_IF_NOT_OK(ValidateIntScalarPositive("UniformAug", "num_ops", num_ops_)); + return Status::OK(); +} + +std::shared_ptr UniformAugOperation::Build() { + std::vector> tensor_ops; + (void)std::transform(transforms_.begin(), transforms_.end(), std::back_inserter(tensor_ops), + [](std::shared_ptr op) -> std::shared_ptr { return op->Build(); }); + std::shared_ptr tensor_op = std::make_shared(tensor_ops, num_ops_); + return tensor_op; +} + +Status UniformAugOperation::to_json(nlohmann::json *out_json) { + nlohmann::json args; + std::vector transforms; + for (auto op : transforms_) { + nlohmann::json op_item, op_args; + RETURN_IF_NOT_OK(op->to_json(&op_args)); + op_item["tensor_op_params"] = op_args; + op_item["tensor_op_name"] = op->Name(); + transforms.push_back(op_item); + } + args["transforms"] = transforms; + args["num_ops"] = num_ops_; + *out_json = args; + return Status::OK(); +} +#endif + +} // namespace vision +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/uniform_aug_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/uniform_aug_ir.h new file mode 100644 index 0000000000..f218686281 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/uniform_aug_ir.h @@ -0,0 +1,60 @@ +/** + * 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. + */ + +#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_UNIFORM_AUG_IR_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_UNIFORM_AUG_IR_H_ + +#include +#include +#include +#include +#include + +#include "include/api/status.h" +#include "minddata/dataset/include/dataset/constants.h" +#include "minddata/dataset/include/dataset/transforms.h" +#include "minddata/dataset/kernels/ir/tensor_operation.h" + +namespace mindspore { +namespace dataset { + +namespace vision { + +constexpr char kUniformAugOperation[] = "UniformAug"; + +class UniformAugOperation : public TensorOperation { + public: + explicit UniformAugOperation(std::vector> transforms, int32_t num_ops); + + ~UniformAugOperation(); + + std::shared_ptr Build() override; + + Status ValidateParams() override; + + std::string Name() const override; + + Status to_json(nlohmann::json *out_json) override; + + private: + std::vector> transforms_; + int32_t num_ops_; +}; + +} // namespace vision +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_UNIFORM_AUG_IR_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/vision_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/vision_ir.cc deleted file mode 100644 index 83a1d1a57f..0000000000 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/vision_ir.cc +++ /dev/null @@ -1,1651 +0,0 @@ -/** - * 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 - -#include "minddata/dataset/kernels/ir/vision/vision_ir.h" - -#ifndef ENABLE_ANDROID -#endif -// Kernel image headers (in alphabetical order) -#include "minddata/dataset/kernels/image/affine_op.h" -#ifndef ENABLE_ANDROID -#include "minddata/dataset/kernels/image/auto_contrast_op.h" -#include "minddata/dataset/kernels/image/bounding_box_augment_op.h" -#endif -#include "minddata/dataset/kernels/image/center_crop_op.h" -#include "minddata/dataset/kernels/image/crop_op.h" -#ifndef ENABLE_ANDROID -#include "minddata/dataset/kernels/image/cutmix_batch_op.h" -#include "minddata/dataset/kernels/image/cut_out_op.h" -#endif -#include "minddata/dataset/kernels/image/decode_op.h" -#ifndef ENABLE_ANDROID -#include "minddata/dataset/kernels/image/equalize_op.h" -#include "minddata/dataset/kernels/image/hwc_to_chw_op.h" -#include "minddata/dataset/kernels/image/invert_op.h" -#include "minddata/dataset/kernels/image/mixup_batch_op.h" -#endif -#include "minddata/dataset/kernels/image/normalize_op.h" -#include "minddata/dataset/kernels/image/normalize_pad_op.h" -#ifndef ENABLE_ANDROID -#include "minddata/dataset/kernels/image/pad_op.h" -#endif -#include "minddata/dataset/kernels/image/random_affine_op.h" -#ifndef ENABLE_ANDROID -#include "minddata/dataset/kernels/image/random_color_op.h" -#include "minddata/dataset/kernels/image/random_color_adjust_op.h" -#include "minddata/dataset/kernels/image/random_crop_and_resize_op.h" -#include "minddata/dataset/kernels/image/random_crop_op.h" -#include "minddata/dataset/kernels/image/random_crop_decode_resize_op.h" -#include "minddata/dataset/kernels/image/random_crop_with_bbox_op.h" -#include "minddata/dataset/kernels/image/random_crop_and_resize_with_bbox_op.h" -#include "minddata/dataset/kernels/image/random_horizontal_flip_op.h" -#include "minddata/dataset/kernels/image/random_horizontal_flip_with_bbox_op.h" -#include "minddata/dataset/kernels/image/random_posterize_op.h" -#include "minddata/dataset/kernels/image/random_resize_op.h" -#include "minddata/dataset/kernels/image/random_resize_with_bbox_op.h" -#include "minddata/dataset/kernels/image/random_rotation_op.h" -#include "minddata/dataset/kernels/image/random_select_subpolicy_op.h" -#include "minddata/dataset/kernels/image/random_sharpness_op.h" -#include "minddata/dataset/kernels/image/random_solarize_op.h" -#include "minddata/dataset/kernels/image/random_vertical_flip_op.h" -#include "minddata/dataset/kernels/image/random_vertical_flip_with_bbox_op.h" -#include "minddata/dataset/kernels/image/rescale_op.h" -#endif -#include "minddata/dataset/kernels/image/resize_op.h" -#ifndef ENABLE_ANDROID -#include "minddata/dataset/kernels/image/resize_with_bbox_op.h" -#include "minddata/dataset/kernels/image/rgba_to_bgr_op.h" -#include "minddata/dataset/kernels/image/rgba_to_rgb_op.h" -#endif -#include "minddata/dataset/kernels/image/resize_preserve_ar_op.h" -#include "minddata/dataset/kernels/image/rgb_to_gray_op.h" -#include "minddata/dataset/kernels/image/rotate_op.h" -#ifndef ENABLE_ANDROID -#include "minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_random_crop_resize_jpeg_op.h" -#include "minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_resize_jpeg_op.h" -#include "minddata/dataset/kernels/image/swap_red_blue_op.h" -#include "minddata/dataset/kernels/image/uniform_aug_op.h" -#endif - -#include "minddata/dataset/kernels/ir/validators.h" - -namespace mindspore { -namespace dataset { - -// Transform operations for computer vision. -namespace vision { - -/* ####################################### Derived TensorOperation classes ################################# */ - -// (In alphabetical order) - -// AffineOperation -AffineOperation::AffineOperation(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) {} - -Status AffineOperation::ValidateParams() { - // Translate - if (translation_.size() != 2) { - std::string err_msg = - "Affine: translate expecting size 2, got: translation.size() = " + std::to_string(translation_.size()); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - RETURN_IF_NOT_OK(ValidateScalar("Affine", "translate", translation_[0], {-1, 1}, false, false)); - RETURN_IF_NOT_OK(ValidateScalar("Affine", "translate", translation_[1], {-1, 1}, false, false)); - - // Shear - if (shear_.size() != 2) { - 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); - } - // Fill Value - RETURN_IF_NOT_OK(ValidateVectorFillvalue("Affine", fill_value_)); - - return Status::OK(); -} - -std::shared_ptr AffineOperation::Build() { - std::shared_ptr tensor_op = - std::make_shared(degrees_, translation_, scale_, shear_, interpolation_, fill_value_); - return tensor_op; -} - -Status AffineOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["degrees"] = degrees_; - args["translate"] = translation_; - args["scale"] = scale_; - args["shear"] = shear_; - args["resample"] = interpolation_; - args["fill_value"] = fill_value_; - *out_json = args; - return Status::OK(); -} - -#ifndef ENABLE_ANDROID - -// AutoContrastOperation -AutoContrastOperation::AutoContrastOperation(float cutoff, std::vector ignore) - : cutoff_(cutoff), ignore_(ignore) {} - -Status AutoContrastOperation::ValidateParams() { - if (cutoff_ < 0 || cutoff_ > 100) { - std::string err_msg = "AutoContrast: cutoff has to be between 0 and 100, got: " + std::to_string(cutoff_); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - - for (uint32_t single_ignore : ignore_) { - if (single_ignore > 255) { - 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; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - } - return Status::OK(); -} - -std::shared_ptr AutoContrastOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(cutoff_, ignore_); - return tensor_op; -} - -Status AutoContrastOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["cutoff"] = cutoff_; - args["ignore"] = ignore_; - *out_json = args; - return Status::OK(); -} - -// BoundingBoxAugmentOperation -BoundingBoxAugmentOperation::BoundingBoxAugmentOperation(std::shared_ptr transform, float ratio) - : transform_(transform), ratio_(ratio) {} - -Status BoundingBoxAugmentOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateVectorTransforms("BoundingBoxAugment", {transform_})); - RETURN_IF_NOT_OK(ValidateScalar("BoundingBoxAugment", "ratio", ratio_, {0.0, 1.0}, false, false)); - return Status::OK(); -} - -std::shared_ptr BoundingBoxAugmentOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(transform_->Build(), ratio_); - return tensor_op; -} - -Status BoundingBoxAugmentOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args, transform_args; - RETURN_IF_NOT_OK(transform_->to_json(&transform_args)); - args["transform"] = transform_args; - args["ratio"] = ratio_; - *out_json = args; - return Status::OK(); -} -#endif - -// CenterCropOperation -CenterCropOperation::CenterCropOperation(std::vector size) : size_(size) {} - -Status CenterCropOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateVectorSize("CenterCrop", size_)); - return Status::OK(); -} - -std::shared_ptr CenterCropOperation::Build() { - int32_t crop_height = size_[0]; - int32_t crop_width = size_[0]; - - // User has specified crop_width. - if (size_.size() == 2) { - crop_width = size_[1]; - } - - std::shared_ptr tensor_op = std::make_shared(crop_height, crop_width); - return tensor_op; -} - -Status CenterCropOperation::to_json(nlohmann::json *out_json) { - (*out_json)["size"] = size_; - return Status::OK(); -} - -// RGB2GRAYOperation -Status RgbToGrayOperation::ValidateParams() { return Status::OK(); } - -std::shared_ptr RgbToGrayOperation::Build() { return std::make_shared(); } - -// CropOperation. -CropOperation::CropOperation(std::vector coordinates, std::vector size) - : coordinates_(coordinates), size_(size) {} - -Status CropOperation::ValidateParams() { - // We have to limit crop size due to library restrictions, optimized to only iterate over size_ once - // 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) { - std::string err_msg = "Crop: coordinates must be a vector of two values"; - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - RETURN_IF_NOT_OK(ValidateVectorNonNegative("Crop", "coordinates", coordinates_)); - return Status::OK(); -} - -std::shared_ptr CropOperation::Build() { - int32_t x, y, height, width; - - x = coordinates_[0]; - y = coordinates_[1]; - - height = size_[0]; - width = size_[0]; - // User has specified crop_width. - if (size_.size() == 2) { - width = size_[1]; - } - - std::shared_ptr tensor_op = std::make_shared(x, y, height, width); - return tensor_op; -} - -#ifndef ENABLE_ANDROID -// CutMixBatchOperation -CutMixBatchOperation::CutMixBatchOperation(ImageBatchFormat image_batch_format, float alpha, float prob) - : image_batch_format_(image_batch_format), alpha_(alpha), prob_(prob) {} - -Status CutMixBatchOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateFloatScalarPositive("CutMixBatch", "alpha", alpha_)); - RETURN_IF_NOT_OK(ValidateProbability("CutMixBatch", prob_)); - return Status::OK(); -} - -std::shared_ptr CutMixBatchOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(image_batch_format_, alpha_, prob_); - return tensor_op; -} - -Status CutMixBatchOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["image_batch_format"] = image_batch_format_; - args["alpha"] = alpha_; - args["prob"] = prob_; - *out_json = args; - return Status::OK(); -} - -// CutOutOperation -CutOutOperation::CutOutOperation(int32_t length, int32_t num_patches) : length_(length), num_patches_(num_patches) {} - -Status CutOutOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateIntScalarPositive("CutOut", "length", length_)); - RETURN_IF_NOT_OK(ValidateIntScalarPositive("CutOut", "num_patches", num_patches_)); - return Status::OK(); -} - -std::shared_ptr CutOutOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(length_, length_, num_patches_, false, 0, 0, 0); - return tensor_op; -} - -Status CutOutOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["length"] = length_; - args["num_patches"] = num_patches_; - *out_json = args; - return Status::OK(); -} -#endif - -// DecodeOperation -DecodeOperation::DecodeOperation(bool rgb) : rgb_(rgb) {} - -Status DecodeOperation::ValidateParams() { return Status::OK(); } - -std::shared_ptr DecodeOperation::Build() { return std::make_shared(rgb_); } - -Status DecodeOperation::to_json(nlohmann::json *out_json) { - (*out_json)["rgb"] = rgb_; - return Status::OK(); -} -#ifndef ENABLE_ANDROID - -// EqualizeOperation -Status EqualizeOperation::ValidateParams() { return Status::OK(); } - -std::shared_ptr EqualizeOperation::Build() { return std::make_shared(); } - -// HwcToChwOperation -Status HwcToChwOperation::ValidateParams() { return Status::OK(); } - -std::shared_ptr HwcToChwOperation::Build() { return std::make_shared(); } - -// InvertOperation -Status InvertOperation::ValidateParams() { return Status::OK(); } - -std::shared_ptr InvertOperation::Build() { return std::make_shared(); } - -// MixUpOperation -MixUpBatchOperation::MixUpBatchOperation(float alpha) : alpha_(alpha) {} - -Status MixUpBatchOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateFloatScalarPositive("MixUpBatch", "alpha", alpha_)); - return Status::OK(); -} - -std::shared_ptr MixUpBatchOperation::Build() { return std::make_shared(alpha_); } - -Status MixUpBatchOperation::to_json(nlohmann::json *out_json) { - (*out_json)["alpha"] = alpha_; - return Status::OK(); -} - -#endif - -// NormalizeOperation -NormalizeOperation::NormalizeOperation(std::vector mean, std::vector std) : mean_(mean), std_(std) {} - -Status NormalizeOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateVectorMeanStd("Normalize", mean_, std_)); - return Status::OK(); -} - -std::shared_ptr NormalizeOperation::Build() { - return std::make_shared(mean_[0], mean_[1], mean_[2], std_[0], std_[1], std_[2]); -} - -Status NormalizeOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["mean"] = mean_; - args["std"] = std_; - *out_json = args; - return Status::OK(); -} - -#ifndef ENABLE_ANDROID -// NormalizePadOperation -NormalizePadOperation::NormalizePadOperation(const std::vector &mean, const std::vector &std, - const std::string &dtype) - : mean_(mean), std_(std), dtype_(dtype) {} - -Status NormalizePadOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateVectorMeanStd("NormalizePad", mean_, std_)); - if (dtype_ != "float32" && dtype_ != "float16") { - std::string err_msg = "NormalizePad: dtype must be float32 or float16, but got: " + dtype_; - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - return Status::OK(); -} - -std::shared_ptr NormalizePadOperation::Build() { - return std::make_shared(mean_[0], mean_[1], mean_[2], std_[0], std_[1], std_[2], dtype_); -} - -Status NormalizePadOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["mean"] = mean_; - args["std"] = std_; - args["dtype"] = dtype_; - *out_json = args; - return Status::OK(); -} - -// PadOperation -PadOperation::PadOperation(std::vector padding, std::vector fill_value, BorderType padding_mode) - : padding_(padding), fill_value_(fill_value), padding_mode_(padding_mode) {} - -Status PadOperation::ValidateParams() { - // padding - RETURN_IF_NOT_OK(ValidateVectorPadding("Pad", padding_)); - // fill_value - RETURN_IF_NOT_OK(ValidateVectorFillvalue("Pad", fill_value_)); - return Status::OK(); -} - -std::shared_ptr PadOperation::Build() { - 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]; - break; - case 2: - pad_left = padding_[0]; - pad_top = padding_[0]; - pad_right = padding_[1]; - pad_bottom = padding_[1]; - break; - default: - pad_left = padding_[0]; - pad_top = padding_[1]; - pad_right = padding_[2]; - pad_bottom = padding_[3]; - } - uint8_t fill_r, fill_g, fill_b; - - fill_r = fill_value_[0]; - fill_g = fill_value_[0]; - fill_b = fill_value_[0]; - - if (fill_value_.size() == 3) { - fill_r = fill_value_[0]; - fill_g = fill_value_[1]; - fill_b = fill_value_[2]; - } - - std::shared_ptr tensor_op = - std::make_shared(pad_top, pad_bottom, pad_left, pad_right, padding_mode_, fill_r, fill_g, fill_b); - return tensor_op; -} - -Status PadOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["padding"] = padding_; - args["fill_value"] = fill_value_; - args["padding_mode"] = padding_mode_; - *out_json = args; - return Status::OK(); -} -#endif - -// RandomAffineOperation -RandomAffineOperation::RandomAffineOperation(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) { - random_op_ = true; -} - -Status RandomAffineOperation::ValidateParams() { - // Degrees - if (degrees_.size() != 2) { - 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]); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - // Translate - if (translate_range_.size() != 2 && translate_range_.size() != 4) { - 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]) { - 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]); - 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]) { - 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]); - 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)); - } - // Scale - RETURN_IF_NOT_OK(ValidateVectorScale("RandomAffine", scale_range_)); - // Shear - if (shear_ranges_.size() != 2 && shear_ranges_.size() != 4) { - 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]) { - 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]); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - if (shear_ranges_.size() == 4 && shear_ranges_[2] > shear_ranges_[3]) { - 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]); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - // Fill Value - RETURN_IF_NOT_OK(ValidateVectorFillvalue("RandomAffine", fill_value_)); - return Status::OK(); -} - -std::shared_ptr RandomAffineOperation::Build() { - if (shear_ranges_.size() == 2) { - shear_ranges_.resize(4); - } - if (translate_range_.size() == 2) { - translate_range_.resize(4); - } - 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]; - } - - auto tensor_op = std::make_shared(degrees_, translate_range_, scale_range_, shear_ranges_, - interpolation_, fill_value); - return tensor_op; -} - -Status RandomAffineOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["degrees"] = degrees_; - args["translate"] = translate_range_; - args["scale"] = scale_range_; - args["shear"] = shear_ranges_; - args["resample"] = interpolation_; - args["fill_value"] = fill_value_; - *out_json = args; - return Status::OK(); -} - -#ifndef ENABLE_ANDROID -// RandomColorOperation. -RandomColorOperation::RandomColorOperation(float t_lb, float t_ub) : t_lb_(t_lb), t_ub_(t_ub) { random_op_ = true; } - -Status RandomColorOperation::ValidateParams() { - if (t_lb_ < 0 || t_ub_ < 0) { - std::string err_msg = - "RandomColor: lower bound or upper bound must be greater than or equal to 0, got t_lb: " + std::to_string(t_lb_) + - ", t_ub: " + std::to_string(t_ub_); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - if (t_lb_ > t_ub_) { - std::string err_msg = - "RandomColor: lower bound must be less or equal to upper bound, got t_lb: " + std::to_string(t_lb_) + - ", t_ub: " + std::to_string(t_ub_); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - return Status::OK(); -} - -std::shared_ptr RandomColorOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(t_lb_, t_ub_); - return tensor_op; -} - -Status RandomColorOperation::to_json(nlohmann::json *out_json) { - (*out_json)["degrees"] = std::vector{t_lb_, t_ub_}; - return Status::OK(); -} - -// RandomColorAdjustOperation. -RandomColorAdjustOperation::RandomColorAdjustOperation(std::vector brightness, std::vector contrast, - std::vector saturation, std::vector hue) - : brightness_(brightness), contrast_(contrast), saturation_(saturation), hue_(hue) { - random_op_ = true; -} - -Status RandomColorAdjustOperation::ValidateParams() { - // brightness - RETURN_IF_NOT_OK(ValidateVectorColorAttribute("RandomColorAdjust", "brightness", brightness_, {0})); - // contrast - RETURN_IF_NOT_OK(ValidateVectorColorAttribute("RandomColorAdjust", "contrast", contrast_, {0})); - // saturation - RETURN_IF_NOT_OK(ValidateVectorColorAttribute("RandomColorAdjust", "saturation", saturation_, {0})); - // hue - RETURN_IF_NOT_OK(ValidateVectorColorAttribute("RandomColorAdjust", "hue", hue_, {-0.5, 0.5})); - return Status::OK(); -} - -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]; - - if (brightness_.size() == 2) brightness_ub = brightness_[1]; - - contrast_lb = contrast_[0]; - contrast_ub = contrast_[0]; - - if (contrast_.size() == 2) contrast_ub = contrast_[1]; - - saturation_lb = saturation_[0]; - saturation_ub = saturation_[0]; - - if (saturation_.size() == 2) saturation_ub = saturation_[1]; - - hue_lb = hue_[0]; - hue_ub = hue_[0]; - - if (hue_.size() == 2) hue_ub = hue_[1]; - - std::shared_ptr tensor_op = std::make_shared( - brightness_lb, brightness_ub, contrast_lb, contrast_ub, saturation_lb, saturation_ub, hue_lb, hue_ub); - return tensor_op; -} - -Status RandomColorAdjustOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["brightness"] = brightness_; - args["contrast"] = contrast_; - args["saturation"] = saturation_; - args["hue"] = hue_; - *out_json = args; - return Status::OK(); -} - -// RandomCropOperation -RandomCropOperation::RandomCropOperation(std::vector size, std::vector padding, bool pad_if_needed, - std::vector fill_value, BorderType padding_mode) - : TensorOperation(true), - size_(size), - padding_(padding), - pad_if_needed_(pad_if_needed), - fill_value_(fill_value), - padding_mode_(padding_mode) { - random_op_ = true; -} - -Status RandomCropOperation::ValidateParams() { - // size - RETURN_IF_NOT_OK(ValidateVectorSize("RandomCrop", size_)); - // padding - RETURN_IF_NOT_OK(ValidateVectorPadding("RandomCrop", padding_)); - // fill_value - RETURN_IF_NOT_OK(ValidateVectorFillvalue("RandomCrop", fill_value_)); - return Status::OK(); -} - -std::shared_ptr RandomCropOperation::Build() { - int32_t crop_height = size_[0]; - int32_t crop_width = size_[0]; - - // User has specified the crop_width value. - if (size_.size() == 2) { - crop_width = size_[1]; - } - - 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]; - break; - case 2: - pad_left = padding_[0]; - pad_top = padding_[0]; - pad_right = padding_[1]; - pad_bottom = padding_[1]; - break; - default: - pad_left = padding_[0]; - pad_top = padding_[1]; - pad_right = padding_[2]; - pad_bottom = padding_[3]; - } - - uint8_t fill_r, fill_g, fill_b; - fill_r = fill_value_[0]; - fill_g = fill_value_[0]; - fill_b = fill_value_[0]; - - if (fill_value_.size() == 3) { - fill_r = fill_value_[0]; - fill_g = fill_value_[1]; - fill_b = fill_value_[2]; - } - - auto tensor_op = std::make_shared(crop_height, crop_width, pad_top, pad_bottom, pad_left, pad_right, - padding_mode_, pad_if_needed_, fill_r, fill_g, fill_b); - return tensor_op; -} - -Status RandomCropOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["size"] = size_; - args["padding"] = padding_; - args["pad_if_needed"] = pad_if_needed_; - args["fill_value"] = fill_value_; - args["padding_mode"] = padding_mode_; - *out_json = args; - return Status::OK(); -} - -// RandomCropDecodeResizeOperation -RandomCropDecodeResizeOperation::RandomCropDecodeResizeOperation(std::vector size, std::vector scale, - std::vector ratio, - InterpolationMode interpolation, int32_t max_attempts) - : RandomResizedCropOperation(size, scale, ratio, interpolation, max_attempts) {} - -std::shared_ptr RandomCropDecodeResizeOperation::Build() { - int32_t crop_height = size_[0]; - int32_t crop_width = size_[0]; - - // User has specified the crop_width value. - if (size_.size() == 2) { - crop_width = size_[1]; - } - - float scale_lower_bound = scale_[0]; - float scale_upper_bound = scale_[1]; - - float aspect_lower_bound = ratio_[0]; - float aspect_upper_bound = ratio_[1]; - - auto tensor_op = - std::make_shared(crop_height, crop_width, scale_lower_bound, scale_upper_bound, - aspect_lower_bound, aspect_upper_bound, interpolation_, max_attempts_); - return tensor_op; -} - -RandomCropDecodeResizeOperation::RandomCropDecodeResizeOperation(const RandomResizedCropOperation &base) - : RandomResizedCropOperation(base) {} - -Status RandomCropDecodeResizeOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["size"] = size_; - args["scale"] = scale_; - args["ratio"] = ratio_; - args["interpolation"] = interpolation_; - args["max_attempts"] = max_attempts_; - *out_json = args; - return Status::OK(); -} - -// RandomCropWithBBoxOperation -RandomCropWithBBoxOperation::RandomCropWithBBoxOperation(std::vector size, std::vector padding, - bool pad_if_needed, std::vector fill_value, - BorderType padding_mode) - : TensorOperation(true), - size_(size), - padding_(padding), - pad_if_needed_(pad_if_needed), - fill_value_(fill_value), - padding_mode_(padding_mode) {} - -Status RandomCropWithBBoxOperation::ValidateParams() { - // size - RETURN_IF_NOT_OK(ValidateVectorSize("RandomCropWithBBox", size_)); - // padding - RETURN_IF_NOT_OK(ValidateVectorPadding("RandomCropWithBBox", padding_)); - // fill_value - RETURN_IF_NOT_OK(ValidateVectorFillvalue("RandomCropWithBBox", fill_value_)); - return Status::OK(); -} - -std::shared_ptr RandomCropWithBBoxOperation::Build() { - int32_t crop_height = size_[0]; - int32_t crop_width = size_[0]; - - // User has specified the crop_width value. - if (size_.size() == 2) { - crop_width = size_[1]; - } - - 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]; - break; - case 2: - pad_left = padding_[0]; - pad_top = padding_[0]; - pad_right = padding_[1]; - pad_bottom = padding_[1]; - break; - default: - pad_left = padding_[0]; - pad_top = padding_[1]; - pad_right = padding_[2]; - pad_bottom = padding_[3]; - } - - uint8_t fill_r, fill_g, fill_b; - fill_r = fill_value_[0]; - fill_g = fill_value_[0]; - fill_b = fill_value_[0]; - - if (fill_value_.size() == 3) { - fill_r = fill_value_[0]; - fill_g = fill_value_[1]; - fill_b = fill_value_[2]; - } - - auto tensor_op = - std::make_shared(crop_height, crop_width, pad_top, pad_bottom, pad_left, pad_right, - padding_mode_, pad_if_needed_, fill_r, fill_g, fill_b); - return tensor_op; -} - -Status RandomCropWithBBoxOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["size"] = size_; - args["padding"] = padding_; - args["pad_if_needed"] = pad_if_needed_; - args["fill_value"] = fill_value_; - args["padding_mode"] = padding_mode_; - *out_json = args; - return Status::OK(); -} - -// RandomHorizontalFlipOperation -RandomHorizontalFlipOperation::RandomHorizontalFlipOperation(float probability) - : TensorOperation(true), probability_(probability) {} - -Status RandomHorizontalFlipOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateProbability("RandomHorizontalFlip", probability_)); - return Status::OK(); -} - -std::shared_ptr RandomHorizontalFlipOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(probability_); - return tensor_op; -} - -Status RandomHorizontalFlipOperation::to_json(nlohmann::json *out_json) { - (*out_json)["prob"] = probability_; - return Status::OK(); -} - -// RandomHorizontalFlipWithBBoxOperation -RandomHorizontalFlipWithBBoxOperation::RandomHorizontalFlipWithBBoxOperation(float probability) - : TensorOperation(true), probability_(probability) {} - -Status RandomHorizontalFlipWithBBoxOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateProbability("RandomHorizontalFlipWithBBox", probability_)); - return Status::OK(); -} - -std::shared_ptr RandomHorizontalFlipWithBBoxOperation::Build() { - std::shared_ptr tensor_op = - std::make_shared(probability_); - return tensor_op; -} - -Status RandomHorizontalFlipWithBBoxOperation::to_json(nlohmann::json *out_json) { - (*out_json)["prob"] = probability_; - return Status::OK(); -} - -// RandomPosterizeOperation -RandomPosterizeOperation::RandomPosterizeOperation(const std::vector &bit_range) - : TensorOperation(true), bit_range_(bit_range) {} - -Status RandomPosterizeOperation::ValidateParams() { - if (bit_range_.size() != 2) { - 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]); - 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]); - 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]); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - return Status::OK(); -} - -std::shared_ptr RandomPosterizeOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(bit_range_); - return tensor_op; -} - -Status RandomPosterizeOperation::to_json(nlohmann::json *out_json) { - (*out_json)["bits"] = bit_range_; - return Status::OK(); -} - -// RandomResizeOperation -RandomResizeOperation::RandomResizeOperation(std::vector size) : TensorOperation(true), size_(size) {} - -Status RandomResizeOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateVectorSize("RandomResize", size_)); - return Status::OK(); -} - -std::shared_ptr RandomResizeOperation::Build() { - // 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 width = 0; - - // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; - } - - std::shared_ptr tensor_op = std::make_shared(height, width); - return tensor_op; -} - -Status RandomResizeOperation::to_json(nlohmann::json *out_json) { - (*out_json)["size"] = size_; - return Status::OK(); -} - -// RandomResizeWithBBoxOperation -RandomResizeWithBBoxOperation::RandomResizeWithBBoxOperation(std::vector size) - : TensorOperation(true), size_(size) {} - -Status RandomResizeWithBBoxOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateVectorSize("RandomResizeWithBBox", size_)); - return Status::OK(); -} - -std::shared_ptr RandomResizeWithBBoxOperation::Build() { - // 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 width = 0; - - // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; - } - - std::shared_ptr tensor_op = std::make_shared(height, width); - return tensor_op; -} - -Status RandomResizeWithBBoxOperation::to_json(nlohmann::json *out_json) { - (*out_json)["size"] = size_; - return Status::OK(); -} - -// RandomResizedCropOperation -RandomResizedCropOperation::RandomResizedCropOperation(std::vector size, std::vector scale, - std::vector ratio, InterpolationMode interpolation, - int32_t max_attempts) - : TensorOperation(true), - size_(size), - scale_(scale), - ratio_(ratio), - interpolation_(interpolation), - max_attempts_(max_attempts) {} - -Status RandomResizedCropOperation::ValidateParams() { - // size - RETURN_IF_NOT_OK(ValidateVectorSize(Name(), size_)); - // scale - RETURN_IF_NOT_OK(ValidateVectorScale(Name(), scale_)); - // ratio - RETURN_IF_NOT_OK(ValidateVectorRatio(Name(), ratio_)); - // max_attempts - if (max_attempts_ < 1) { - std::string err_msg = - Name() + ": max_attempts must be greater than or equal to 1, got: " + std::to_string(max_attempts_); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - return Status::OK(); -} - -std::shared_ptr RandomResizedCropOperation::Build() { - int32_t height = size_[0]; - int32_t width = size_[0]; - // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; - } - std::shared_ptr tensor_op = std::make_shared( - height, width, scale_[0], scale_[1], ratio_[0], ratio_[1], interpolation_, max_attempts_); - return tensor_op; -} - -Status RandomResizedCropOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["size"] = size_; - args["scale"] = scale_; - args["ratio"] = ratio_; - args["interpolation_"] = interpolation_; - args["max_attempts"] = max_attempts_; - *out_json = args; - return Status::OK(); -} - -// RandomResizedCropWithBBoxOperation -RandomResizedCropWithBBoxOperation::RandomResizedCropWithBBoxOperation(std::vector size, - std::vector scale, - std::vector ratio, - InterpolationMode interpolation, - int32_t max_attempts) - : size_(size), scale_(scale), ratio_(ratio), interpolation_(interpolation), max_attempts_(max_attempts) {} - -Status RandomResizedCropWithBBoxOperation::ValidateParams() { - // size - RETURN_IF_NOT_OK(ValidateVectorSize("RandomResizedCropWithBBox", size_)); - // scale - RETURN_IF_NOT_OK(ValidateVectorScale("RandomResizedCropWithBBox", scale_)); - // ratio - RETURN_IF_NOT_OK(ValidateVectorRatio("RandomResizedCropWithBBox", ratio_)); - // max_attempts - if (max_attempts_ < 1) { - std::string err_msg = "RandomResizedCropWithBBox: max_attempts must be greater than or equal to 1, got: " + - std::to_string(max_attempts_); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - return Status::OK(); -} - -std::shared_ptr RandomResizedCropWithBBoxOperation::Build() { - int32_t height = size_[0]; - int32_t width = size_[0]; - // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; - } - std::shared_ptr tensor_op = std::make_shared( - height, width, scale_[0], scale_[1], ratio_[0], ratio_[1], interpolation_, max_attempts_); - return tensor_op; -} - -Status RandomResizedCropWithBBoxOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["size"] = size_; - args["scale"] = scale_; - args["ratio"] = ratio_; - args["interpolation_"] = interpolation_; - args["max_attempts"] = max_attempts_; - *out_json = args; - return Status::OK(); -} - -// Function to create RandomRotationOperation. -RandomRotationOperation::RandomRotationOperation(std::vector degrees, InterpolationMode interpolation_mode, - bool expand, std::vector center, - std::vector fill_value) - : TensorOperation(true), - degrees_(degrees), - interpolation_mode_(interpolation_mode), - expand_(expand), - center_(center), - fill_value_(fill_value) {} - -Status RandomRotationOperation::ValidateParams() { - // degrees - if (degrees_.size() != 2 && degrees_.size() != 1) { - 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])) { - 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]) + ")"; - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } else if ((degrees_.size() == 1) && (degrees_[0] < 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]); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - // center - if (center_.empty() || center_.size() != 2) { - std::string err_msg = - "RandomRotation: center must be a vector of two values, got: " + std::to_string(center_.size()); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - // fill_value - RETURN_IF_NOT_OK(ValidateVectorFillvalue("RandomRotation", fill_value_)); - return Status::OK(); -} - -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]; - } - - uint8_t fill_r, fill_g, fill_b; - fill_r = fill_value_[0]; - fill_g = fill_value_[0]; - fill_b = fill_value_[0]; - - if (fill_value_.size() == 3) { - fill_r = fill_value_[0]; - fill_g = fill_value_[1]; - fill_b = fill_value_[2]; - } - - std::shared_ptr tensor_op = std::make_shared( - start_degree, end_degree, center_[0], center_[1], interpolation_mode_, expand_, fill_r, fill_g, fill_b); - return tensor_op; -} - -Status RandomRotationOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["degrees"] = degrees_; - args["resample"] = interpolation_mode_; - args["expand"] = expand_; - args["center"] = center_; - args["fill_value"] = fill_value_; - *out_json = args; - return Status::OK(); -} - -// RandomSelectSubpolicyOperation. -RandomSelectSubpolicyOperation::RandomSelectSubpolicyOperation( - std::vector, double>>> policy) - : TensorOperation(true), policy_(policy) {} - -Status RandomSelectSubpolicyOperation::ValidateParams() { - if (policy_.empty()) { - std::string err_msg = "RandomSelectSubpolicy: policy must not be empty"; - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - for (int32_t i = 0; i < policy_.size(); i++) { - if (policy_[i].empty()) { - std::string err_msg = "RandomSelectSubpolicy: policy[" + std::to_string(i) + "] must not be empty"; - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - for (int32_t j = 0; j < policy_[i].size(); j++) { - if (policy_[i][j].first == nullptr) { - std::string transform_pos = "[" + std::to_string(i) + "]" + "[" + std::to_string(j) + "]"; - std::string err_msg = "RandomSelectSubpolicy: transform in policy" + transform_pos + " must not be null"; - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } else { - RETURN_IF_NOT_OK(policy_[i][j].first->ValidateParams()); - } - if (policy_[i][j].second < 0.0 || policy_[i][j].second > 1.0) { - std::string transform_pos = "[" + std::to_string(i) + "]" + "[" + std::to_string(j) + "]"; - std::string err_msg = "RandomSelectSubpolicy: probability of transform in policy" + transform_pos + - " must be between 0.0 and 1.0, got: " + std::to_string(policy_[i][j].second); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - } - } - return Status::OK(); -} - -std::shared_ptr RandomSelectSubpolicyOperation::Build() { - std::vector policy_tensor_ops; - for (int32_t i = 0; i < policy_.size(); i++) { - Subpolicy sub_policy_tensor_ops; - for (int32_t j = 0; j < policy_[i].size(); j++) { - sub_policy_tensor_ops.push_back(std::make_pair(policy_[i][j].first->Build(), policy_[i][j].second)); - } - policy_tensor_ops.push_back(sub_policy_tensor_ops); - } - std::shared_ptr tensor_op = std::make_shared(policy_tensor_ops); - return tensor_op; -} - -Status RandomSelectSubpolicyOperation::to_json(nlohmann::json *out_json) { - auto policy_tensor_ops = nlohmann::json::array(); - for (int32_t i = 0; i < policy_.size(); i++) { - auto sub_policy_tensor_ops = nlohmann::json::array(); - for (int32_t j = 0; j < policy_[i].size(); j++) { - nlohmann::json policy, args; - auto tensor_op = policy_[i][j].first; - RETURN_IF_NOT_OK(tensor_op->to_json(&args)); - policy["tensor_op"]["tensor_op_params"] = args; - policy["tensor_op"]["tensor_op_name"] = tensor_op->Name(); - policy["prob"] = policy_[i][j].second; - sub_policy_tensor_ops.push_back(policy); - } - policy_tensor_ops.push_back(sub_policy_tensor_ops); - } - (*out_json)["policy"] = policy_tensor_ops; - return Status::OK(); -} - -// Function to create RandomSharpness. -RandomSharpnessOperation::RandomSharpnessOperation(std::vector degrees) - : TensorOperation(true), degrees_(degrees) {} - -Status RandomSharpnessOperation::ValidateParams() { - if (degrees_.size() != 2 || degrees_[0] < 0 || degrees_[1] < 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]) { - 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); - } - return Status::OK(); -} - -std::shared_ptr RandomSharpnessOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(degrees_[0], degrees_[1]); - return tensor_op; -} - -Status RandomSharpnessOperation::to_json(nlohmann::json *out_json) { - (*out_json)["degrees"] = degrees_; - return Status::OK(); -} - -// RandomSolarizeOperation. -RandomSolarizeOperation::RandomSolarizeOperation(std::vector threshold) - : TensorOperation(true), threshold_(threshold) {} - -Status RandomSolarizeOperation::ValidateParams() { - if (threshold_.size() != 2) { - 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) { - 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]) { - 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); - } - return Status::OK(); -} - -std::shared_ptr RandomSolarizeOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(threshold_); - return tensor_op; -} - -Status RandomSolarizeOperation::to_json(nlohmann::json *out_json) { - (*out_json)["threshold"] = threshold_; - return Status::OK(); -} - -// RandomVerticalFlipOperation -RandomVerticalFlipOperation::RandomVerticalFlipOperation(float probability) - : TensorOperation(true), probability_(probability) {} - -Status RandomVerticalFlipOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateProbability("RandomVerticalFlip", probability_)); - - return Status::OK(); -} - -std::shared_ptr RandomVerticalFlipOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(probability_); - return tensor_op; -} - -Status RandomVerticalFlipOperation::to_json(nlohmann::json *out_json) { - (*out_json)["prob"] = probability_; - return Status::OK(); -} - -// RandomVerticalFlipWithBBoxOperation -RandomVerticalFlipWithBBoxOperation::RandomVerticalFlipWithBBoxOperation(float probability) - : TensorOperation(true), probability_(probability) {} - -Status RandomVerticalFlipWithBBoxOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateProbability("RandomVerticalFlipWithBBox", probability_)); - - return Status::OK(); -} - -std::shared_ptr RandomVerticalFlipWithBBoxOperation::Build() { - std::shared_ptr tensor_op = - std::make_shared(probability_); - return tensor_op; -} - -Status RandomVerticalFlipWithBBoxOperation::to_json(nlohmann::json *out_json) { - (*out_json)["prob"] = probability_; - return Status::OK(); -} - -// RescaleOperation -RescaleOperation::RescaleOperation(float rescale, float shift) : rescale_(rescale), shift_(shift) {} - -Status RescaleOperation::ValidateParams() { - if (rescale_ < 0) { - std::string err_msg = "Rescale: rescale must be greater than or equal to 0, got: " + std::to_string(rescale_); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - return Status::OK(); -} - -std::shared_ptr RescaleOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(rescale_, shift_); - return tensor_op; -} - -Status RescaleOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["rescale"] = rescale_; - args["shift"] = shift_; - *out_json = args; - return Status::OK(); -} - -#endif -// ResizeOperation -ResizeOperation::ResizeOperation(std::vector size, InterpolationMode interpolation) - : size_(size), interpolation_(interpolation) {} - -Status ResizeOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateVectorSize("Resize", size_)); - return Status::OK(); -} - -std::shared_ptr ResizeOperation::Build() { - // 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 width = 0; - - // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; - } - - return std::make_shared(height, width, interpolation_); -} - -Status ResizeOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["size"] = size_; - args["interpolation"] = interpolation_; - *out_json = args; - return Status::OK(); -} - -// ResizePreserveAROperation -ResizePreserveAROperation::ResizePreserveAROperation(int32_t height, int32_t width, int32_t img_orientation) - : height_(height), width_(width), img_orientation_(img_orientation) {} - -Status ResizePreserveAROperation::ValidateParams() { return Status::OK(); } - -std::shared_ptr ResizePreserveAROperation::Build() { - return std::make_shared(height_, width_, img_orientation_); -} - -Status ResizePreserveAROperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["height"] = height_; - args["width"] = width_; - args["img_orientation"] = img_orientation_; - *out_json = args; - return Status::OK(); -} - -// RotateOperation -RotateOperation::RotateOperation() { rotate_op = std::make_shared(0); } - -Status RotateOperation::ValidateParams() { return Status::OK(); } - -std::shared_ptr RotateOperation::Build() { return rotate_op; } - -void RotateOperation::setAngle(uint64_t angle_id) { - std::dynamic_pointer_cast(rotate_op)->setAngle(angle_id); -} - -#ifndef ENABLE_ANDROID -// ResizeWithBBoxOperation -ResizeWithBBoxOperation::ResizeWithBBoxOperation(std::vector size, InterpolationMode interpolation) - : size_(size), interpolation_(interpolation) {} - -Status ResizeWithBBoxOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateVectorSize("ResizeWithBBox", size_)); - return Status::OK(); -} - -std::shared_ptr ResizeWithBBoxOperation::Build() { - int32_t height = size_[0]; - int32_t width = 0; - - // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; - } - - return std::make_shared(height, width, interpolation_); -} - -Status ResizeWithBBoxOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["size"] = size_; - args["interpolation"] = interpolation_; - *out_json = args; - return Status::OK(); -} - -// RgbaToBgrOperation. -RgbaToBgrOperation::RgbaToBgrOperation() {} - -Status RgbaToBgrOperation::ValidateParams() { return Status::OK(); } - -std::shared_ptr RgbaToBgrOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(); - return tensor_op; -} - -// RgbaToRgbOperation. -RgbaToRgbOperation::RgbaToRgbOperation() {} - -Status RgbaToRgbOperation::ValidateParams() { return Status::OK(); } - -std::shared_ptr RgbaToRgbOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(); - return tensor_op; -} - -// SoftDvppDecodeRandomCropResizeJpegOperation -SoftDvppDecodeRandomCropResizeJpegOperation::SoftDvppDecodeRandomCropResizeJpegOperation(std::vector size, - std::vector scale, - std::vector ratio, - int32_t max_attempts) - : size_(size), scale_(scale), ratio_(ratio), max_attempts_(max_attempts) {} - -Status SoftDvppDecodeRandomCropResizeJpegOperation::ValidateParams() { - // size - RETURN_IF_NOT_OK(ValidateVectorSize("SoftDvppDecodeRandomCropResizeJpeg", size_)); - for (int32_t i = 0; i < size_.size(); i++) { - if (size_[i] % 2 == 1) { - 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; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - } - // scale - RETURN_IF_NOT_OK(ValidateVectorScale("SoftDvppDecodeRandomCropResizeJpeg", scale_)); - // ratio - RETURN_IF_NOT_OK(ValidateVectorRatio("SoftDvppDecodeRandomCropResizeJpeg", ratio_)); - // max_attempts - if (max_attempts_ < 1) { - std::string err_msg = "SoftDvppDecodeRandomCropResizeJpeg: max_attempts must be greater than or equal to 1, got: " + - std::to_string(max_attempts_); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - return Status::OK(); -} - -std::shared_ptr SoftDvppDecodeRandomCropResizeJpegOperation::Build() { - int32_t height = size_[0]; - int32_t width = size_[0]; - // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; - } - - auto tensor_op = std::make_shared(height, width, scale_[0], scale_[1], - ratio_[0], ratio_[1], max_attempts_); - return tensor_op; -} - -Status SoftDvppDecodeRandomCropResizeJpegOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - args["size"] = size_; - args["scale"] = scale_; - args["ratio"] = ratio_; - args["max_attempts"] = max_attempts_; - *out_json = args; - return Status::OK(); -} - -// SoftDvppDecodeResizeJpegOperation -SoftDvppDecodeResizeJpegOperation::SoftDvppDecodeResizeJpegOperation(std::vector size) : size_(size) {} - -Status SoftDvppDecodeResizeJpegOperation::ValidateParams() { - RETURN_IF_NOT_OK(ValidateVectorSize("SoftDvppDecodeResizeJpeg", size_)); - for (int32_t i = 0; i < size_.size(); i++) { - if (size_[i] % 2 == 1) { - 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; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - } - return Status::OK(); -} - -std::shared_ptr SoftDvppDecodeResizeJpegOperation::Build() { - // 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 width = 0; - - // User specified the width value. - if (size_.size() == 2) { - width = size_[1]; - } - std::shared_ptr tensor_op = std::make_shared(height, width); - return tensor_op; -} - -Status SoftDvppDecodeResizeJpegOperation::to_json(nlohmann::json *out_json) { - (*out_json)["size"] = size_; - return Status::OK(); -} - -// SwapRedBlueOperation. -SwapRedBlueOperation::SwapRedBlueOperation() {} - -Status SwapRedBlueOperation::ValidateParams() { return Status::OK(); } - -std::shared_ptr SwapRedBlueOperation::Build() { - std::shared_ptr tensor_op = std::make_shared(); - return tensor_op; -} - -// UniformAugOperation -UniformAugOperation::UniformAugOperation(std::vector> transforms, int32_t num_ops) - : transforms_(transforms), num_ops_(num_ops) {} - -Status UniformAugOperation::ValidateParams() { - // transforms - RETURN_IF_NOT_OK(ValidateVectorTransforms("UniformAug", transforms_)); - if (num_ops_ > transforms_.size()) { - std::string err_msg = - "UniformAug: num_ops must be less than or equal to transforms size, but got: " + std::to_string(num_ops_); - MS_LOG(ERROR) << err_msg; - RETURN_STATUS_SYNTAX_ERROR(err_msg); - } - // num_ops - RETURN_IF_NOT_OK(ValidateIntScalarPositive("UniformAug", "num_ops", num_ops_)); - return Status::OK(); -} - -std::shared_ptr UniformAugOperation::Build() { - std::vector> tensor_ops; - (void)std::transform(transforms_.begin(), transforms_.end(), std::back_inserter(tensor_ops), - [](std::shared_ptr op) -> std::shared_ptr { return op->Build(); }); - std::shared_ptr tensor_op = std::make_shared(tensor_ops, num_ops_); - return tensor_op; -} - -Status UniformAugOperation::to_json(nlohmann::json *out_json) { - nlohmann::json args; - std::vector transforms; - for (auto op : transforms_) { - nlohmann::json op_item, op_args; - RETURN_IF_NOT_OK(op->to_json(&op_args)); - op_item["tensor_op_params"] = op_args; - op_item["tensor_op_name"] = op->Name(); - transforms.push_back(op_item); - } - args["transforms"] = transforms; - args["num_ops"] = num_ops_; - *out_json = args; - return Status::OK(); -} -#endif - -} // namespace vision -} // namespace dataset -} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/vision_ir.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/vision_ir.h deleted file mode 100644 index c6db4bdfc0..0000000000 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/vision_ir.h +++ /dev/null @@ -1,943 +0,0 @@ -/** - * 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. - */ - -#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_VISION_IR_H_ -#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_VISION_IR_H_ - -#include -#include -#include -#include -#include - -#include "include/api/status.h" -#include "minddata/dataset/include/dataset/constants.h" -#include "minddata/dataset/include/dataset/transforms.h" -#include "minddata/dataset/kernels/ir/tensor_operation.h" - -namespace mindspore { -namespace dataset { - -// Transform operations for performing computer vision. -namespace vision { - -// Char arrays storing name of corresponding classes (in alphabetical order) -constexpr char kAffineOperation[] = "Affine"; -constexpr char kAutoContrastOperation[] = "AutoContrast"; -constexpr char kBoundingBoxAugmentOperation[] = "BoundingBoxAugment"; -constexpr char kCenterCropOperation[] = "CenterCrop"; -constexpr char kCropOperation[] = "Crop"; -constexpr char kCutMixBatchOperation[] = "CutMixBatch"; -constexpr char kCutOutOperation[] = "CutOut"; -constexpr char kDecodeOperation[] = "Decode"; -constexpr char kEqualizeOperation[] = "Equalize"; -constexpr char kHwcToChwOperation[] = "HwcToChw"; -constexpr char kInvertOperation[] = "Invert"; -constexpr char kMixUpBatchOperation[] = "MixUpBatch"; -constexpr char kNormalizeOperation[] = "Normalize"; -constexpr char kNormalizePadOperation[] = "NormalizePad"; -constexpr char kPadOperation[] = "Pad"; -constexpr char kRandomAffineOperation[] = "RandomAffine"; -constexpr char kRandomColorAdjustOperation[] = "RandomColorAdjust"; -constexpr char kRandomColorOperation[] = "RandomColor"; -constexpr char kRandomCropDecodeResizeOperation[] = "RandomCropDecodeResize"; -constexpr char kRandomCropOperation[] = "RandomCrop"; -constexpr char kRandomCropWithBBoxOperation[] = "RandomCropWithBBox"; -constexpr char kRandomHorizontalFlipOperation[] = "RandomHorizontalFlip"; -constexpr char kRandomHorizontalFlipWithBBoxOperation[] = "RandomHorizontalFlipWithBBox"; -constexpr char kRandomPosterizeOperation[] = "RandomPosterize"; -constexpr char kRandomResizedCropOperation[] = "RandomResizedCrop"; -constexpr char kRandomResizedCropWithBBoxOperation[] = "RandomResizedCropWithBBox"; -constexpr char kRandomResizeOperation[] = "RandomResize"; -constexpr char kRandomResizeWithBBoxOperation[] = "RandomResizeWithBBox"; -constexpr char kRandomRotationOperation[] = "RandomRotation"; -constexpr char kRandomSelectSubpolicyOperation[] = "RandomSelectSubpolicy"; -constexpr char kRandomSharpnessOperation[] = "RandomSharpness"; -constexpr char kRandomSolarizeOperation[] = "RandomSolarize"; -constexpr char kRandomVerticalFlipOperation[] = "RandomVerticalFlip"; -constexpr char kRandomVerticalFlipWithBBoxOperation[] = "RandomVerticalFlipWithBBox"; -constexpr char kRescaleOperation[] = "Rescale"; -constexpr char kResizeOperation[] = "Resize"; -constexpr char kResizePreserveAROperation[] = "ResizePreserveAR"; -constexpr char kResizeWithBBoxOperation[] = "ResizeWithBBox"; -constexpr char kRgbaToBgrOperation[] = "RgbaToBgr"; -constexpr char kRgbaToRgbOperation[] = "RgbaToRgb"; -constexpr char kRgbToGrayOperation[] = "RgbToGray"; -constexpr char kRotateOperation[] = "Rotate"; -constexpr char kSoftDvppDecodeRandomCropResizeJpegOperation[] = "SoftDvppDecodeRandomCropResizeJpeg"; -constexpr char kSoftDvppDecodeResizeJpegOperation[] = "SoftDvppDecodeResizeJpeg"; -constexpr char kSwapRedBlueOperation[] = "SwapRedBlue"; -constexpr char kUniformAugOperation[] = "UniformAug"; - -/* ####################################### Derived TensorOperation classes ################################# */ - -class AffineOperation : public TensorOperation { - public: - explicit AffineOperation(float_t degrees, const std::vector &translation, float scale, - const std::vector &shear, InterpolationMode interpolation, - const std::vector &fill_value); - - ~AffineOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kAffineOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - float degrees_; - std::vector translation_; - float scale_; - std::vector shear_; - InterpolationMode interpolation_; - std::vector fill_value_; -}; - -class AutoContrastOperation : public TensorOperation { - public: - explicit AutoContrastOperation(float cutoff, std::vector ignore); - - ~AutoContrastOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kAutoContrastOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - float cutoff_; - std::vector ignore_; -}; - -class BoundingBoxAugmentOperation : public TensorOperation { - public: - explicit BoundingBoxAugmentOperation(std::shared_ptr transform, float ratio); - - ~BoundingBoxAugmentOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kBoundingBoxAugmentOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::shared_ptr transform_; - float ratio_; -}; - -class CenterCropOperation : public TensorOperation { - public: - explicit CenterCropOperation(std::vector size); - - ~CenterCropOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kCenterCropOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector size_; -}; - -class RgbToGrayOperation : public TensorOperation { - public: - RgbToGrayOperation() = default; - - ~RgbToGrayOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRgbToGrayOperation; } -}; - -class CropOperation : public TensorOperation { - public: - CropOperation(std::vector coordinates, std::vector size); - - ~CropOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kCropOperation; } - - private: - std::vector coordinates_; - std::vector size_; -}; - -class CutMixBatchOperation : public TensorOperation { - public: - explicit CutMixBatchOperation(ImageBatchFormat image_batch_format, float alpha, float prob); - - ~CutMixBatchOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kCutMixBatchOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - float alpha_; - float prob_; - ImageBatchFormat image_batch_format_; -}; - -class CutOutOperation : public TensorOperation { - public: - explicit CutOutOperation(int32_t length, int32_t num_patches); - - ~CutOutOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kCutOutOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - int32_t length_; - int32_t num_patches_; -}; - -class DecodeOperation : public TensorOperation { - public: - explicit DecodeOperation(bool rgb); - - ~DecodeOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kDecodeOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - bool rgb_; -}; - -class EqualizeOperation : public TensorOperation { - public: - ~EqualizeOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kEqualizeOperation; } -}; - -class HwcToChwOperation : public TensorOperation { - public: - ~HwcToChwOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kHwcToChwOperation; } -}; - -class InvertOperation : public TensorOperation { - public: - ~InvertOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kInvertOperation; } -}; - -class MixUpBatchOperation : public TensorOperation { - public: - explicit MixUpBatchOperation(float alpha); - - ~MixUpBatchOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kMixUpBatchOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - float alpha_; -}; - -class NormalizeOperation : public TensorOperation { - public: - NormalizeOperation(std::vector mean, std::vector std); - - ~NormalizeOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kNormalizeOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector mean_; - std::vector std_; -}; - -class NormalizePadOperation : public TensorOperation { - public: - NormalizePadOperation(const std::vector &mean, const std::vector &std, const std::string &dtype); - - ~NormalizePadOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kNormalizePadOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector mean_; - std::vector std_; - std::string dtype_; -}; - -class PadOperation : public TensorOperation { - public: - PadOperation(std::vector padding, std::vector fill_value, BorderType padding_mode); - - ~PadOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kPadOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector padding_; - std::vector fill_value_; - BorderType padding_mode_; -}; - -class RandomAffineOperation : public TensorOperation { - public: - RandomAffineOperation(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); - - ~RandomAffineOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomAffineOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - 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_; -}; - -class RandomColorOperation : public TensorOperation { - public: - RandomColorOperation(float t_lb, float t_ub); - - ~RandomColorOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomColorOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - float t_lb_; - float t_ub_; -}; - -class RandomColorAdjustOperation : public TensorOperation { - public: - RandomColorAdjustOperation(std::vector brightness, std::vector contrast, std::vector saturation, - std::vector hue); - - ~RandomColorAdjustOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomColorAdjustOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector brightness_; - std::vector contrast_; - std::vector saturation_; - std::vector hue_; -}; - -class RandomCropOperation : public TensorOperation { - public: - RandomCropOperation(std::vector size, std::vector padding, bool pad_if_needed, - std::vector fill_value, BorderType padding_mode); - - ~RandomCropOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomCropOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector size_; - std::vector padding_; - bool pad_if_needed_; - std::vector fill_value_; - BorderType padding_mode_; -}; - -class RandomResizedCropOperation : public TensorOperation { - public: - RandomResizedCropOperation(std::vector size, std::vector scale, std::vector ratio, - InterpolationMode interpolation, int32_t max_attempts); - - /// \brief default copy constructor - explicit RandomResizedCropOperation(const RandomResizedCropOperation &) = default; - - ~RandomResizedCropOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomResizedCropOperation; } - - Status to_json(nlohmann::json *out_json) override; - - protected: - std::vector size_; - std::vector scale_; - std::vector ratio_; - InterpolationMode interpolation_; - int32_t max_attempts_; -}; - -class RandomCropDecodeResizeOperation : public RandomResizedCropOperation { - public: - RandomCropDecodeResizeOperation(std::vector size, std::vector scale, std::vector ratio, - InterpolationMode interpolation, int32_t max_attempts); - - explicit RandomCropDecodeResizeOperation(const RandomResizedCropOperation &base); - - ~RandomCropDecodeResizeOperation() = default; - - std::shared_ptr Build() override; - - std::string Name() const override { return kRandomCropDecodeResizeOperation; } - - Status to_json(nlohmann::json *out_json) override; -}; - -class RandomCropWithBBoxOperation : public TensorOperation { - public: - RandomCropWithBBoxOperation(std::vector size, std::vector padding, bool pad_if_needed, - std::vector fill_value, BorderType padding_mode); - - ~RandomCropWithBBoxOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomCropWithBBoxOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector size_; - std::vector padding_; - bool pad_if_needed_; - std::vector fill_value_; - BorderType padding_mode_; -}; - -class RandomHorizontalFlipOperation : public TensorOperation { - public: - explicit RandomHorizontalFlipOperation(float probability); - - ~RandomHorizontalFlipOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomHorizontalFlipOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - float probability_; -}; - -class RandomHorizontalFlipWithBBoxOperation : public TensorOperation { - public: - explicit RandomHorizontalFlipWithBBoxOperation(float probability); - - ~RandomHorizontalFlipWithBBoxOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomHorizontalFlipWithBBoxOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - float probability_; -}; - -class RandomPosterizeOperation : public TensorOperation { - public: - explicit RandomPosterizeOperation(const std::vector &bit_range); - - ~RandomPosterizeOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomPosterizeOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector bit_range_; -}; - -class RandomResizeOperation : public TensorOperation { - public: - explicit RandomResizeOperation(std::vector size); - - ~RandomResizeOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomResizeOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector size_; -}; - -class RandomResizeWithBBoxOperation : public TensorOperation { - public: - explicit RandomResizeWithBBoxOperation(std::vector size); - - ~RandomResizeWithBBoxOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomResizeWithBBoxOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector size_; -}; - -class RandomResizedCropWithBBoxOperation : public TensorOperation { - public: - explicit RandomResizedCropWithBBoxOperation(std::vector size, std::vector scale, - std::vector ratio, InterpolationMode interpolation, - int32_t max_attempts); - - ~RandomResizedCropWithBBoxOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomResizedCropWithBBoxOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector size_; - std::vector scale_; - std::vector ratio_; - InterpolationMode interpolation_; - int32_t max_attempts_; -}; - -class RandomRotationOperation : public TensorOperation { - public: - RandomRotationOperation(std::vector degrees, InterpolationMode interpolation_mode, bool expand, - std::vector center, std::vector fill_value); - - ~RandomRotationOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomRotationOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector degrees_; - InterpolationMode interpolation_mode_; - std::vector center_; - bool expand_; - std::vector fill_value_; -}; - -class RandomSelectSubpolicyOperation : public TensorOperation { - public: - explicit RandomSelectSubpolicyOperation( - std::vector, double>>> policy); - - ~RandomSelectSubpolicyOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomSelectSubpolicyOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector, double>>> policy_; -}; - -class RandomSharpnessOperation : public TensorOperation { - public: - explicit RandomSharpnessOperation(std::vector degrees); - - ~RandomSharpnessOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomSharpnessOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector degrees_; -}; - -class RandomSolarizeOperation : public TensorOperation { - public: - explicit RandomSolarizeOperation(std::vector threshold); - - ~RandomSolarizeOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomSolarizeOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector threshold_; -}; - -class RandomVerticalFlipOperation : public TensorOperation { - public: - explicit RandomVerticalFlipOperation(float probability); - - ~RandomVerticalFlipOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomVerticalFlipOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - float probability_; -}; - -class RandomVerticalFlipWithBBoxOperation : public TensorOperation { - public: - explicit RandomVerticalFlipWithBBoxOperation(float probability); - - ~RandomVerticalFlipWithBBoxOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRandomVerticalFlipWithBBoxOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - float probability_; -}; - -class RescaleOperation : public TensorOperation { - public: - explicit RescaleOperation(float rescale, float shift); - - ~RescaleOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRescaleOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - float rescale_; - float shift_; -}; - -class ResizeOperation : public TensorOperation { - public: - explicit ResizeOperation(std::vector size, InterpolationMode interpolation_mode); - - ~ResizeOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kResizeOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector size_; - InterpolationMode interpolation_; -}; - -class ResizePreserveAROperation : public TensorOperation { - public: - ResizePreserveAROperation(int32_t height, int32_t width, int32_t img_orientation); - - ~ResizePreserveAROperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kResizePreserveAROperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - int32_t height_; - int32_t width_; - int32_t img_orientation_; -}; - -class ResizeWithBBoxOperation : public TensorOperation { - public: - explicit ResizeWithBBoxOperation(std::vector size, InterpolationMode interpolation_mode); - - ~ResizeWithBBoxOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kResizeWithBBoxOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector size_; - InterpolationMode interpolation_; -}; - -class RgbaToBgrOperation : public TensorOperation { - public: - RgbaToBgrOperation(); - - ~RgbaToBgrOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRgbaToBgrOperation; } -}; - -class RgbaToRgbOperation : public TensorOperation { - public: - RgbaToRgbOperation(); - - ~RgbaToRgbOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRgbaToRgbOperation; } -}; - -class RotateOperation : public TensorOperation { - public: - RotateOperation(); - - ~RotateOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kRotateOperation; } - - void setAngle(uint64_t angle_id); - - private: - std::shared_ptr rotate_op; -}; - -class SoftDvppDecodeRandomCropResizeJpegOperation : public TensorOperation { - public: - explicit SoftDvppDecodeRandomCropResizeJpegOperation(std::vector size, std::vector scale, - std::vector ratio, int32_t max_attempts); - - ~SoftDvppDecodeRandomCropResizeJpegOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kSoftDvppDecodeRandomCropResizeJpegOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector size_; - std::vector scale_; - std::vector ratio_; - int32_t max_attempts_; -}; - -class SoftDvppDecodeResizeJpegOperation : public TensorOperation { - public: - explicit SoftDvppDecodeResizeJpegOperation(std::vector size); - - ~SoftDvppDecodeResizeJpegOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kSoftDvppDecodeResizeJpegOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector size_; -}; - -class SwapRedBlueOperation : public TensorOperation { - public: - SwapRedBlueOperation(); - - ~SwapRedBlueOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kSwapRedBlueOperation; } -}; - -class UniformAugOperation : public TensorOperation { - public: - explicit UniformAugOperation(std::vector> transforms, int32_t num_ops); - - ~UniformAugOperation() = default; - - std::shared_ptr Build() override; - - Status ValidateParams() override; - - std::string Name() const override { return kUniformAugOperation; } - - Status to_json(nlohmann::json *out_json) override; - - private: - std::vector> transforms_; - int32_t num_ops_; -}; - -} // namespace vision -} // namespace dataset -} // namespace mindspore -#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_VISION_IR_H_ diff --git a/mindspore/lite/minddata/CMakeLists.txt b/mindspore/lite/minddata/CMakeLists.txt index 50f95f4906..32c759cd9c 100644 --- a/mindspore/lite/minddata/CMakeLists.txt +++ b/mindspore/lite/minddata/CMakeLists.txt @@ -142,7 +142,15 @@ if(BUILD_MINDDATA STREQUAL "full") ${MINDDATA_DIR}/engine/ir/datasetops/shuffle_node.cc ${MINDDATA_DIR}/engine/ir/datasetops/source/album_node.cc ${MINDDATA_DIR}/engine/ir/datasetops/source/mnist_node.cc + ${MINDDATA_DIR}/engine/ir/datasetops/source/samplers/distributed_sampler_ir.cc + ${MINDDATA_DIR}/engine/ir/datasetops/source/samplers/pk_sampler_ir.cc + ${MINDDATA_DIR}/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.cc + ${MINDDATA_DIR}/engine/ir/datasetops/source/samplers/random_sampler_ir.cc ${MINDDATA_DIR}/engine/ir/datasetops/source/samplers/samplers_ir.cc + ${MINDDATA_DIR}/engine/ir/datasetops/source/samplers/sequential_sampler_ir.cc + ${MINDDATA_DIR}/engine/ir/datasetops/source/samplers/subset_random_sampler_ir.cc + ${MINDDATA_DIR}/engine/ir/datasetops/source/samplers/subset_sampler_ir.cc + ${MINDDATA_DIR}/engine/ir/datasetops/source/samplers/weighted_random_sampler_ir.cc ${MINDDATA_DIR}/engine/datasetops/dataset_op.cc ${MINDDATA_DIR}/engine/datasetops/repeat_op.cc ${MINDDATA_DIR}/engine/datasetops/epoch_ctrl_op.cc @@ -216,7 +224,52 @@ if(BUILD_MINDDATA STREQUAL "full") ${MINDDATA_DIR}/kernels/image/exif_utils.cc ${MINDDATA_DIR}/kernels/ir/validators.cc ${MINDDATA_DIR}/kernels/ir/data/transforms_ir.cc - ${MINDDATA_DIR}/kernels/ir/vision/vision_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/affine_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/auto_contrast_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/bounding_box_augment_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/center_crop_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/crop_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/cutmix_batch_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/cutout_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/decode_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/equalize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/hwc_to_chw_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/invert_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/mixup_batch_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/normalize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/normalize_pad_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/pad_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_affine_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_color_adjust_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_color_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_crop_decode_resize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_crop_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_crop_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_horizontal_flip_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_posterize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_resized_crop_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_resized_crop_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_resize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_resize_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_rotation_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_select_subpolicy_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_sharpness_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_solarize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_vertical_flip_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_vertical_flip_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rescale_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/resize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/resize_preserve_ar_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/resize_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rgba_to_bgr_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rgba_to_rgb_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rgb_to_gray_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rotate_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/swap_red_blue_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/uniform_aug_ir.cc ${MINDDATA_DIR}/callback/callback_manager.cc ${MINDDATA_DIR}/util/task_manager.cc ${MINDDATA_DIR}/util/services.cc @@ -301,7 +354,52 @@ elseif(BUILD_MINDDATA STREQUAL "wrapper") ${MINDDATA_DIR}/kernels/image/exif_utils.cc ${MINDDATA_DIR}/kernels/ir/validators.cc ${MINDDATA_DIR}/kernels/ir/data/transforms_ir.cc - ${MINDDATA_DIR}/kernels/ir/vision/vision_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/affine_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/auto_contrast_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/bounding_box_augment_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/center_crop_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/crop_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/cutmix_batch_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/cutout_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/decode_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/equalize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/hwc_to_chw_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/invert_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/mixup_batch_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/normalize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/normalize_pad_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/pad_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_affine_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_color_adjust_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_color_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_crop_decode_resize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_crop_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_crop_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_horizontal_flip_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_posterize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_resized_crop_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_resized_crop_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_resize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_resize_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_rotation_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_select_subpolicy_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_sharpness_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_solarize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_vertical_flip_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_vertical_flip_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rescale_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/resize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/resize_preserve_ar_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/resize_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rgba_to_bgr_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rgba_to_rgb_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rgb_to_gray_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rotate_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/swap_red_blue_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/uniform_aug_ir.cc ${CMAKE_CURRENT_SOURCE_DIR}/wrapper/MDToDApi.cc ${CMAKE_CURRENT_SOURCE_DIR}/wrapper/album_op_android.cc ) @@ -416,7 +514,52 @@ elseif(BUILD_MINDDATA STREQUAL "lite") ${CORE_DIR}/utils/ms_utils.cc ${MINDDATA_DIR}/kernels/ir/validators.cc ${MINDDATA_DIR}/kernels/ir/data/transforms_ir.cc - ${MINDDATA_DIR}/kernels/ir/vision/vision_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/affine_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/auto_contrast_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/bounding_box_augment_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/center_crop_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/crop_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/cutmix_batch_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/cutout_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/decode_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/equalize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/hwc_to_chw_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/invert_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/mixup_batch_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/normalize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/normalize_pad_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/pad_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_affine_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_color_adjust_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_color_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_crop_decode_resize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_crop_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_crop_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_horizontal_flip_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_posterize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_resized_crop_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_resized_crop_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_resize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_resize_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_rotation_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_select_subpolicy_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_sharpness_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_solarize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_vertical_flip_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/random_vertical_flip_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rescale_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/resize_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/resize_preserve_ar_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/resize_with_bbox_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rgba_to_bgr_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rgba_to_rgb_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rgb_to_gray_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/rotate_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/swap_red_blue_ir.cc + ${MINDDATA_DIR}/kernels/ir/vision/uniform_aug_ir.cc ) target_link_libraries(minddata-lite diff --git a/tests/ut/cpp/dataset/ir_sampler_test.cc b/tests/ut/cpp/dataset/ir_sampler_test.cc index 9bb773c735..fa25a44d7a 100644 --- a/tests/ut/cpp/dataset/ir_sampler_test.cc +++ b/tests/ut/cpp/dataset/ir_sampler_test.cc @@ -15,7 +15,15 @@ */ #include "common/common.h" #include "minddata/dataset/engine/datasetops/source/sampler/sampler.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/distributed_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/pk_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/random_sampler_ir.h" #include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/sequential_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/subset_random_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/subset_sampler_ir.h" +#include "minddata/dataset/engine/ir/datasetops/source/samplers/weighted_random_sampler_ir.h" #include "minddata/dataset/core/tensor.h" using namespace mindspore::dataset; diff --git a/tests/ut/cpp/dataset/ir_vision_random_test.cc b/tests/ut/cpp/dataset/ir_vision_random_test.cc index d75959f20a..1d364e1daa 100644 --- a/tests/ut/cpp/dataset/ir_vision_random_test.cc +++ b/tests/ut/cpp/dataset/ir_vision_random_test.cc @@ -16,7 +16,25 @@ #include #include "common/common.h" -#include "minddata/dataset/kernels/ir/vision/vision_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" using namespace mindspore::dataset; diff --git a/tests/ut/cpp/dataset/ir_vision_test.cc b/tests/ut/cpp/dataset/ir_vision_test.cc index ccdac3c207..a14f8b48c1 100644 --- a/tests/ut/cpp/dataset/ir_vision_test.cc +++ b/tests/ut/cpp/dataset/ir_vision_test.cc @@ -17,7 +17,52 @@ #include #include #include "common/common.h" -#include "minddata/dataset/kernels/ir/vision/vision_ir.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" using namespace mindspore::dataset; diff --git a/tests/ut/cpp/dataset/optimization_pass_test.cc b/tests/ut/cpp/dataset/optimization_pass_test.cc index a80c9ae75b..fc77f074cf 100644 --- a/tests/ut/cpp/dataset/optimization_pass_test.cc +++ b/tests/ut/cpp/dataset/optimization_pass_test.cc @@ -28,7 +28,9 @@ #include "minddata/dataset/include/dataset/vision.h" #include "minddata/dataset/include/dataset/vision_lite.h" #include "minddata/dataset/kernels/ir/data/transforms_ir.h" -#include "minddata/dataset/kernels/ir/vision/vision_ir.h" +#include "minddata/dataset/kernels/ir/vision/decode_ir.h" +#include "minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.h" +#include "minddata/dataset/kernels/ir/vision/random_resized_crop_ir.h" using namespace mindspore::dataset; using mindspore::LogStream;