forked from mindspore-Ecosystem/mindspore
split sampler vision IR files
This commit is contained in:
parent
1e2e554db3
commit
9ce28cd34c
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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})
|
|
@ -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<SamplerRT> *sampler) {
|
||||
// runtime sampler object
|
||||
*sampler = std::make_shared<dataset::DistributedSamplerRT>(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<mindrecord::ShardOperator> DistributedSamplerObj::BuildForMindDataset() {
|
||||
// runtime mindrecord sampler object
|
||||
auto mind_sampler = std::make_shared<mindrecord::ShardDistributedSample>(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<nlohmann::json> 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<SamplerObj> DistributedSamplerObj::SamplerCopy() {
|
||||
auto sampler =
|
||||
std::make_shared<DistributedSamplerObj>(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
|
|
@ -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 <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#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<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> 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_
|
|
@ -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<nlohmann::json> 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<SamplerRT> *sampler) {
|
||||
// runtime sampler object
|
||||
*sampler = std::make_shared<dataset::PKSamplerRT>(num_samples_, num_val_, shuffle_);
|
||||
Status s = BuildChildren(sampler);
|
||||
sampler = s.IsOk() ? sampler : nullptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> PKSamplerObj::BuildForMindDataset() {
|
||||
// runtime mindrecord sampler object
|
||||
std::shared_ptr<mindrecord::ShardOperator> mind_sampler;
|
||||
if (shuffle_ == true) {
|
||||
mind_sampler = std::make_shared<mindrecord::ShardPkSample>("label", num_val_, std::numeric_limits<int64_t>::max(),
|
||||
GetSeed(), num_samples_);
|
||||
} else {
|
||||
mind_sampler = std::make_shared<mindrecord::ShardPkSample>("label", num_val_, num_samples_);
|
||||
}
|
||||
|
||||
return mind_sampler;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::shared_ptr<SamplerObj> PKSamplerObj::SamplerCopy() {
|
||||
auto sampler = std::make_shared<PKSamplerObj>(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
|
|
@ -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 <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#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<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> 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_
|
|
@ -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<SamplerRT> sampler) : sp_(std::move(sampler)) {}
|
||||
|
||||
// Destructor
|
||||
PreBuiltSamplerObj::~PreBuiltSamplerObj() = default;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
PreBuiltSamplerObj::PreBuiltSamplerObj(std::shared_ptr<mindrecord::ShardOperator> sampler)
|
||||
: sp_minddataset_(std::move(sampler)) {}
|
||||
#endif
|
||||
|
||||
Status PreBuiltSamplerObj::ValidateParams() { return Status::OK(); }
|
||||
|
||||
Status PreBuiltSamplerObj::SamplerBuild(std::shared_ptr<SamplerRT> *const sampler) {
|
||||
Status s = BuildChildren(&sp_);
|
||||
if (s.IsOk())
|
||||
*sampler = sp_;
|
||||
else
|
||||
*sampler = nullptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> PreBuiltSamplerObj::BuildForMindDataset() { return sp_minddataset_; }
|
||||
#endif
|
||||
|
||||
std::shared_ptr<SamplerObj> PreBuiltSamplerObj::SamplerCopy() {
|
||||
#ifndef ENABLE_ANDROID
|
||||
if (sp_minddataset_ != nullptr) {
|
||||
auto sampler = std::make_shared<PreBuiltSamplerObj>(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<PreBuiltSamplerObj>(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
|
|
@ -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 <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#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<SamplerRT> sampler);
|
||||
#ifndef ENABLE_ANDROID
|
||||
explicit PreBuiltSamplerObj(std::shared_ptr<mindrecord::ShardOperator> sampler);
|
||||
#endif
|
||||
|
||||
~PreBuiltSamplerObj();
|
||||
|
||||
Status SamplerBuild(std::shared_ptr<SamplerRT> *const sampler) override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> BuildForMindDataset() override;
|
||||
#endif
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
Status to_json(nlohmann::json *const out_json) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<SamplerRT> sp_;
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> sp_minddataset_;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_PREBUILT_SAMPLER_IR_H_
|
|
@ -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<nlohmann::json> 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<SamplerRT> *sampler) {
|
||||
// runtime sampler object
|
||||
*sampler = std::make_shared<dataset::RandomSamplerRT>(num_samples_, replacement_, reshuffle_each_epoch_);
|
||||
Status s = BuildChildren(sampler);
|
||||
sampler = s.IsOk() ? sampler : nullptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> RandomSamplerObj::BuildForMindDataset() {
|
||||
// runtime mindrecord sampler object
|
||||
auto mind_sampler =
|
||||
std::make_shared<mindrecord::ShardShuffle>(GetSeed(), num_samples_, replacement_, reshuffle_each_epoch_);
|
||||
|
||||
return mind_sampler;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::shared_ptr<SamplerObj> RandomSamplerObj::SamplerCopy() {
|
||||
auto sampler = std::make_shared<RandomSamplerObj>(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
|
|
@ -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 <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#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<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> 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_
|
|
@ -15,26 +15,9 @@
|
|||
*/
|
||||
|
||||
#include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h"
|
||||
#include "minddata/dataset/engine/datasetops/source/sampler/sampler.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
|
||||
|
||||
namespace mindspore {
|
||||
namespace dataset {
|
||||
|
@ -42,6 +25,9 @@ namespace dataset {
|
|||
// Constructor
|
||||
SamplerObj::SamplerObj() {}
|
||||
|
||||
// Destructor
|
||||
SamplerObj::~SamplerObj() = default;
|
||||
|
||||
Status SamplerObj::BuildChildren(std::shared_ptr<SamplerRT> *const sampler) {
|
||||
for (auto child : children_) {
|
||||
std::shared_ptr<SamplerRT> sampler_rt = nullptr;
|
||||
|
@ -72,492 +58,5 @@ Status SamplerObj::AddChildSampler(std::shared_ptr<SamplerObj> 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<SamplerRT> *sampler) {
|
||||
// runtime sampler object
|
||||
*sampler = std::make_shared<dataset::DistributedSamplerRT>(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<mindrecord::ShardOperator> DistributedSamplerObj::BuildForMindDataset() {
|
||||
// runtime mindrecord sampler object
|
||||
auto mind_sampler = std::make_shared<mindrecord::ShardDistributedSample>(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<nlohmann::json> 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<SamplerObj> DistributedSamplerObj::SamplerCopy() {
|
||||
auto sampler =
|
||||
std::make_shared<DistributedSamplerObj>(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<nlohmann::json> 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<SamplerRT> *sampler) {
|
||||
// runtime sampler object
|
||||
*sampler = std::make_shared<dataset::PKSamplerRT>(num_samples_, num_val_, shuffle_);
|
||||
Status s = BuildChildren(sampler);
|
||||
sampler = s.IsOk() ? sampler : nullptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> PKSamplerObj::BuildForMindDataset() {
|
||||
// runtime mindrecord sampler object
|
||||
std::shared_ptr<mindrecord::ShardOperator> mind_sampler;
|
||||
if (shuffle_ == true) {
|
||||
mind_sampler = std::make_shared<mindrecord::ShardPkSample>("label", num_val_, std::numeric_limits<int64_t>::max(),
|
||||
GetSeed(), num_samples_);
|
||||
} else {
|
||||
mind_sampler = std::make_shared<mindrecord::ShardPkSample>("label", num_val_, num_samples_);
|
||||
}
|
||||
|
||||
return mind_sampler;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::shared_ptr<SamplerObj> PKSamplerObj::SamplerCopy() {
|
||||
auto sampler = std::make_shared<PKSamplerObj>(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<SamplerRT> sampler) : sp_(std::move(sampler)) {}
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
PreBuiltSamplerObj::PreBuiltSamplerObj(std::shared_ptr<mindrecord::ShardOperator> sampler)
|
||||
: sp_minddataset_(std::move(sampler)) {}
|
||||
#endif
|
||||
|
||||
Status PreBuiltSamplerObj::ValidateParams() { return Status::OK(); }
|
||||
|
||||
Status PreBuiltSamplerObj::SamplerBuild(std::shared_ptr<SamplerRT> *const sampler) {
|
||||
Status s = BuildChildren(&sp_);
|
||||
if (s.IsOk())
|
||||
*sampler = sp_;
|
||||
else
|
||||
*sampler = nullptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> PreBuiltSamplerObj::BuildForMindDataset() { return sp_minddataset_; }
|
||||
#endif
|
||||
|
||||
std::shared_ptr<SamplerObj> PreBuiltSamplerObj::SamplerCopy() {
|
||||
#ifndef ENABLE_ANDROID
|
||||
if (sp_minddataset_ != nullptr) {
|
||||
auto sampler = std::make_shared<PreBuiltSamplerObj>(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<PreBuiltSamplerObj>(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<nlohmann::json> 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<SamplerRT> *sampler) {
|
||||
// runtime sampler object
|
||||
*sampler = std::make_shared<dataset::RandomSamplerRT>(num_samples_, replacement_, reshuffle_each_epoch_);
|
||||
Status s = BuildChildren(sampler);
|
||||
sampler = s.IsOk() ? sampler : nullptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> RandomSamplerObj::BuildForMindDataset() {
|
||||
// runtime mindrecord sampler object
|
||||
auto mind_sampler =
|
||||
std::make_shared<mindrecord::ShardShuffle>(GetSeed(), num_samples_, replacement_, reshuffle_each_epoch_);
|
||||
|
||||
return mind_sampler;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::shared_ptr<SamplerObj> RandomSamplerObj::SamplerCopy() {
|
||||
auto sampler = std::make_shared<RandomSamplerObj>(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<nlohmann::json> 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<SamplerRT> *sampler) {
|
||||
// runtime sampler object
|
||||
*sampler = std::make_shared<dataset::SequentialSamplerRT>(num_samples_, start_index_);
|
||||
Status s = BuildChildren(sampler);
|
||||
sampler = s.IsOk() ? sampler : nullptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> SequentialSamplerObj::BuildForMindDataset() {
|
||||
// runtime mindrecord sampler object
|
||||
auto mind_sampler = std::make_shared<mindrecord::ShardSequentialSample>(num_samples_, start_index_);
|
||||
|
||||
return mind_sampler;
|
||||
}
|
||||
#endif
|
||||
std::shared_ptr<SamplerObj> SequentialSamplerObj::SamplerCopy() {
|
||||
auto sampler = std::make_shared<SequentialSamplerObj>(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<int64_t> 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<SamplerRT> *sampler) {
|
||||
// runtime sampler object
|
||||
*sampler = std::make_shared<dataset::SubsetSamplerRT>(num_samples_, indices_);
|
||||
Status s = BuildChildren(sampler);
|
||||
sampler = s.IsOk() ? sampler : nullptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> SubsetSamplerObj::BuildForMindDataset() {
|
||||
// runtime mindrecord sampler object
|
||||
auto mind_sampler = std::make_shared<mindrecord::ShardSample>(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<nlohmann::json> 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<SamplerObj> SubsetSamplerObj::SamplerCopy() {
|
||||
auto sampler = std::make_shared<SubsetSamplerObj>(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<int64_t> indices, int64_t num_samples)
|
||||
: SubsetSamplerObj(std::move(indices), num_samples) {}
|
||||
|
||||
Status SubsetRandomSamplerObj::SamplerBuild(std::shared_ptr<SamplerRT> *sampler) {
|
||||
// runtime sampler object
|
||||
*sampler = std::make_shared<dataset::SubsetRandomSamplerRT>(num_samples_, indices_);
|
||||
Status s = BuildChildren(sampler);
|
||||
sampler = s.IsOk() ? sampler : nullptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> SubsetRandomSamplerObj::BuildForMindDataset() {
|
||||
// runtime mindrecord sampler object
|
||||
auto mind_sampler = std::make_shared<mindrecord::ShardSample>(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<nlohmann::json> 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<SamplerObj> SubsetRandomSamplerObj::SamplerCopy() {
|
||||
auto sampler = std::make_shared<SubsetRandomSamplerObj>(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<double> 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<nlohmann::json> 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<SamplerRT> *sampler) {
|
||||
*sampler = std::make_shared<dataset::WeightedRandomSamplerRT>(num_samples_, weights_, replacement_);
|
||||
Status s = BuildChildren(sampler);
|
||||
sampler = s.IsOk() ? sampler : nullptr;
|
||||
return s;
|
||||
}
|
||||
std::shared_ptr<SamplerObj> WeightedRandomSamplerObj::SamplerCopy() {
|
||||
auto sampler = std::make_shared<WeightedRandomSamplerObj>(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
|
||||
|
|
|
@ -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<std::shared_ptr<SamplerObj>> 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<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> 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<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> 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<SamplerRT> sampler);
|
||||
#ifndef ENABLE_ANDROID
|
||||
explicit PreBuiltSamplerObj(std::shared_ptr<mindrecord::ShardOperator> sampler);
|
||||
#endif
|
||||
|
||||
~PreBuiltSamplerObj() = default;
|
||||
|
||||
Status SamplerBuild(std::shared_ptr<SamplerRT> *const sampler) override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> BuildForMindDataset() override;
|
||||
#endif
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
Status to_json(nlohmann::json *const out_json) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<SamplerRT> sp_;
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> 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<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> 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<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> 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<int64_t> indices, int64_t num_samples);
|
||||
|
||||
~SubsetSamplerObj() = default;
|
||||
|
||||
Status SamplerBuild(std::shared_ptr<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> 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<int64_t> indices_;
|
||||
int64_t num_samples_;
|
||||
};
|
||||
|
||||
class SubsetRandomSamplerObj : public SubsetSamplerObj {
|
||||
public:
|
||||
SubsetRandomSamplerObj(std::vector<int64_t> indices, int64_t num_samples);
|
||||
|
||||
~SubsetRandomSamplerObj() = default;
|
||||
|
||||
Status to_json(nlohmann::json *const out_json) override;
|
||||
|
||||
Status SamplerBuild(std::shared_ptr<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> BuildForMindDataset() override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class WeightedRandomSamplerObj : public SamplerObj {
|
||||
public:
|
||||
explicit WeightedRandomSamplerObj(std::vector<double> weights, int64_t num_samples = 0, bool replacement = true);
|
||||
|
||||
~WeightedRandomSamplerObj() = default;
|
||||
|
||||
Status SamplerBuild(std::shared_ptr<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> 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<double> weights_;
|
||||
int64_t num_samples_;
|
||||
bool replacement_;
|
||||
};
|
||||
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SAMPLERS_IR_H_
|
||||
|
|
|
@ -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<nlohmann::json> 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<SamplerRT> *sampler) {
|
||||
// runtime sampler object
|
||||
*sampler = std::make_shared<dataset::SequentialSamplerRT>(num_samples_, start_index_);
|
||||
Status s = BuildChildren(sampler);
|
||||
sampler = s.IsOk() ? sampler : nullptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> SequentialSamplerObj::BuildForMindDataset() {
|
||||
// runtime mindrecord sampler object
|
||||
auto mind_sampler = std::make_shared<mindrecord::ShardSequentialSample>(num_samples_, start_index_);
|
||||
|
||||
return mind_sampler;
|
||||
}
|
||||
#endif
|
||||
std::shared_ptr<SamplerObj> SequentialSamplerObj::SamplerCopy() {
|
||||
auto sampler = std::make_shared<SequentialSamplerObj>(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
|
|
@ -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 <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#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<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> 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_
|
|
@ -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<int64_t> indices, int64_t num_samples)
|
||||
: SubsetSamplerObj(std::move(indices), num_samples) {}
|
||||
|
||||
// Destructor
|
||||
SubsetRandomSamplerObj::~SubsetRandomSamplerObj() = default;
|
||||
|
||||
Status SubsetRandomSamplerObj::SamplerBuild(std::shared_ptr<SamplerRT> *sampler) {
|
||||
// runtime sampler object
|
||||
*sampler = std::make_shared<dataset::SubsetRandomSamplerRT>(num_samples_, indices_);
|
||||
Status s = BuildChildren(sampler);
|
||||
sampler = s.IsOk() ? sampler : nullptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> SubsetRandomSamplerObj::BuildForMindDataset() {
|
||||
// runtime mindrecord sampler object
|
||||
auto mind_sampler = std::make_shared<mindrecord::ShardSample>(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<nlohmann::json> 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<SamplerObj> SubsetRandomSamplerObj::SamplerCopy() {
|
||||
auto sampler = std::make_shared<SubsetRandomSamplerObj>(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
|
|
@ -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 <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#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<int64_t> indices, int64_t num_samples);
|
||||
|
||||
~SubsetRandomSamplerObj();
|
||||
|
||||
Status to_json(nlohmann::json *const out_json) override;
|
||||
|
||||
Status SamplerBuild(std::shared_ptr<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> BuildForMindDataset() override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SUBSET_RANDOM_SAMPLER_IR_H_
|
|
@ -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<int64_t> 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<SamplerRT> *sampler) {
|
||||
// runtime sampler object
|
||||
*sampler = std::make_shared<dataset::SubsetSamplerRT>(num_samples_, indices_);
|
||||
Status s = BuildChildren(sampler);
|
||||
sampler = s.IsOk() ? sampler : nullptr;
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> SubsetSamplerObj::BuildForMindDataset() {
|
||||
// runtime mindrecord sampler object
|
||||
auto mind_sampler = std::make_shared<mindrecord::ShardSample>(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<nlohmann::json> 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<SamplerObj> SubsetSamplerObj::SamplerCopy() {
|
||||
auto sampler = std::make_shared<SubsetSamplerObj>(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
|
|
@ -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 <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#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<int64_t> indices, int64_t num_samples);
|
||||
|
||||
~SubsetSamplerObj();
|
||||
|
||||
Status SamplerBuild(std::shared_ptr<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> SamplerCopy() override;
|
||||
|
||||
#ifndef ENABLE_ANDROID
|
||||
std::shared_ptr<mindrecord::ShardOperator> 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<int64_t> indices_;
|
||||
int64_t num_samples_;
|
||||
};
|
||||
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SUBSET_SAMPLER_IR_H_
|
|
@ -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<double> 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<nlohmann::json> 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<SamplerRT> *sampler) {
|
||||
*sampler = std::make_shared<dataset::WeightedRandomSamplerRT>(num_samples_, weights_, replacement_);
|
||||
Status s = BuildChildren(sampler);
|
||||
sampler = s.IsOk() ? sampler : nullptr;
|
||||
return s;
|
||||
}
|
||||
std::shared_ptr<SamplerObj> WeightedRandomSamplerObj::SamplerCopy() {
|
||||
auto sampler = std::make_shared<WeightedRandomSamplerObj>(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
|
|
@ -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 <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#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<double> weights, int64_t num_samples = 0, bool replacement = true);
|
||||
|
||||
~WeightedRandomSamplerObj();
|
||||
|
||||
Status SamplerBuild(std::shared_ptr<SamplerRT> *sampler) override;
|
||||
|
||||
std::shared_ptr<SamplerObj> 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<double> 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_
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<float> &translation, float scale,
|
||||
const std::vector<float> &shear, InterpolationMode interpolation,
|
||||
const std::vector<uint8_t> &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<TensorOp> AffineOperation::Build() {
|
||||
std::shared_ptr<AffineOp> tensor_op =
|
||||
std::make_shared<AffineOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<float> &translation, float scale,
|
||||
const std::vector<float> &shear, InterpolationMode interpolation,
|
||||
const std::vector<uint8_t> &fill_value);
|
||||
|
||||
~AffineOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
float degrees_;
|
||||
std::vector<float> translation_;
|
||||
float scale_;
|
||||
std::vector<float> shear_;
|
||||
InterpolationMode interpolation_;
|
||||
std::vector<uint8_t> fill_value_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_AFFINE_IR_H_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<uint32_t> 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<TensorOp> AutoContrastOperation::Build() {
|
||||
std::shared_ptr<AutoContrastOp> tensor_op = std::make_shared<AutoContrastOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<uint32_t> ignore);
|
||||
|
||||
~AutoContrastOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
float cutoff_;
|
||||
std::vector<uint32_t> ignore_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_AUTO_CONTRAST_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.
|
||||
*/
|
||||
#include <algorithm>
|
||||
|
||||
#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<TensorOperation> 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<TensorOp> BoundingBoxAugmentOperation::Build() {
|
||||
std::shared_ptr<BoundingBoxAugmentOp> tensor_op = std::make_shared<BoundingBoxAugmentOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOperation> transform, float ratio);
|
||||
|
||||
~BoundingBoxAugmentOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<TensorOperation> transform_;
|
||||
float ratio_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // 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.
|
||||
*/
|
||||
#include <algorithm>
|
||||
|
||||
#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<int32_t> 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<TensorOp> 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<CenterCropOp> tensor_op = std::make_shared<CenterCropOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<int32_t> size);
|
||||
|
||||
~CenterCropOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<int32_t> size_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_CENTER_CROP_IR_H_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<int32_t> coordinates, std::vector<int32_t> 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<TensorOp> 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<CropOp> tensor_op = std::make_shared<CropOp>(x, y, height, width);
|
||||
return tensor_op;
|
||||
}
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<int32_t> coordinates, std::vector<int32_t> size);
|
||||
|
||||
~CropOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
private:
|
||||
std::vector<int32_t> coordinates_;
|
||||
std::vector<int32_t> size_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_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.
|
||||
*/
|
||||
#include <algorithm>
|
||||
|
||||
#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<TensorOp> CutMixBatchOperation::Build() {
|
||||
std::shared_ptr<CutMixBatchOp> tensor_op = std::make_shared<CutMixBatchOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<TensorOp> CutOutOperation::Build() {
|
||||
std::shared_ptr<CutOutOp> tensor_op = std::make_shared<CutOutOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<TensorOp> DecodeOperation::Build() { return std::make_shared<DecodeOp>(rgb_); }
|
||||
|
||||
Status DecodeOperation::to_json(nlohmann::json *out_json) {
|
||||
(*out_json)["rgb"] = rgb_;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<TensorOp> EqualizeOperation::Build() { return std::make_shared<EqualizeOp>(); }
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<TensorOp> HwcToChwOperation::Build() { return std::make_shared<HwcToChwOp>(); }
|
||||
#endif
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<TensorOp> InvertOperation::Build() { return std::make_shared<InvertOp>(); }
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<TensorOp> MixUpBatchOperation::Build() { return std::make_shared<MixUpBatchOp>(alpha_); }
|
||||
|
||||
Status MixUpBatchOperation::to_json(nlohmann::json *out_json) {
|
||||
(*out_json)["alpha"] = alpha_;
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<float> mean, std::vector<float> 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<TensorOp> NormalizeOperation::Build() {
|
||||
return std::make_shared<NormalizeOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<float> mean, std::vector<float> std);
|
||||
|
||||
~NormalizeOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<float> mean_;
|
||||
std::vector<float> std_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_NORMALIZE_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.
|
||||
*/
|
||||
#include <algorithm>
|
||||
|
||||
#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<float> &mean, const std::vector<float> &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<TensorOp> NormalizePadOperation::Build() {
|
||||
return std::make_shared<NormalizePadOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<float> &mean, const std::vector<float> &std, const std::string &dtype);
|
||||
|
||||
~NormalizePadOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<float> mean_;
|
||||
std::vector<float> std_;
|
||||
std::string dtype_;
|
||||
};
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_NORMALIZE_PAD_IR_H_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<int32_t> padding, std::vector<uint8_t> 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<TensorOp> 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<PadOp> tensor_op =
|
||||
std::make_shared<PadOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<int32_t> padding, std::vector<uint8_t> fill_value, BorderType padding_mode);
|
||||
|
||||
~PadOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<int32_t> padding_;
|
||||
std::vector<uint8_t> fill_value_;
|
||||
BorderType padding_mode_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_PAD_IR_H_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<float_t> °rees,
|
||||
const std::vector<float_t> &translate_range,
|
||||
const std::vector<float_t> &scale_range,
|
||||
const std::vector<float_t> &shear_ranges, InterpolationMode interpolation,
|
||||
const std::vector<uint8_t> &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<TensorOp> RandomAffineOperation::Build() {
|
||||
if (shear_ranges_.size() == 2) {
|
||||
shear_ranges_.resize(4);
|
||||
}
|
||||
if (translate_range_.size() == 2) {
|
||||
translate_range_.resize(4);
|
||||
}
|
||||
std::vector<uint8_t> 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<RandomAffineOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<float_t> °rees, const std::vector<float_t> &translate_range,
|
||||
const std::vector<float_t> &scale_range, const std::vector<float_t> &shear_ranges,
|
||||
InterpolationMode interpolation, const std::vector<uint8_t> &fill_value);
|
||||
|
||||
~RandomAffineOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<float_t> degrees_; // min_degree, max_degree
|
||||
std::vector<float_t> translate_range_; // maximum x translation percentage, maximum y translation percentage
|
||||
std::vector<float_t> scale_range_; // min_scale, max_scale
|
||||
std::vector<float_t> shear_ranges_; // min_x_shear, max_x_shear, min_y_shear, max_y_shear
|
||||
InterpolationMode interpolation_;
|
||||
std::vector<uint8_t> fill_value_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_AFFINE_IR_H_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<float> brightness, std::vector<float> contrast,
|
||||
std::vector<float> saturation, std::vector<float> 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<TensorOp> 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<RandomColorAdjustOp> tensor_op = std::make_shared<RandomColorAdjustOp>(
|
||||
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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<float> brightness, std::vector<float> contrast, std::vector<float> saturation,
|
||||
std::vector<float> hue);
|
||||
|
||||
~RandomColorAdjustOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<float> brightness_;
|
||||
std::vector<float> contrast_;
|
||||
std::vector<float> saturation_;
|
||||
std::vector<float> hue_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_COLOR_ADJUST_IR_H_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<TensorOp> RandomColorOperation::Build() {
|
||||
std::shared_ptr<RandomColorOp> tensor_op = std::make_shared<RandomColorOp>(t_lb_, t_ub_);
|
||||
return tensor_op;
|
||||
}
|
||||
|
||||
Status RandomColorOperation::to_json(nlohmann::json *out_json) {
|
||||
(*out_json)["degrees"] = std::vector<float>{t_lb_, t_ub_};
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<int32_t> size, std::vector<float> scale,
|
||||
std::vector<float> 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<TensorOp> 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<RandomCropDecodeResizeOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<int32_t> size, std::vector<float> scale, std::vector<float> ratio,
|
||||
InterpolationMode interpolation, int32_t max_attempts);
|
||||
|
||||
explicit RandomCropDecodeResizeOperation(const RandomResizedCropOperation &base);
|
||||
|
||||
~RandomCropDecodeResizeOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<int32_t> size, std::vector<int32_t> padding, bool pad_if_needed,
|
||||
std::vector<uint8_t> 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<TensorOp> 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<RandomCropOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<int32_t> size, std::vector<int32_t> padding, bool pad_if_needed,
|
||||
std::vector<uint8_t> fill_value, BorderType padding_mode);
|
||||
|
||||
~RandomCropOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<int32_t> size_;
|
||||
std::vector<int32_t> padding_;
|
||||
bool pad_if_needed_;
|
||||
std::vector<uint8_t> fill_value_;
|
||||
BorderType padding_mode_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_CROP_IR_H_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<int32_t> size, std::vector<int32_t> padding,
|
||||
bool pad_if_needed, std::vector<uint8_t> 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<TensorOp> 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<RandomCropWithBBoxOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<int32_t> size, std::vector<int32_t> padding, bool pad_if_needed,
|
||||
std::vector<uint8_t> fill_value, BorderType padding_mode);
|
||||
|
||||
~RandomCropWithBBoxOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<int32_t> size_;
|
||||
std::vector<int32_t> padding_;
|
||||
bool pad_if_needed_;
|
||||
std::vector<uint8_t> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<TensorOp> RandomHorizontalFlipOperation::Build() {
|
||||
std::shared_ptr<RandomHorizontalFlipOp> tensor_op = std::make_shared<RandomHorizontalFlipOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<TensorOp> RandomHorizontalFlipWithBBoxOperation::Build() {
|
||||
std::shared_ptr<RandomHorizontalFlipWithBBoxOp> tensor_op =
|
||||
std::make_shared<RandomHorizontalFlipWithBBoxOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<uint8_t> &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<TensorOp> RandomPosterizeOperation::Build() {
|
||||
std::shared_ptr<RandomPosterizeOp> tensor_op = std::make_shared<RandomPosterizeOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<uint8_t> &bit_range);
|
||||
|
||||
~RandomPosterizeOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> bit_range_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_POSTERIZE_IR_H_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<int32_t> 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<TensorOp> 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<RandomResizeOp> tensor_op = std::make_shared<RandomResizeOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<int32_t> size);
|
||||
|
||||
~RandomResizeOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<int32_t> size_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZE_IR_H_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<int32_t> 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<TensorOp> 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<RandomResizeWithBBoxOp> tensor_op = std::make_shared<RandomResizeWithBBoxOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<int32_t> size);
|
||||
|
||||
~RandomResizeWithBBoxOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<int32_t> size_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_RESIZE_WITH_BBOX_IR_H_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<int32_t> size, std::vector<float> scale,
|
||||
std::vector<float> 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<TensorOp> 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<RandomCropAndResizeOp> tensor_op = std::make_shared<RandomCropAndResizeOp>(
|
||||
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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<int32_t> size, std::vector<float> scale, std::vector<float> ratio,
|
||||
InterpolationMode interpolation, int32_t max_attempts);
|
||||
|
||||
/// \brief default copy constructor
|
||||
explicit RandomResizedCropOperation(const RandomResizedCropOperation &);
|
||||
|
||||
~RandomResizedCropOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
protected:
|
||||
std::vector<int32_t> size_;
|
||||
std::vector<float> scale_;
|
||||
std::vector<float> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<int32_t> size,
|
||||
std::vector<float> scale,
|
||||
std::vector<float> 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<TensorOp> 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<RandomCropAndResizeWithBBoxOp> tensor_op = std::make_shared<RandomCropAndResizeWithBBoxOp>(
|
||||
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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<int32_t> size, std::vector<float> scale,
|
||||
std::vector<float> ratio, InterpolationMode interpolation,
|
||||
int32_t max_attempts);
|
||||
|
||||
~RandomResizedCropWithBBoxOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<int32_t> size_;
|
||||
std::vector<float> scale_;
|
||||
std::vector<float> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<float> degrees, InterpolationMode interpolation_mode,
|
||||
bool expand, std::vector<float> center,
|
||||
std::vector<uint8_t> 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<TensorOp> 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<RandomRotationOp> tensor_op = std::make_shared<RandomRotationOp>(
|
||||
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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<float> degrees, InterpolationMode interpolation_mode, bool expand,
|
||||
std::vector<float> center, std::vector<uint8_t> fill_value);
|
||||
|
||||
~RandomRotationOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<float> degrees_;
|
||||
InterpolationMode interpolation_mode_;
|
||||
std::vector<float> center_;
|
||||
bool expand_;
|
||||
std::vector<uint8_t> fill_value_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_ROTATION_IR_H_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<std::vector<std::pair<std::shared_ptr<TensorOperation>, 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<TensorOp> RandomSelectSubpolicyOperation::Build() {
|
||||
std::vector<Subpolicy> 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<RandomSelectSubpolicyOp> tensor_op = std::make_shared<RandomSelectSubpolicyOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<std::vector<std::pair<std::shared_ptr<TensorOperation>, double>>> policy);
|
||||
|
||||
~RandomSelectSubpolicyOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<std::vector<std::pair<std::shared_ptr<TensorOperation>, double>>> policy_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_SELECT_SUBPOLICY_IR_H_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<float> 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<TensorOp> RandomSharpnessOperation::Build() {
|
||||
std::shared_ptr<RandomSharpnessOp> tensor_op = std::make_shared<RandomSharpnessOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<float> degrees);
|
||||
|
||||
~RandomSharpnessOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<float> degrees_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_SHARPNESS_IR_H_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<uint8_t> 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<TensorOp> RandomSolarizeOperation::Build() {
|
||||
std::shared_ptr<RandomSolarizeOp> tensor_op = std::make_shared<RandomSolarizeOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<uint8_t> threshold);
|
||||
|
||||
~RandomSolarizeOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> threshold_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RANDOM_SOLARIZE_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.
|
||||
*/
|
||||
#include <algorithm>
|
||||
|
||||
#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<TensorOp> RandomVerticalFlipOperation::Build() {
|
||||
std::shared_ptr<RandomVerticalFlipOp> tensor_op = std::make_shared<RandomVerticalFlipOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<TensorOp> RandomVerticalFlipWithBBoxOperation::Build() {
|
||||
std::shared_ptr<RandomVerticalFlipWithBBoxOp> tensor_op =
|
||||
std::make_shared<RandomVerticalFlipWithBBoxOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<TensorOp> RescaleOperation::Build() {
|
||||
std::shared_ptr<RescaleOp> tensor_op = std::make_shared<RescaleOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
|
@ -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 <algorithm>
|
||||
|
||||
#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<int32_t> 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<TensorOp> 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<ResizeOp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<int32_t> size, InterpolationMode interpolation_mode);
|
||||
|
||||
~ResizeOperation();
|
||||
|
||||
std::shared_ptr<TensorOp> Build() override;
|
||||
|
||||
Status ValidateParams() override;
|
||||
|
||||
std::string Name() const override;
|
||||
|
||||
Status to_json(nlohmann::json *out_json) override;
|
||||
|
||||
private:
|
||||
std::vector<int32_t> size_;
|
||||
InterpolationMode interpolation_;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
} // namespace dataset
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_VISION_RESIZE_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.
|
||||
*/
|
||||
#include <algorithm>
|
||||
|
||||
#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<TensorOp> ResizePreserveAROperation::Build() {
|
||||
return std::make_shared<ResizePreserveAROp>(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
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<TensorOp> 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_
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue