!26527 dataset: enhance error msg

Merge pull request !26527 from ms_yan/log_abstract
This commit is contained in:
i-robot 2021-11-30 02:22:07 +00:00 committed by Gitee
commit b44bba6a19
52 changed files with 193 additions and 139 deletions

View File

@ -46,6 +46,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
#ifdef ENABLE_PYTHON
#include "minddata/dataset/kernels/py_func_op.h"
#endif
@ -175,7 +176,7 @@ Status OneHotOperation::to_json(nlohmann::json *out_json) {
}
Status OneHotOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("num_classes") != op_params.end(), "Failed tofind num_classes");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "num_classes", kOneHotOperation));
int32_t num_classes = op_params["num_classes"];
*operation = std::make_shared<transforms::OneHotOperation>(num_classes);
return Status::OK();
@ -281,7 +282,7 @@ Status TypeCastOperation::to_json(nlohmann::json *out_json) {
}
Status TypeCastOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("data_type") != op_params.end(), "Failed tofind data_type");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "data_type", kTypeCastOperation));
std::string data_type = op_params["data_type"];
*operation = std::make_shared<transforms::TypeCastOperation>(data_type);
return Status::OK();

View File

@ -20,6 +20,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -49,8 +50,8 @@ Status AdjustGammaOperation::to_json(nlohmann::json *out_json) {
}
Status AdjustGammaOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("gamma") != op_params.end(), "Failed to find gamma");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("gain") != op_params.end(), "Failed to find gain");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "gamma", kAdjustGammaOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "gain", kAdjustGammaOperation));
float gamma = op_params["gamma"];
float gain = op_params["gain"];
*operation = std::make_shared<vision::AdjustGammaOperation>(gamma, gain);

View File

@ -18,6 +18,7 @@
#include "minddata/dataset/kernels/image/affine_op.h"
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -84,12 +85,12 @@ Status AffineOperation::to_json(nlohmann::json *out_json) {
}
Status AffineOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("degrees") != op_params.end(), "Failed to find degrees");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("translate") != op_params.end(), "Failed to find translate");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("scale") != op_params.end(), "Failed to find scale");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("shear") != op_params.end(), "Failed to find shear");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("resample") != op_params.end(), "Failed to find resample");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("fill_value") != op_params.end(), "Failed to find fill_value");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "degrees", kAffineOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "translate", kAffineOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "scale", kAffineOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "shear", kAffineOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "resample", kAffineOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "fill_value", kAffineOperation));
float_t degrees = op_params["degrees"];
std::vector<float> translation = op_params["translate"];
float scale = op_params["scale"];

View File

@ -24,6 +24,7 @@
#include "minddata/dataset/kernels/image/dvpp/dvpp_decode_png_op.h"
#include "minddata/dataset/kernels/image/dvpp/dvpp_normalize_op.h"
#include "minddata/dataset/kernels/image/dvpp/dvpp_resize_jpeg_op.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -78,7 +79,7 @@ Status DvppCropJpegOperation::to_json(nlohmann::json *out_json) {
}
Status DvppCropJpegOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Fail to find size");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kDvppCropJpegOperation));
std::vector<uint32_t> resize = op_params["size"];
*operation = std::make_shared<vision::DvppCropJpegOperation>(resize);
return Status::OK();
@ -132,7 +133,7 @@ Status DvppDecodeResizeOperation::to_json(nlohmann::json *out_json) {
}
Status DvppDecodeResizeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Fail to find size");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kDvppDecodeResizeOperation));
std::vector<uint32_t> resize = op_params["size"];
*operation = std::make_shared<vision::DvppDecodeResizeOperation>(resize);
return Status::OK();
@ -236,8 +237,8 @@ Status DvppDecodeResizeCropOperation::to_json(nlohmann::json *out_json) {
}
Status DvppDecodeResizeCropOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("crop_size") != op_params.end(), "Fail to find crop_size");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("resize_size") != op_params.end(), "Fail to find resize_size");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "crop_size", kDvppDecodeResizeCropOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "resize_size", kDvppDecodeResizeCropOperation));
std::vector<uint32_t> crop = op_params["crop_size"];
std::vector<uint32_t> resize = op_params["resize_size"];
*operation = std::make_shared<vision::DvppDecodeResizeCropOperation>(crop, resize);
@ -304,8 +305,8 @@ Status DvppNormalizeOperation::to_json(nlohmann::json *out_json) {
}
Status DvppNormalizeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("mean") != op_params.end(), "Fail to find mean");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("std") != op_params.end(), "Fail to find std");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "mean", kDvppNormalizeOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "std", kDvppNormalizeOperation));
std::vector<float> mean = op_params["mean"];
std::vector<float> std = op_params["std"];
*operation = std::make_shared<vision::DvppNormalizeOperation>(mean, std);
@ -359,7 +360,7 @@ Status DvppResizeJpegOperation::to_json(nlohmann::json *out_json) {
}
Status DvppResizeJpegOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Fail to find size");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kDvppResizeJpegOperation));
std::vector<uint32_t> resize = op_params["size"];
*operation = std::make_shared<vision::DvppResizeJpegOperation>(resize);
return Status::OK();

