From 07c8b361f57bb61846bafbcaa0a3723991b73f50 Mon Sep 17 00:00:00 2001 From: ms_yan Date: Thu, 18 Nov 2021 21:54:05 +0800 Subject: [PATCH] improve error msg --- .../dataset/kernels/ir/data/transforms_ir.cc | 5 +++-- .../dataset/kernels/ir/vision/adjust_gamma_ir.cc | 5 +++-- .../dataset/kernels/ir/vision/affine_ir.cc | 13 +++++++------ .../dataset/kernels/ir/vision/ascend_vision_ir.cc | 15 ++++++++------- .../dataset/kernels/ir/vision/auto_augment_ir.cc | 7 ++++--- .../dataset/kernels/ir/vision/auto_contrast_ir.cc | 5 +++-- .../kernels/ir/vision/bounding_box_augment_ir.cc | 5 +++-- .../dataset/kernels/ir/vision/center_crop_ir.cc | 3 ++- .../dataset/kernels/ir/vision/convert_color_ir.cc | 3 ++- .../minddata/dataset/kernels/ir/vision/crop_ir.cc | 5 +++-- .../dataset/kernels/ir/vision/cutmix_batch_ir.cc | 8 ++++---- .../dataset/kernels/ir/vision/cutout_ir.cc | 5 +++-- .../dataset/kernels/ir/vision/decode_ir.cc | 3 ++- .../dataset/kernels/ir/vision/gaussian_blur_ir.cc | 9 ++++++--- .../dataset/kernels/ir/vision/mixup_batch_ir.cc | 3 ++- .../dataset/kernels/ir/vision/normalize_ir.cc | 5 +++-- .../dataset/kernels/ir/vision/normalize_pad_ir.cc | 7 ++++--- .../minddata/dataset/kernels/ir/vision/pad_ir.cc | 7 ++++--- .../ir/vision/random_adjust_sharpness_ir.cc | 5 +++-- .../dataset/kernels/ir/vision/random_affine_ir.cc | 13 +++++++------ .../kernels/ir/vision/random_auto_contrast_ir.cc | 7 ++++--- .../kernels/ir/vision/random_color_adjust_ir.cc | 9 +++++---- .../dataset/kernels/ir/vision/random_color_ir.cc | 3 ++- .../ir/vision/random_crop_decode_resize_ir.cc | 11 ++++++----- .../dataset/kernels/ir/vision/random_crop_ir.cc | 13 +++++++------ .../kernels/ir/vision/random_crop_with_bbox_ir.cc | 11 ++++++----- .../kernels/ir/vision/random_equalize_ir.cc | 3 ++- .../ir/vision/random_horizontal_flip_ir.cc | 3 ++- .../vision/random_horizontal_flip_with_bbox_ir.cc | 3 ++- .../dataset/kernels/ir/vision/random_invert_ir.cc | 3 ++- .../kernels/ir/vision/random_posterize_ir.cc | 3 ++- .../dataset/kernels/ir/vision/random_resize_ir.cc | 3 ++- .../ir/vision/random_resize_with_bbox_ir.cc | 3 ++- .../kernels/ir/vision/random_resized_crop_ir.cc | 11 ++++++----- .../ir/vision/random_resized_crop_with_bbox_ir.cc | 11 ++++++----- .../kernels/ir/vision/random_rotation_ir.cc | 11 ++++++----- .../ir/vision/random_select_subpolicy_ir.cc | 7 ++++--- .../kernels/ir/vision/random_sharpness_ir.cc | 3 ++- .../kernels/ir/vision/random_solarize_ir.cc | 3 ++- .../kernels/ir/vision/random_vertical_flip_ir.cc | 3 ++- .../vision/random_vertical_flip_with_bbox_ir.cc | 3 ++- .../dataset/kernels/ir/vision/rescale_ir.cc | 5 +++-- .../dataset/kernels/ir/vision/resize_ir.cc | 5 +++-- .../kernels/ir/vision/resize_preserve_ar_ir.cc | 7 ++++--- .../kernels/ir/vision/resize_with_bbox_ir.cc | 5 +++-- .../dataset/kernels/ir/vision/rotate_ir.cc | 12 ++++++------ .../dataset/kernels/ir/vision/slice_patches_ir.cc | 9 +++++---- .../softdvpp_decode_random_crop_resize_jpeg_ir.cc | 9 +++++---- .../ir/vision/softdvpp_decode_resize_jpeg_ir.cc | 3 ++- .../dataset/kernels/ir/vision/uniform_aug_ir.cc | 5 +++-- .../ccsrc/minddata/dataset/kernels/py_func_op.cc | 5 +++-- .../ccsrc/minddata/dataset/util/validators.h | 9 ++++++--- 52 files changed, 193 insertions(+), 139 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/data/transforms_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/data/transforms_ir.cc index 4b216c192ae..7cb6778e50a 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/data/transforms_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/data/transforms_ir.cc @@ -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 *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(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 *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(data_type); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/adjust_gamma_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/adjust_gamma_ir.cc index 5ac850b36db..b45c16ac3fb 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/adjust_gamma_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/adjust_gamma_ir.cc @@ -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 *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(gamma, gain); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.cc index adadc6cab88..b3e0ccd7ba6 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/affine_ir.cc @@ -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 *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 translation = op_params["translate"]; float scale = op_params["scale"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/ascend_vision_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/ascend_vision_ir.cc index dc8110ba3ce..9382912244f 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/ascend_vision_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/ascend_vision_ir.cc @@ -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 *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 resize = op_params["size"]; *operation = std::make_shared(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 *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 resize = op_params["size"]; *operation = std::make_shared(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 *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 crop = op_params["crop_size"]; std::vector resize = op_params["resize_size"]; *operation = std::make_shared(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 *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 mean = op_params["mean"]; std::vector std = op_params["std"]; *operation = std::make_shared(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 *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 resize = op_params["size"]; *operation = std::make_shared(resize); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_augment_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_augment_ir.cc index 64232e14da6..9e80492d976 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_augment_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_augment_ir.cc @@ -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 *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 fill_value = op_params["fill_value"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_contrast_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_contrast_ir.cc index 6f9cd7c258c..05855340369 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_contrast_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/auto_contrast_ir.cc @@ -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 *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 ignore = op_params["ignore"]; *operation = std::make_shared(cutoff, ignore); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.cc index dc4e4af653f..7ce30f609c2 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/bounding_box_augment_ir.cc @@ -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 *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> transforms; std::vector json_operations = {}; json_operations.push_back(op_params["transform"]); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/center_crop_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/center_crop_ir.cc index a85ce239a3b..2b093280aa4 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/center_crop_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/center_crop_ir.cc @@ -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 *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 size = op_params["size"]; *operation = std::make_shared(size); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/convert_color_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/convert_color_ir.cc index 37b479bd69b..b623d0b9801 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/convert_color_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/convert_color_ir.cc @@ -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 *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(op_params["convert_mode"]); *operation = std::make_shared(convert_mode); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.cc index 942d33a33b2..a8cacee817f 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/crop_ir.cc @@ -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 *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 coordinates = op_params["coordinates"]; std::vector size = op_params["size"]; *operation = std::make_shared(coordinates, size); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutmix_batch_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutmix_batch_ir.cc index 921a2abce45..560b94e3bf2 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutmix_batch_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutmix_batch_ir.cc @@ -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 *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(op_params["image_batch_format"]); float alpha = op_params["alpha"]; float prob = op_params["prob"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutout_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutout_ir.cc index 50ba03f1d88..942b16790db 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutout_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/cutout_ir.cc @@ -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 *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(length, num_patches); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/decode_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/decode_ir.cc index a920ab42b78..ea84b8625c6 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/decode_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/decode_ir.cc @@ -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 *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(rgb); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/gaussian_blur_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/gaussian_blur_ir.cc index cb58f42b80e..6156220660f 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/gaussian_blur_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/gaussian_blur_ir.cc @@ -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 kernel_size, const std::vector sigma) : kernel_size_(kernel_size), sigma_(sigma) {} @@ -47,7 +50,7 @@ std::shared_ptr 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 tensor_op = std::make_shared(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 *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 kernel_size = op_params["kernel_size"]; std::vector sigma = op_params["sigma"]; *operation = std::make_shared(kernel_size, sigma); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/mixup_batch_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/mixup_batch_ir.cc index fb23c57d20c..6d07fff9eb4 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/mixup_batch_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/mixup_batch_ir.cc @@ -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 *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(alpha); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.cc index 21dc3308d4a..877dbe61658 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_ir.cc @@ -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 *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 mean = op_params["mean"]; std::vector std = op_params["std"]; *operation = std::make_shared(mean, std); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_pad_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_pad_ir.cc index a3fcac2c89e..9fc44f2c835 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_pad_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/normalize_pad_ir.cc @@ -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 *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 mean = op_params["mean"]; std::vector std = op_params["std"]; std::string dtype = op_params["dtype"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.cc index 3bb3a864813..05b418aca01 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/pad_ir.cc @@ -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 *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 padding = op_params["padding"]; std::vector fill_value = op_params["fill_value"]; BorderType padding_mode = static_cast(op_params["padding_mode"]); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_adjust_sharpness_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_adjust_sharpness_ir.cc index c4aab69f155..85ba06aee44 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_adjust_sharpness_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_adjust_sharpness_ir.cc @@ -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 *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(degree, prob); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_affine_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_affine_ir.cc index 26646c3f74a..c52c43e0478 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_affine_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_affine_ir.cc @@ -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 *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 degrees = op_params["degrees"]; std::vector translate_range = op_params["translate"]; std::vector scale_range = op_params["scale"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_auto_contrast_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_auto_contrast_ir.cc index b45e1ab24d4..efc84d36fb1 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_auto_contrast_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_auto_contrast_ir.cc @@ -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 *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 ignore = op_params["ignore"]; float prob = op_params["prob"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_adjust_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_adjust_ir.cc index f8e38289b92..69a942d5551 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_adjust_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_adjust_ir.cc @@ -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 *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 brightness = op_params["brightness"]; std::vector contrast = op_params["contrast"]; std::vector saturation = op_params["saturation"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_ir.cc index dd462ef52e4..bad99e3b22c 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_color_ir.cc @@ -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 *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 degrees = op_params["degrees"]; CHECK_FAIL_RETURN_UNEXPECTED(degrees.size() == 2, "The number of degrees should be 2"); float t_lb = degrees[0]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.cc index e9d2337662f..10df7a05335 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_decode_resize_ir.cc @@ -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 *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 size = op_params["size"]; std::vector scale = op_params["scale"]; std::vector ratio = op_params["ratio"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_ir.cc index 235f8f6182c..08868ce2565 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_ir.cc @@ -16,12 +16,13 @@ #include #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 *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 size = op_params["size"]; std::vector padding = op_params["padding"]; bool pad_if_needed = op_params["pad_if_needed"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_with_bbox_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_with_bbox_ir.cc index b7f80abf922..3e00350699a 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_with_bbox_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_crop_with_bbox_ir.cc @@ -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 *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 size = op_params["size"]; std::vector padding = op_params["padding"]; bool pad_if_needed = op_params["pad_if_needed"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_equalize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_equalize_ir.cc index b5b5756a5a6..ab27965d14a 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_equalize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_equalize_ir.cc @@ -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 *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(prob); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.cc index 5654905da25..0f2d3da27f8 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_ir.cc @@ -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 *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(prob); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.cc index 703f737a218..f4a71a7473b 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_horizontal_flip_with_bbox_ir.cc @@ -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 *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(prob); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_invert_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_invert_ir.cc index d07c8cbb501..1ccebce9ef7 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_invert_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_invert_ir.cc @@ -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 *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(prob); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_posterize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_posterize_ir.cc index 36c0ce99099..8ffb656245e 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_posterize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_posterize_ir.cc @@ -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 *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 bit_range = op_params["bits"]; *operation = std::make_shared(bit_range); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_ir.cc index c4542b534ce..718c6c7f229 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_ir.cc @@ -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 *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 size = op_params["size"]; *operation = std::make_shared(size); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.cc index 46e6b568335..f057b400da0 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resize_with_bbox_ir.cc @@ -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 *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 size = op_params["size"]; *operation = std::make_shared(size); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_ir.cc index addd7ed662f..9961dc2f94f 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_ir.cc @@ -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 *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 size = op_params["size"]; std::vector scale = op_params["scale"]; std::vector ratio = op_params["ratio"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_with_bbox_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_with_bbox_ir.cc index da09f9a353f..1216a54a30e 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_with_bbox_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_resized_crop_with_bbox_ir.cc @@ -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 *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 size = op_params["size"]; std::vector scale = op_params["scale"]; std::vector ratio = op_params["ratio"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_rotation_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_rotation_ir.cc index 07db871ea80..03784734224 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_rotation_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_rotation_ir.cc @@ -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 *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 degrees = op_params["degrees"]; InterpolationMode resample = static_cast(op_params["resample"]); bool expand = op_params["expand"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_select_subpolicy_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_select_subpolicy_ir.cc index fa694b1daa1..62c32dd012f 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_select_subpolicy_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_select_subpolicy_ir.cc @@ -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 *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, double>>> policy; std::vector, 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> operations; std::pair, double> policy_pair; std::shared_ptr operation; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_sharpness_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_sharpness_ir.cc index 08f5ed89ce8..81062fc2a2b 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_sharpness_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_sharpness_ir.cc @@ -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 *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 degrees = op_params["degrees"]; *operation = std::make_shared(degrees); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_solarize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_solarize_ir.cc index 61407ed7a4a..82f378f358d 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_solarize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_solarize_ir.cc @@ -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 *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 threshold = op_params["threshold"]; *operation = std::make_shared(threshold); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_ir.cc index c0442ffb217..d46a6451055 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_ir.cc @@ -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 *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(prob); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_with_bbox_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_with_bbox_ir.cc index 5c94515b518..4ed2cc24661 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_with_bbox_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/random_vertical_flip_with_bbox_ir.cc @@ -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 *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(prob); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.cc index 6c7d9a6b77c..7e401bf13e7 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rescale_ir.cc @@ -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 *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(rescale, shift); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.cc index c4b6c4b025a..b4e0a73f5e7 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_ir.cc @@ -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 *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 size = op_params["size"]; InterpolationMode interpolation = static_cast(op_params["interpolation"]); *operation = std::make_shared(size, interpolation); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_preserve_ar_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_preserve_ar_ir.cc index 907606871bd..b9aa96ca839 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_preserve_ar_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_preserve_ar_ir.cc @@ -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 *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"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.cc index 3a695e3609e..df66f60a35b 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/resize_with_bbox_ir.cc @@ -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 *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 size = op_params["size"]; InterpolationMode interpolation = static_cast(op_params["interpolation"]); *operation = std::make_shared(size, interpolation); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.cc index 8fa40d8c855..9dc882d47ac 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/rotate_ir.cc @@ -103,11 +103,11 @@ Status RotateOperation::to_json(nlohmann::json *out_json) { Status RotateOperation::from_json(nlohmann::json op_params, std::shared_ptr *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(op_params["resample"]); bool expand = op_params["expand"]; @@ -115,7 +115,7 @@ Status RotateOperation::from_json(nlohmann::json op_params, std::shared_ptr fill_value = op_params["fill_value"]; *operation = std::make_shared(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 rotate_operation = std::make_shared(FixRotationAngle::k0Degree); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/slice_patches_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/slice_patches_ir.cc index 11220781f19..3bb6b744e25 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/slice_patches_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/slice_patches_ir.cc @@ -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 *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(op_params["slice_mode"]); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.cc index 5e92c98645b..9b33001b520 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_random_crop_resize_jpeg_ir.cc @@ -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 *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 size = op_params["size"]; std::vector scale = op_params["scale"]; std::vector ratio = op_params["ratio"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.cc index 0e009e1eb87..381dcb7ab92 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/softdvpp_decode_resize_jpeg_ir.cc @@ -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 *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 size = op_params["size"]; *operation = std::make_shared(size); return Status::OK(); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/uniform_aug_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/uniform_aug_ir.cc index 1ccec8f19a9..dea762afc29 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/uniform_aug_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/uniform_aug_ir.cc @@ -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 *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> transforms = {}; RETURN_IF_NOT_OK(Serdes::ConstructTensorOps(op_params["transforms"], &transforms)); int32_t num_ops = op_params["num_ops"]; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/py_func_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/py_func_op.cc index 089948d6ca7..e18dd3ca03f 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/py_func_op.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/py_func_op.cc @@ -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> *result) { std::vector> 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"]; diff --git a/mindspore/ccsrc/minddata/dataset/util/validators.h b/mindspore/ccsrc/minddata/dataset/util/validators.h index ff9e81d0e97..fac8baaf912 100644 --- a/mindspore/ccsrc/minddata/dataset/util/validators.h +++ b/mindspore/ccsrc/minddata/dataset/util/validators.h @@ -17,6 +17,7 @@ #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_VALIDATORS_H_ #define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_VALIDATORS_H_ +#include #include #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 ¶m_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 ¶m_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();