View File

@ -20,6 +20,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -64,9 +65,9 @@ Status AutoAugmentOperation::to_json(nlohmann::json *out_json) {
}
Status AutoAugmentOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("policy") != op_params.end(), "Failed to find degrees");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("interpolation") != op_params.end(), "Failed to find translate");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("fill_value") != op_params.end(), "Failed to find scale");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "policy", kAutoAugmentOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "interpolation", kAutoAugmentOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "fill_value", kAutoAugmentOperation));
AutoAugmentPolicy policy = op_params["policy"];
InterpolationMode interpolation = op_params["interpolation"];
std::vector<uint8_t> fill_value = op_params["fill_value"];

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -66,8 +67,8 @@ Status AutoContrastOperation::to_json(nlohmann::json *out_json) {
}
Status AutoContrastOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("cutoff") != op_params.end(), "Failed to find cutoff");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("ignore") != op_params.end(), "Failed to find ignore");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "cutoff", kAutoContrastOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "ignore", kAutoContrastOperation));
float cutoff = op_params["cutoff"];
std::vector<uint32_t> ignore = op_params["ignore"];
*operation = std::make_shared<vision::AutoContrastOperation>(cutoff, ignore);

View File

@ -23,6 +23,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -59,8 +60,8 @@ Status BoundingBoxAugmentOperation::to_json(nlohmann::json *out_json) {
}
Status BoundingBoxAugmentOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("transform") != op_params.end(), "Failed to find transform");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("ratio") != op_params.end(), "Failed to find ratio");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "transform", kBoundingBoxAugmentOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "ratio", kBoundingBoxAugmentOperation));
std::vector<std::shared_ptr<TensorOperation>> transforms;
std::vector<nlohmann::json> json_operations = {};
json_operations.push_back(op_params["transform"]);

View File

@ -18,6 +18,7 @@
#include "minddata/dataset/kernels/image/center_crop_op.h"
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -53,7 +54,7 @@ Status CenterCropOperation::to_json(nlohmann::json *out_json) {
}
Status CenterCropOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kCenterCropOperation));
std::vector<int32_t> size = op_params["size"];
*operation = std::make_shared<CenterCropOperation>(size);
return Status::OK();

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -55,7 +56,7 @@ Status ConvertColorOperation::to_json(nlohmann::json *out_json) {
}
Status ConvertColorOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("convert_mode") != op_params.end(), "Failed to find convert_mode");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "convert_mode", kConvertColorOperation));
ConvertMode convert_mode = static_cast<ConvertMode>(op_params["convert_mode"]);
*operation = std::make_shared<vision::ConvertColorOperation>(convert_mode);
return Status::OK();

View File

@ -18,6 +18,7 @@
#include "minddata/dataset/kernels/image/crop_op.h"
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -68,8 +69,8 @@ Status CropOperation::to_json(nlohmann::json *out_json) {
}
Status CropOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("coordinates") != op_params.end(), "Failed to find coordinates");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "coordinates", kCropOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kCropOperation));
std::vector<int32_t> coordinates = op_params["coordinates"];
std::vector<int32_t> size = op_params["size"];
*operation = std::make_shared<CropOperation>(coordinates, size);

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -60,10 +61,9 @@ Status CutMixBatchOperation::to_json(nlohmann::json *out_json) {
}
Status CutMixBatchOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("image_batch_format") != op_params.end(),
"Failed to find image_batch_format");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("alpha") != op_params.end(), "Failed to find alpha");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("prob") != op_params.end(), "Failed to find prob");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "image_batch_format", kCutMixBatchOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "alpha", kCutMixBatchOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "prob", kCutMixBatchOperation));
ImageBatchFormat image_batch = static_cast<ImageBatchFormat>(op_params["image_batch_format"]);
float alpha = op_params["alpha"];
float prob = op_params["prob"];

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -53,8 +54,8 @@ Status CutOutOperation::to_json(nlohmann::json *out_json) {
}
Status CutOutOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("length") != op_params.end(), "Failed to find length");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("num_patches") != op_params.end(), "Failed to find num_patches");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "length", kCutOutOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "num_patches", kCutOutOperation));
int32_t length = op_params["length"];
int32_t num_patches = op_params["num_patches"];
*operation = std::make_shared<vision::CutOutOperation>(length, num_patches);

View File

@ -18,6 +18,7 @@
#include "minddata/dataset/kernels/image/decode_op.h"
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -38,7 +39,7 @@ Status DecodeOperation::to_json(nlohmann::json *out_json) {
return Status::OK();
}
Status DecodeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("rgb") != op_params.end(), "Failed to find rgb");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "rgb", kDecodeOperation));
bool rgb = op_params["rgb"];
*operation = std::make_shared<vision::DecodeOperation>(rgb);
return Status::OK();

View File

@ -17,10 +17,13 @@
#include "minddata/dataset/kernels/image/gaussian_blur_op.h"
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
namespace vision {
constexpr int sigma_size = 2;
GaussianBlurOperation::GaussianBlurOperation(const std::vector<int32_t> kernel_size, const std::vector<float> sigma)
: kernel_size_(kernel_size), sigma_(sigma) {}
@ -47,7 +50,7 @@ std::shared_ptr<TensorOp> GaussianBlurOperation::Build() {
float sigma_y = sigma_x;
// User has specified sigma_y.
if (sigma_.size() == 2) {
if (sigma_.size() == sigma_size) {
sigma_y = sigma_[1] <= 0 ? kernel_y * 0.15 + 0.35 : sigma_[1];
}
std::shared_ptr<GaussianBlurOp> tensor_op = std::make_shared<GaussianBlurOp>(kernel_x, kernel_y, sigma_x, sigma_y);
@ -63,8 +66,8 @@ Status GaussianBlurOperation::to_json(nlohmann::json *out_json) {
}
Status GaussianBlurOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("kernel_size") != op_params.end(), "Failed to find kernel_size");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("sigma") != op_params.end(), "Failed to find sigma");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "kernel_size", kGaussianBlurOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "sigma", kGaussianBlurOperation));
std::vector<int32_t> kernel_size = op_params["kernel_size"];
std::vector<float> sigma = op_params["sigma"];
*operation = std::make_shared<vision::GaussianBlurOperation>(kernel_size, sigma);

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -47,7 +48,7 @@ Status MixUpBatchOperation::to_json(nlohmann::json *out_json) {
}
Status MixUpBatchOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("alpha") != op_params.end(), "Failed to find alpha");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "alpha", kMixUpBatchOperation));
float alpha = op_params["alpha"];
*operation = std::make_shared<vision::MixUpBatchOperation>(alpha);
return Status::OK();

View File

@ -18,6 +18,7 @@
#include "minddata/dataset/kernels/image/normalize_op.h"
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -46,8 +47,8 @@ Status NormalizeOperation::to_json(nlohmann::json *out_json) {
}
Status NormalizeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("mean") != op_params.end(), "Fail to find mean");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("std") != op_params.end(), "Fail to find std");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "mean", kNormalizeOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "std", kNormalizeOperation));
std::vector<float> mean = op_params["mean"];
std::vector<float> std = op_params["std"];
*operation = std::make_shared<vision::NormalizeOperation>(mean, std);

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -63,9 +64,9 @@ Status NormalizePadOperation::to_json(nlohmann::json *out_json) {
}
Status NormalizePadOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("mean") != op_params.end(), "Failed to find mean");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("std") != op_params.end(), "Failed to find std");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("dtype") != op_params.end(), "Failed to find dtype");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "mean", kNormalizePadOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "std", kNormalizePadOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "dtype", kNormalizePadOperation));
std::vector<float> mean = op_params["mean"];
std::vector<float> std = op_params["std"];
std::string dtype = op_params["dtype"];

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -105,9 +106,9 @@ Status PadOperation::to_json(nlohmann::json *out_json) {
}
Status PadOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("padding") != op_params.end(), "Failed to find padding");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("fill_value") != op_params.end(), "Failed to find fill_value");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("padding_mode") != op_params.end(), "Failed to find padding_mode");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "padding", kPadOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "fill_value", kPadOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "padding_mode", kPadOperation));
std::vector<int32_t> padding = op_params["padding"];
std::vector<uint8_t> fill_value = op_params["fill_value"];
BorderType padding_mode = static_cast<BorderType>(op_params["padding_mode"]);

View File

@ -20,6 +20,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -54,8 +55,8 @@ Status RandomAdjustSharpnessOperation::to_json(nlohmann::json *out_json) {
Status RandomAdjustSharpnessOperation::from_json(nlohmann::json op_params,
std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("degree") != op_params.end(), "Failed to find degree");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("prob") != op_params.end(), "Failed to find prob");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "degree", kRandomAdjustSharpnessOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "prob", kRandomAdjustSharpnessOperation));
float degree = op_params["degree"];
float prob = op_params["prob"];
*operation = std::make_shared<vision::RandomAdjustSharpnessOperation>(degree, prob);

View File

@ -20,6 +20,7 @@
#include "minddata/dataset/kernels/image/random_affine_op.h"
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -154,12 +155,12 @@ Status RandomAffineOperation::to_json(nlohmann::json *out_json) {
}
Status RandomAffineOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("degrees") != op_params.end(), "Failed to find degrees");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("translate") != op_params.end(), "Failed to find translate");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("scale") != op_params.end(), "Failed to find scale");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("shear") != op_params.end(), "Failed to find shear");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("resample") != op_params.end(), "Failed to find resample");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("fill_value") != op_params.end(), "Failed to find fill_value");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "degrees", kRandomAffineOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "translate", kRandomAffineOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "scale", kRandomAffineOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "shear", kRandomAffineOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "resample", kRandomAffineOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "fill_value", kRandomAffineOperation));
std::vector<float_t> degrees = op_params["degrees"];
std::vector<float_t> translate_range = op_params["translate"];
std::vector<float_t> scale_range = op_params["scale"];

View File

@ -20,6 +20,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -60,9 +61,9 @@ Status RandomAutoContrastOperation::to_json(nlohmann::json *out_json) {
}
Status RandomAutoContrastOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("cutoff") != op_params.end(), "Failed to find cutoff");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("ignore") != op_params.end(), "Failed to find ignore");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("prob") != op_params.end(), "Failed to find prob");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "cutoff", kRandomAutoContrastOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "ignore", kRandomAutoContrastOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "prob", kRandomAutoContrastOperation));
float cutoff = op_params["cutoff"];
std::vector<uint32_t> ignore = op_params["ignore"];
float prob = op_params["prob"];

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -95,10 +96,10 @@ Status RandomColorAdjustOperation::to_json(nlohmann::json *out_json) {
}
Status RandomColorAdjustOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("brightness") != op_params.end(), "Failed to find brightness");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("contrast") != op_params.end(), "Failed to find contrast");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("saturation") != op_params.end(), "Failed to find saturation");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("hue") != op_params.end(), "Failed to find hue");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "brightness", kRandomColorAdjustOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "contrast", kRandomColorAdjustOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "saturation", kRandomColorAdjustOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "hue", kRandomColorAdjustOperation));
std::vector<float> brightness = op_params["brightness"];
std::vector<float> contrast = op_params["contrast"];
std::vector<float> saturation = op_params["saturation"];

View File

@ -23,6 +23,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -62,7 +63,7 @@ Status RandomColorOperation::to_json(nlohmann::json *out_json) {
}
Status RandomColorOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("degrees") != op_params.end(), "Failed to find degrees");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "degrees", kRandomColorOperation));
std::vector<float> degrees = op_params["degrees"];
CHECK_FAIL_RETURN_UNEXPECTED(degrees.size() == 2, "The number of degrees should be 2");
float t_lb = degrees[0];

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -79,11 +80,11 @@ Status RandomCropDecodeResizeOperation::to_json(nlohmann::json *out_json) {
Status RandomCropDecodeResizeOperation::from_json(nlohmann::json op_params,
std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("scale") != op_params.end(), "Failed to find scale");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("ratio") != op_params.end(), "Failed to find ratio");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("interpolation") != op_params.end(), "Failed to find interpolation");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("max_attempts") != op_params.end(), "Failed to find max_attempts");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kRandomCropDecodeResizeOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "scale", kRandomCropDecodeResizeOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "ratio", kRandomCropDecodeResizeOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "interpolation", kRandomCropDecodeResizeOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "max_attempts", kRandomCropDecodeResizeOperation));
std::vector<int32_t> size = op_params["size"];
std::vector<float> scale = op_params["scale"];
std::vector<float> ratio = op_params["ratio"];

View File

@ -16,12 +16,13 @@
#include <algorithm>
#include "minddata/dataset/kernels/ir/vision/random_crop_ir.h"
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.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 {
@ -125,11 +126,11 @@ Status RandomCropOperation::to_json(nlohmann::json *out_json) {
}
Status RandomCropOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("padding") != op_params.end(), "Failed to find padding");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("pad_if_needed") != op_params.end(), "Failed to find pad_if_needed");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("fill_value") != op_params.end(), "Failed to find fill_value");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("padding_mode") != op_params.end(), "Failed to find padding_mode");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kRandomCropOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "padding", kRandomCropOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "pad_if_needed", kRandomCropOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "fill_value", kRandomCropOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "padding_mode", kRandomCropOperation));
std::vector<int32_t> size = op_params["size"];
std::vector<int32_t> padding = op_params["padding"];
bool pad_if_needed = op_params["pad_if_needed"];

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -126,11 +127,11 @@ Status RandomCropWithBBoxOperation::to_json(nlohmann::json *out_json) {
}
Status RandomCropWithBBoxOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("padding") != op_params.end(), "Failed to find padding");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("pad_if_needed") != op_params.end(), "Failed to find pad_if_needed");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("fill_value") != op_params.end(), "Failed to find fill_value");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("padding_mode") != op_params.end(), "Failed to find padding_mode");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kRandomCropWithBBoxOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "padding", kRandomCropWithBBoxOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "pad_if_needed", kRandomCropWithBBoxOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "fill_value", kRandomCropWithBBoxOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "padding_mode", kRandomCropWithBBoxOperation));
std::vector<int32_t> size = op_params["size"];
std::vector<int32_t> padding = op_params["padding"];
bool pad_if_needed = op_params["pad_if_needed"];

View File

@ -21,6 +21,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -49,7 +50,7 @@ Status RandomEqualizeOperation::to_json(nlohmann::json *out_json) {
}
Status RandomEqualizeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("prob") != op_params.end(), "Failed to find prob");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "prob", kRandomEqualizeOperation));
float prob = op_params["prob"];
*operation = std::make_shared<vision::RandomEqualizeOperation>(prob);
return Status::OK();

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -50,7 +51,7 @@ Status RandomHorizontalFlipOperation::to_json(nlohmann::json *out_json) {
}
Status RandomHorizontalFlipOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("prob") != op_params.end(), "Failed to find prob");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "prob", kRandomHorizontalFlipOperation));
float prob = op_params["prob"];
*operation = std::make_shared<vision::RandomHorizontalFlipOperation>(prob);
return Status::OK();

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -53,7 +54,7 @@ Status RandomHorizontalFlipWithBBoxOperation::to_json(nlohmann::json *out_json)
Status RandomHorizontalFlipWithBBoxOperation::from_json(nlohmann::json op_params,
std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("prob") != op_params.end(), "Failed to find prob");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "prob", kRandomHorizontalFlipWithBBoxOperation));
float prob = op_params["prob"];
*operation = std::make_shared<vision::RandomHorizontalFlipWithBBoxOperation>(prob);
return Status::OK();

View File

@ -20,6 +20,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -48,7 +49,7 @@ Status RandomInvertOperation::to_json(nlohmann::json *out_json) {
}
Status RandomInvertOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("prob") != op_params.end(), "Failed to find prob");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "prob", kRandomInvertOperation));
float prob = op_params["prob"];
*operation = std::make_shared<vision::RandomInvertOperation>(prob);
return Status::OK();

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -77,7 +78,7 @@ Status RandomPosterizeOperation::to_json(nlohmann::json *out_json) {
}
Status RandomPosterizeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("bits") != op_params.end(), "Failed to find bits");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "bits", kRandomPosterizeOperation));
std::vector<uint8_t> bit_range = op_params["bits"];
*operation = std::make_shared<vision::RandomPosterizeOperation>(bit_range);
return Status::OK();

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -64,7 +65,7 @@ Status RandomResizeOperation::to_json(nlohmann::json *out_json) {
}
Status RandomResizeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kRandomResizeOperation));
std::vector<int32_t> size = op_params["size"];
*operation = std::make_shared<vision::RandomResizeOperation>(size);
return Status::OK();

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -65,7 +66,7 @@ Status RandomResizeWithBBoxOperation::to_json(nlohmann::json *out_json) {
}
Status RandomResizeWithBBoxOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kRandomResizeWithBBoxOperation));
std::vector<int32_t> size = op_params["size"];
*operation = std::make_shared<vision::RandomResizeWithBBoxOperation>(size);
return Status::OK();

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -96,11 +97,11 @@ Status RandomResizedCropOperation::to_json(nlohmann::json *out_json) {
}
Status RandomResizedCropOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("scale") != op_params.end(), "Failed to find scale");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("ratio") != op_params.end(), "Failed to find ratio");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("interpolation") != op_params.end(), "Failed to find interpolation");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("max_attempts") != op_params.end(), "Failed to find max_attempts");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kRandomResizedCropOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "scale", kRandomResizedCropOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "ratio", kRandomResizedCropOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "interpolation", kRandomResizedCropOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "max_attempts", kRandomResizedCropOperation));
std::vector<int32_t> size = op_params["size"];
std::vector<float> scale = op_params["scale"];
std::vector<float> ratio = op_params["ratio"];

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -92,11 +93,11 @@ Status RandomResizedCropWithBBoxOperation::to_json(nlohmann::json *out_json) {
Status RandomResizedCropWithBBoxOperation::from_json(nlohmann::json op_params,
std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("scale") != op_params.end(), "Failed to find scale");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("ratio") != op_params.end(), "Failed to find ratio");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("interpolation") != op_params.end(), "Failed to find interpolation");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("max_attempts") != op_params.end(), "Failed to find max_attempts");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kRandomResizedCropWithBBoxOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "scale", kRandomResizedCropWithBBoxOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "ratio", kRandomResizedCropWithBBoxOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "interpolation", kRandomResizedCropWithBBoxOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "max_attempts", kRandomResizedCropWithBBoxOperation));
std::vector<int32_t> size = op_params["size"];
std::vector<float> scale = op_params["scale"];
std::vector<float> ratio = op_params["ratio"];

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -123,11 +124,11 @@ Status RandomRotationOperation::to_json(nlohmann::json *out_json) {
}
Status RandomRotationOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("degrees") != op_params.end(), "Failed to find degrees");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("resample") != op_params.end(), "Failed to find resample");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("expand") != op_params.end(), "Failed to find expand");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("center") != op_params.end(), "Failed to find center");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("fill_value") != op_params.end(), "Failed to find fill_value");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "degrees", kRandomRotationOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "resample", kRandomRotationOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "expand", kRandomRotationOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "center", kRandomRotationOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "fill_value", kRandomRotationOperation));
std::vector<float> degrees = op_params["degrees"];
InterpolationMode resample = static_cast<InterpolationMode>(op_params["resample"]);
bool expand = op_params["expand"];

View File

@ -23,6 +23,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -100,14 +101,14 @@ Status RandomSelectSubpolicyOperation::to_json(nlohmann::json *out_json) {
Status RandomSelectSubpolicyOperation::from_json(nlohmann::json op_params,
std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("policy") != op_params.end(), "Failed to find policy");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "policy", kRandomSelectSubpolicyOperation));
nlohmann::json policy_json = op_params["policy"];
std::vector<std::vector<std::pair<std::shared_ptr<TensorOperation>, double>>> policy;
std::vector<std::pair<std::shared_ptr<TensorOperation>, double>> policy_items;
for (nlohmann::json item : policy_json) {
for (nlohmann::json item_pair : item) {
CHECK_FAIL_RETURN_UNEXPECTED(item_pair.find("prob") != item_pair.end(), "Failed to find prob");
CHECK_FAIL_RETURN_UNEXPECTED(item_pair.find("tensor_op") != item_pair.end(), "Failed to find tensor_op");
RETURN_IF_NOT_OK(ValidateParamInJson(item_pair, "prob", kRandomSelectSubpolicyOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(item_pair, "tensor_op", kRandomSelectSubpolicyOperation));
std::vector<std::shared_ptr<TensorOperation>> operations;
std::pair<std::shared_ptr<TensorOperation>, double> policy_pair;
std::shared_ptr<TensorOperation> operation;

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -66,7 +67,7 @@ Status RandomSharpnessOperation::to_json(nlohmann::json *out_json) {
}
Status RandomSharpnessOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("degrees") != op_params.end(), "Failed to find degrees");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "degrees", kRandomSharpnessOperation));
std::vector<float> degrees = op_params["degrees"];
*operation = std::make_shared<vision::RandomSharpnessOperation>(degrees);
return Status::OK();

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -71,7 +72,7 @@ Status RandomSolarizeOperation::to_json(nlohmann::json *out_json) {
}
Status RandomSolarizeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("threshold") != op_params.end(), "Failed to find threshold");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "threshold", kRandomSolarizeOperation));
std::vector<uint8_t> threshold = op_params["threshold"];
*operation = std::make_shared<vision::RandomSolarizeOperation>(threshold);
return Status::OK();

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -51,7 +52,7 @@ Status RandomVerticalFlipOperation::to_json(nlohmann::json *out_json) {
}
Status RandomVerticalFlipOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("prob") != op_params.end(), "Failed to find prob");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "prob", kRandomVerticalFlipOperation));
float prob = op_params["prob"];
*operation = std::make_shared<vision::RandomVerticalFlipOperation>(prob);
return Status::OK();

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -54,7 +55,7 @@ Status RandomVerticalFlipWithBBoxOperation::to_json(nlohmann::json *out_json) {
Status RandomVerticalFlipWithBBoxOperation::from_json(nlohmann::json op_params,
std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("prob") != op_params.end(), "Failed to find prob");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "prob", kRandomVerticalFlipWithBBoxOperation));
float prob = op_params["prob"];
*operation = std::make_shared<vision::RandomVerticalFlipWithBBoxOperation>(prob);
return Status::OK();

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -56,8 +57,8 @@ Status RescaleOperation::to_json(nlohmann::json *out_json) {
}
Status RescaleOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("rescale") != op_params.end(), "Failed to find rescale");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("shift") != op_params.end(), "Failed to find shift");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "rescale", kRescaleOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "shift", kRescaleOperation));
float rescale = op_params["rescale"];
float shift = op_params["shift"];
*operation = std::make_shared<vision::RescaleOperation>(rescale, shift);

View File

@ -18,6 +18,7 @@
#include "minddata/dataset/kernels/image/resize_op.h"
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -69,8 +70,8 @@ Status ResizeOperation::to_json(nlohmann::json *out_json) {
}
Status ResizeOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("interpolation") != op_params.end(), "Failed to find interpolation");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kResizeOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "interpolation", kResizeOperation));
std::vector<int32_t> size = op_params["size"];
InterpolationMode interpolation = static_cast<InterpolationMode>(op_params["interpolation"]);
*operation = std::make_shared<vision::ResizeOperation>(size, interpolation);

View File

@ -18,6 +18,7 @@
#include "minddata/dataset/kernels/image/resize_preserve_ar_op.h"
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -53,9 +54,9 @@ Status ResizePreserveAROperation::to_json(nlohmann::json *out_json) {
}
Status ResizePreserveAROperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("height") != op_params.end(), "Failed to find height");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("width") != op_params.end(), "Failed to find width");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("img_orientation") != op_params.end(), "Failed to find img_orientation");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "height", kResizePreserveAROperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "width", kResizePreserveAROperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "img_orientation", kResizePreserveAROperation));
int32_t height = op_params["height"];
int32_t width = op_params["width"];
int32_t img_orientation = op_params["img_orientation"];

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -72,8 +73,8 @@ Status ResizeWithBBoxOperation::to_json(nlohmann::json *out_json) {
}
Status ResizeWithBBoxOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("interpolation") != op_params.end(), "Failed to find interpolation");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kResizeWithBBoxOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "interpolation", kResizeWithBBoxOperation));
std::vector<int32_t> size = op_params["size"];
InterpolationMode interpolation = static_cast<InterpolationMode>(op_params["interpolation"]);
*operation = std::make_shared<vision::ResizeWithBBoxOperation>(size, interpolation);

View File

@ -103,11 +103,11 @@ Status RotateOperation::to_json(nlohmann::json *out_json) {
Status RotateOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
#ifndef ENABLE_ANDROID
RETURN_IF_NOT_OK(ValidateParamInJson(op_params.find("degree") != op_params.end(), "degree"));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params.find("resample") != op_params.end(), "resample"));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params.find("expand") != op_params.end(), "expand"));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params.find("center") != op_params.end(), "center"));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params.find("fill_value") != op_params.end(), "fill_value"));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "degree", kRotateOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "resample", kRotateOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "expand", kRotateOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "center", kRotateOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "fill_value", kRotateOperation));
float degrees = op_params["degree"];
InterpolationMode resample = static_cast<InterpolationMode>(op_params["resample"]);
bool expand = op_params["expand"];
@ -115,7 +115,7 @@ Status RotateOperation::from_json(nlohmann::json op_params, std::shared_ptr<Tens
std::vector<uint8_t> fill_value = op_params["fill_value"];
*operation = std::make_shared<vision::RotateOperation>(degrees, resample, expand, center, fill_value);
#else
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("angle_id") != op_params.end(), "Failed to find angle_id");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "angle_id", kRotateOperation));
uint64_t angle_id = op_params["angle_id"];
std::shared_ptr<RotateOperation> rotate_operation =
std::make_shared<vision::RotateOperation>(FixRotationAngle::k0Degree);

View File

@ -18,6 +18,7 @@
#include "minddata/dataset/kernels/ir/vision/slice_patches_ir.h"
#include "minddata/dataset/kernels/image/slice_patches_op.h"
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -57,10 +58,10 @@ Status SlicePatchesOperation::to_json(nlohmann::json *out_json) {
}
Status SlicePatchesOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("num_height") != op_params.end(), "Failed to find num_height");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("num_width") != op_params.end(), "Failed to find num_width");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("slice_mode") != op_params.end(), "Failed to find slice_mode");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("fill_value") != op_params.end(), "Failed to find fill_value");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "num_height", kSlicePatchesOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "num_width", kSlicePatchesOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "slice_mode", kSlicePatchesOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "fill_value", kSlicePatchesOperation));
int32_t num_height = op_params["num_height"];
int32_t num_width = op_params["num_width"];
SliceMode slice_mode = static_cast<SliceMode>(op_params["slice_mode"]);

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -94,10 +95,10 @@ Status SoftDvppDecodeRandomCropResizeJpegOperation::to_json(nlohmann::json *out_
Status SoftDvppDecodeRandomCropResizeJpegOperation::from_json(nlohmann::json op_params,
std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("scale") != op_params.end(), "Failed to find scale");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("ratio") != op_params.end(), "Failed to find ratio");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("max_attempts") != op_params.end(), "Failed to find max_attempts");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kSoftDvppDecodeRandomCropResizeJpegOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "scale", kSoftDvppDecodeRandomCropResizeJpegOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "ratio", kSoftDvppDecodeRandomCropResizeJpegOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "max_attempts", kSoftDvppDecodeRandomCropResizeJpegOperation));
std::vector<int32_t> size = op_params["size"];
std::vector<float> scale = op_params["scale"];
std::vector<float> ratio = op_params["ratio"];

View File

@ -22,6 +22,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -73,7 +74,7 @@ Status SoftDvppDecodeResizeJpegOperation::to_json(nlohmann::json *out_json) {
Status SoftDvppDecodeResizeJpegOperation::from_json(nlohmann::json op_params,
std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("size") != op_params.end(), "Failed to find size");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "size", kSoftDvppDecodeResizeJpegOperation));
std::vector<int32_t> size = op_params["size"];
*operation = std::make_shared<vision::SoftDvppDecodeResizeJpegOperation>(size);
return Status::OK();

View File

@ -23,6 +23,7 @@
#endif
#include "minddata/dataset/kernels/ir/validators.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -77,8 +78,8 @@ Status UniformAugOperation::to_json(nlohmann::json *out_json) {
}
Status UniformAugOperation::from_json(nlohmann::json op_params, std::shared_ptr<TensorOperation> *operation) {
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("transforms") != op_params.end(), "Failed to find transforms");
CHECK_FAIL_RETURN_UNEXPECTED(op_params.find("num_ops") != op_params.end(), "Failed to find num_ops");
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "transforms", kUniformAugOperation));
RETURN_IF_NOT_OK(ValidateParamInJson(op_params, "num_ops", kUniformAugOperation));
std::vector<std::shared_ptr<TensorOperation>> transforms = {};
RETURN_IF_NOT_OK(Serdes::ConstructTensorOps(op_params["transforms"], &transforms));
int32_t num_ops = op_params["num_ops"];

View File

@ -22,6 +22,7 @@
#include "minddata/dataset/kernels/tensor_op.h"
#include "minddata/dataset/kernels/ir/data/transforms_ir.h"
#include "minddata/dataset/util/status.h"
#include "minddata/dataset/util/validators.h"
namespace mindspore {
namespace dataset {
@ -134,8 +135,8 @@ Status PyFuncOp::to_json(nlohmann::json *out_json) {
Status PyFuncOp::from_json(nlohmann::json json_obj, std::vector<std::shared_ptr<TensorOperation>> *result) {
std::vector<std::shared_ptr<TensorOperation>> output;
CHECK_FAIL_RETURN_UNEXPECTED(json_obj.find("tensor_op_name") != json_obj.end(), "Failed to find tensor_op_name");
CHECK_FAIL_RETURN_UNEXPECTED(json_obj.find("tensor_op_params") != json_obj.end(), "Failed to find tensor_op_params");
RETURN_IF_NOT_OK(ValidateParamInJson(json_obj, "tensor_op_name", kPyFuncOp));
RETURN_IF_NOT_OK(ValidateParamInJson(json_obj, "tensor_op_params", kPyFuncOp));
std::string op_name = json_obj["tensor_op_name"];
nlohmann::json op_params = json_obj["tensor_op_params"];
std::string python_module = json_obj["python_module"];

View File

@ -17,6 +17,7 @@
#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_VALIDATORS_H_
#define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_VALIDATORS_H_
#include <nlohmann/json.hpp>
#include <string>
#include "minddata/dataset/util/status.h"
@ -24,9 +25,11 @@
namespace mindspore {
namespace dataset {
// validator Parameter in json file
inline Status ValidateParamInJson(const bool cond, const std::string &param_name) {
if (!cond) {
std::string err_msg = "Failed to find param '" + param_name + "' in json file for deserialize.";
inline Status ValidateParamInJson(nlohmann::json op_params, const std::string &param_name,
const std::string &operator_name) {
if (op_params.find(param_name) == op_params.end()) {
std::string err_msg = "Failed to find parameter '" + param_name + "' of '" + operator_name +
"' operator in input json file or input dict, check input parameter of API 'deserialize.";
RETURN_STATUS_UNEXPECTED(err_msg);
}
return Status::OK();