forked from mindspore-Ecosystem/mindspore
[MD] add common validation functions for transform
This commit is contained in:
parent
3708624a25
commit
1893ae8662
|
@ -31,29 +31,52 @@ namespace mindspore {
|
||||||
namespace dataset {
|
namespace dataset {
|
||||||
|
|
||||||
/* ####################################### Validator Functions ############################################ */
|
/* ####################################### Validator Functions ############################################ */
|
||||||
Status ValidateVectorFillvalue(const std::string &transform_name, const std::vector<uint8_t> &fill_value) {
|
Status ValidateProbability(const std::string &op_name, const float probability) {
|
||||||
|
if (probability < 0.0 || probability > 1.0) {
|
||||||
|
std::string err_msg = op_name + ": probability must be between 0.0 and 1.0, got: " + std::to_string(probability);
|
||||||
|
MS_LOG(ERROR) << err_msg;
|
||||||
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
Status ValidateIntScalarPositive(const std::string &op_name, const std::string &scalar_name, int32_t scalar) {
|
||||||
|
RETURN_IF_NOT_OK(ValidateScalar(op_name, scalar_name, scalar, {0}, true));
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
Status ValidateFloatScalarPositive(const std::string &op_name, const std::string &scalar_name, float scalar) {
|
||||||
|
RETURN_IF_NOT_OK(ValidateScalar(op_name, scalar_name, scalar, {0}, true));
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
Status ValidateVectorFillvalue(const std::string &op_name, const std::vector<uint8_t> &fill_value) {
|
||||||
if (fill_value.empty() || (fill_value.size() != 1 && fill_value.size() != 3)) {
|
if (fill_value.empty() || (fill_value.size() != 1 && fill_value.size() != 3)) {
|
||||||
std::string err_msg =
|
std::string err_msg =
|
||||||
transform_name + ": fill_value vector has incorrect size: " + std::to_string(fill_value.size());
|
op_name + ": fill_value expecting size 1 or 3, got fill_value.size(): " + std::to_string(fill_value.size());
|
||||||
MS_LOG(ERROR) << err_msg;
|
MS_LOG(ERROR) << err_msg;
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
}
|
}
|
||||||
for (uint8_t single_fill_value : fill_value) {
|
// Note that fill_value need to be in range [0, 255],
|
||||||
if (single_fill_value > 255) {
|
// but we omit the check since its type is uint8_t
|
||||||
std::string err_msg =
|
|
||||||
transform_name + ": fill_value has to be between 0 and 255, got:" + std::to_string(single_fill_value);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status ValidateProbability(const std::string &transform_name, const float &probability) {
|
Status ValidateVectorColorAttribute(const std::string &op_name, const std::string &attr_name,
|
||||||
if (probability < 0.0 || probability > 1.0) {
|
const std::vector<float> &attr, const std::vector<float> &range) {
|
||||||
std::string err_msg =
|
if (attr.empty() || attr.size() > 2) {
|
||||||
transform_name + ": probability must be between 0.0 and 1.0, got: " + std::to_string(probability);
|
std::string err_msg = op_name + ":" + attr_name + " expecting size 1 or 2, but got: " + std::to_string(attr.size());
|
||||||
|
MS_LOG(ERROR) << err_msg;
|
||||||
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
|
}
|
||||||
|
for (auto &attr_val : attr) {
|
||||||
|
RETURN_IF_NOT_OK(ValidateScalar(op_name, attr_name, attr_val, range, false, false));
|
||||||
|
}
|
||||||
|
if (attr.size() == 2 && (attr[0] > attr[1])) {
|
||||||
|
std::string err_msg = op_name + ":" + attr_name +
|
||||||
|
" lower bound must be less or equal to upper bound, got lb: " + std::to_string(attr[0]) +
|
||||||
|
", ub: " + std::to_string(attr[1]);
|
||||||
MS_LOG(ERROR) << err_msg;
|
MS_LOG(ERROR) << err_msg;
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
}
|
}
|
||||||
|
@ -61,55 +84,116 @@ Status ValidateProbability(const std::string &transform_name, const float &proba
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status ValidateVectorPadding(const std::string &transform_name, const std::vector<int32_t> &padding) {
|
Status ValidateVectorMeanStd(const std::string &op_name, const std::vector<float> &mean,
|
||||||
|
const std::vector<float> &std) {
|
||||||
|
if (mean.size() != 3) {
|
||||||
|
std::string err_msg = op_name + ": mean expecting size 3, got size: " + std::to_string(mean.size());
|
||||||
|
MS_LOG(ERROR) << err_msg;
|
||||||
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
|
}
|
||||||
|
if (std.size() != 3) {
|
||||||
|
std::string err_msg = op_name + ": std expecting size 3, got size: " + std::to_string(std.size());
|
||||||
|
MS_LOG(ERROR) << err_msg;
|
||||||
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
|
}
|
||||||
|
// check std/mean value
|
||||||
|
for (int32_t i = 0; i < std.size(); ++i) {
|
||||||
|
RETURN_IF_NOT_OK(ValidateScalar(op_name, "mean", mean[i], {0.0, 255.0}, false, false));
|
||||||
|
RETURN_IF_NOT_OK(ValidateScalar(op_name, "std", std[i], {0.0, 255.0}, true, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
Status ValidateVectorPadding(const std::string &op_name, const std::vector<int32_t> &padding) {
|
||||||
if (padding.empty() || padding.size() == 3 || padding.size() > 4) {
|
if (padding.empty() || padding.size() == 3 || padding.size() > 4) {
|
||||||
std::string err_msg = transform_name + ": padding vector has incorrect size: " + std::to_string(padding.size());
|
std::string err_msg = op_name + ": padding expecting size 1, 2 or 4, got size: " + std::to_string(padding.size());
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
for (int32_t i = 0; i < padding.size(); ++i) {
|
|
||||||
if (padding[i] < 0) {
|
|
||||||
std::string err_msg =
|
|
||||||
transform_name +
|
|
||||||
": invalid padding, padding value must be greater than or equal to 0, got: " + std::to_string(padding[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (padding[i] == INT_MAX) {
|
|
||||||
std::string err_msg =
|
|
||||||
transform_name + ": invalid padding, padding value too large, got: " + std::to_string(padding[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
MS_LOG(ERROR) << err_msg;
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
}
|
}
|
||||||
|
for (const auto &pad_val : padding) {
|
||||||
|
RETURN_IF_NOT_OK(ValidateScalar(op_name, "padding", pad_val, {0, INT_MAX}, false, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status ValidateVectorPositive(const std::string &transform_name, const std::vector<int32_t> &size) {
|
Status ValidateVectorPositive(const std::string &op_name, const std::string &vec_name,
|
||||||
for (int32_t i = 0; i < size.size(); ++i) {
|
const std::vector<int32_t> &vec) {
|
||||||
if (size[i] <= 0) {
|
for (const auto &vec_val : vec) {
|
||||||
std::string err_msg =
|
RETURN_IF_NOT_OK(ValidateScalar(op_name, vec_name, vec_val, {0}, true));
|
||||||
transform_name + ": Non-positive size value: " + std::to_string(size[i]) + " at element: " + std::to_string(i);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status ValidateVectorTransforms(const std::string &transform_name,
|
Status ValidateVectorNonNegative(const std::string &op_name, const std::string &vec_name,
|
||||||
|
const std::vector<int32_t> &vec) {
|
||||||
|
for (const auto &vec_val : vec) {
|
||||||
|
RETURN_IF_NOT_OK(ValidateScalar(op_name, vec_name, vec_val, {0}, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
Status ValidateVectorSize(const std::string &op_name, const std::vector<int32_t> &size) {
|
||||||
|
if (size.empty() || size.size() > 2) {
|
||||||
|
std::string err_msg = op_name + ": size expecting size 2, got size.size(): " + std::to_string(size.size());
|
||||||
|
MS_LOG(ERROR) << err_msg;
|
||||||
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
|
}
|
||||||
|
for (const auto &size_val : size) {
|
||||||
|
RETURN_IF_NOT_OK(ValidateScalar(op_name, "size", size_val, {0, INT_MAX}, true, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
Status ValidateVectorScale(const std::string &op_name, const std::vector<float> &scale) {
|
||||||
|
if (scale.size() != 2) {
|
||||||
|
std::string err_msg = op_name + ": scale expecting size 2, got scale.size(): " + std::to_string(scale.size());
|
||||||
|
MS_LOG(ERROR) << err_msg;
|
||||||
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
|
}
|
||||||
|
RETURN_IF_NOT_OK(ValidateScalar(op_name, "scale", scale[0], {0}, false));
|
||||||
|
RETURN_IF_NOT_OK(ValidateScalar(op_name, "scale", scale[1], {0}, true));
|
||||||
|
if (scale[1] < scale[0]) {
|
||||||
|
std::string err_msg = op_name + ": scale must be in the format of (min, max).";
|
||||||
|
MS_LOG(ERROR) << op_name + ": scale must be in the format of (min, max), but got: " << scale;
|
||||||
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
Status ValidateVectorRatio(const std::string &op_name, const std::vector<float> &ratio) {
|
||||||
|
if (ratio.size() != 2) {
|
||||||
|
std::string err_msg = op_name + ": ratio expecting size 2, got ratio.size(): " + std::to_string(ratio.size());
|
||||||
|
MS_LOG(ERROR) << err_msg;
|
||||||
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
|
}
|
||||||
|
RETURN_IF_NOT_OK(ValidateScalar(op_name, "scale", ratio[0], {0}, true));
|
||||||
|
RETURN_IF_NOT_OK(ValidateScalar(op_name, "scale", ratio[1], {0}, true));
|
||||||
|
if (ratio[1] < ratio[0]) {
|
||||||
|
std::string err_msg = op_name + ": ratio must be in the format of (min, max).";
|
||||||
|
MS_LOG(ERROR) << op_name + ": ratio must be in the format of (min, max), but got: " << ratio;
|
||||||
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
Status ValidateVectorTransforms(const std::string &op_name,
|
||||||
const std::vector<std::shared_ptr<TensorOperation>> &transforms) {
|
const std::vector<std::shared_ptr<TensorOperation>> &transforms) {
|
||||||
if (transforms.empty()) {
|
if (transforms.empty()) {
|
||||||
std::string err_msg = transform_name + ": transform list must not be empty.";
|
std::string err_msg = op_name + ": transform list must not be empty.";
|
||||||
MS_LOG(ERROR) << err_msg;
|
MS_LOG(ERROR) << err_msg;
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
}
|
}
|
||||||
for (int32_t i = 0; i < transforms.size(); ++i) {
|
for (int32_t i = 0; i < transforms.size(); ++i) {
|
||||||
if (transforms[i] == nullptr) {
|
if (transforms[i] == nullptr) {
|
||||||
std::string err_msg =
|
std::string err_msg =
|
||||||
transform_name + ": transform ops must not be null, got transform[" + std::to_string(i) + "] == nullptr.";
|
op_name + ": transform ops must not be null, got transform[" + std::to_string(i) + "] == nullptr.";
|
||||||
MS_LOG(ERROR) << err_msg;
|
MS_LOG(ERROR) << err_msg;
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
}
|
}
|
||||||
|
@ -118,7 +202,7 @@ Status ValidateVectorTransforms(const std::string &transform_name,
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CmpFloat(const float &a, const float &b, float epsilon) { return (std::fabs(a - b) < epsilon); }
|
bool CmpFloat(const float a, const float b, float epsilon) { return (std::fabs(a - b) < epsilon); }
|
||||||
|
|
||||||
// Transform operations for data.
|
// Transform operations for data.
|
||||||
namespace transforms {
|
namespace transforms {
|
||||||
|
|
|
@ -492,24 +492,7 @@ std::shared_ptr<TensorOp> BoundingBoxAugmentOperation::Build() {
|
||||||
CenterCropOperation::CenterCropOperation(std::vector<int32_t> size) : size_(size) {}
|
CenterCropOperation::CenterCropOperation(std::vector<int32_t> size) : size_(size) {}
|
||||||
|
|
||||||
Status CenterCropOperation::ValidateParams() {
|
Status CenterCropOperation::ValidateParams() {
|
||||||
if (size_.empty() || size_.size() > 2) {
|
RETURN_IF_NOT_OK(ValidateVectorSize("CenterCrop", size_));
|
||||||
std::string err_msg = "CenterCrop: size vector has incorrect size.";
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// We have to limit crop size due to library restrictions, optimized to only iterate over size_ once
|
|
||||||
for (int32_t i = 0; i < size_.size(); ++i) {
|
|
||||||
if (size_[i] <= 0) {
|
|
||||||
std::string err_msg = "CenterCrop: invalid size, size must be greater than 0, got: " + std::to_string(size_[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (size_[i] == INT_MAX) {
|
|
||||||
std::string err_msg = "CenterCrop: invalid size, size too large, got: " + std::to_string(size_[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,39 +519,16 @@ CropOperation::CropOperation(std::vector<int32_t> coordinates, std::vector<int32
|
||||||
: coordinates_(coordinates), size_(size) {}
|
: coordinates_(coordinates), size_(size) {}
|
||||||
|
|
||||||
Status CropOperation::ValidateParams() {
|
Status CropOperation::ValidateParams() {
|
||||||
// Do some input validation.
|
// We have to limit crop size due to library restrictions, optimized to only iterate over size_ once
|
||||||
|
// we don't check the coordinates here because we don't have access to image dimensions
|
||||||
|
RETURN_IF_NOT_OK(ValidateVectorSize("Crop", size_));
|
||||||
|
|
||||||
if (coordinates_.size() != 2) {
|
if (coordinates_.size() != 2) {
|
||||||
std::string err_msg = "Crop: coordinates must be a vector of two values";
|
std::string err_msg = "Crop: coordinates must be a vector of two values";
|
||||||
MS_LOG(ERROR) << err_msg;
|
MS_LOG(ERROR) << err_msg;
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
}
|
}
|
||||||
// we don't check the coordinates here because we don't have access to image dimensions
|
RETURN_IF_NOT_OK(ValidateVectorNonNegative("Crop", "coordinates", coordinates_));
|
||||||
if (size_.empty() || size_.size() > 2) {
|
|
||||||
std::string err_msg = "Crop: size must be a vector of one or two values";
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// We have to limit crop size due to library restrictions, optimized to only iterate over size_ once
|
|
||||||
for (int32_t i = 0; i < size_.size(); ++i) {
|
|
||||||
if (size_[i] <= 0) {
|
|
||||||
std::string err_msg = "Crop: invalid size, size must be greater than 0, got: " + std::to_string(size_[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (size_[i] == INT_MAX) {
|
|
||||||
std::string err_msg = "Crop: invalid size, size too large, got: " + std::to_string(size_[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int32_t j = 0; j < coordinates_.size(); ++j) {
|
|
||||||
if (coordinates_[j] < 0) {
|
|
||||||
std::string err_msg =
|
|
||||||
"Crop: invalid coordinates, coordinates must be greater than 0, got: " + std::to_string(coordinates_[j]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -595,17 +555,8 @@ CutMixBatchOperation::CutMixBatchOperation(ImageBatchFormat image_batch_format,
|
||||||
: image_batch_format_(image_batch_format), alpha_(alpha), prob_(prob) {}
|
: image_batch_format_(image_batch_format), alpha_(alpha), prob_(prob) {}
|
||||||
|
|
||||||
Status CutMixBatchOperation::ValidateParams() {
|
Status CutMixBatchOperation::ValidateParams() {
|
||||||
if (alpha_ <= 0) {
|
RETURN_IF_NOT_OK(ValidateFloatScalarPositive("CutMixBatch", "alpha", alpha_));
|
||||||
std::string err_msg =
|
RETURN_IF_NOT_OK(ValidateProbability("CutMixBatch", prob_));
|
||||||
"CutMixBatch: alpha must be a positive floating value however it is: " + std::to_string(alpha_);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (prob_ < 0 || prob_ > 1) {
|
|
||||||
std::string err_msg = "CutMixBatch: Probability has to be between 0 and 1.";
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,16 +569,8 @@ std::shared_ptr<TensorOp> CutMixBatchOperation::Build() {
|
||||||
CutOutOperation::CutOutOperation(int32_t length, int32_t num_patches) : length_(length), num_patches_(num_patches) {}
|
CutOutOperation::CutOutOperation(int32_t length, int32_t num_patches) : length_(length), num_patches_(num_patches) {}
|
||||||
|
|
||||||
Status CutOutOperation::ValidateParams() {
|
Status CutOutOperation::ValidateParams() {
|
||||||
if (length_ <= 0) {
|
RETURN_IF_NOT_OK(ValidateIntScalarPositive("CutOut", "length", length_));
|
||||||
std::string err_msg = "CutOut: length must be positive, got: " + std::to_string(length_);
|
RETURN_IF_NOT_OK(ValidateIntScalarPositive("CutOut", "num_patches", num_patches_));
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (num_patches_ <= 0) {
|
|
||||||
std::string err_msg = "CutOut: number of patches must be positive, got: " + std::to_string(num_patches_);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -667,13 +610,7 @@ std::shared_ptr<TensorOp> InvertOperation::Build() { return std::make_shared<Inv
|
||||||
MixUpBatchOperation::MixUpBatchOperation(float alpha) : alpha_(alpha) {}
|
MixUpBatchOperation::MixUpBatchOperation(float alpha) : alpha_(alpha) {}
|
||||||
|
|
||||||
Status MixUpBatchOperation::ValidateParams() {
|
Status MixUpBatchOperation::ValidateParams() {
|
||||||
if (alpha_ <= 0) {
|
RETURN_IF_NOT_OK(ValidateFloatScalarPositive("MixUpBatch", "alpha", alpha_));
|
||||||
std::string err_msg =
|
|
||||||
"MixUpBatch: alpha must be a positive floating value however it is: " + std::to_string(alpha_);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -781,29 +718,7 @@ std::shared_ptr<TensorOp> DvppDecodeResizeCropOperation::Build() {
|
||||||
NormalizeOperation::NormalizeOperation(std::vector<float> mean, std::vector<float> std) : mean_(mean), std_(std) {}
|
NormalizeOperation::NormalizeOperation(std::vector<float> mean, std::vector<float> std) : mean_(mean), std_(std) {}
|
||||||
|
|
||||||
Status NormalizeOperation::ValidateParams() {
|
Status NormalizeOperation::ValidateParams() {
|
||||||
if (mean_.size() != 3) {
|
RETURN_IF_NOT_OK(ValidateVectorMeanStd("Normalize", mean_, std_));
|
||||||
std::string err_msg = "Normalize: mean vector has incorrect size: " + std::to_string(mean_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (std_.size() != 3) {
|
|
||||||
std::string err_msg = "Normalize: std vector has incorrect size: " + std::to_string(std_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// check std/mean value
|
|
||||||
for (int32_t i = 0; i < std_.size(); ++i) {
|
|
||||||
if (std_[i] < 0.0f || std_[i] > 255.0f || CmpFloat(std_[i], 0.0f)) {
|
|
||||||
std::string err_msg = "Normalize: std vector has incorrect value: " + std::to_string(std_[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (mean_[i] < 0.0f || mean_[i] > 255.0f) {
|
|
||||||
std::string err_msg = "Normalize: mean vector has incorrect value: " + std::to_string(mean_[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -826,29 +741,7 @@ NormalizePadOperation::NormalizePadOperation(const std::vector<float> &mean, con
|
||||||
: mean_(mean), std_(std), dtype_(dtype) {}
|
: mean_(mean), std_(std), dtype_(dtype) {}
|
||||||
|
|
||||||
Status NormalizePadOperation::ValidateParams() {
|
Status NormalizePadOperation::ValidateParams() {
|
||||||
if (mean_.size() != 3) {
|
RETURN_IF_NOT_OK(ValidateVectorMeanStd("NormalizePad", mean_, std_));
|
||||||
std::string err_msg = "NormalizePad: mean vector has incorrect size: " + std::to_string(mean_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (std_.size() != 3) {
|
|
||||||
std::string err_msg = "NormalizePad: std vector has incorrect size: " + std::to_string(std_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// check std/mean value
|
|
||||||
for (int32_t i = 0; i < std_.size(); ++i) {
|
|
||||||
if (std_[i] < 0.0f || std_[i] > 255.0f || CmpFloat(std_[i], 0.0f)) {
|
|
||||||
std::string err_msg = "NormalizePad: std vector has incorrect value: " + std::to_string(std_[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (mean_[i] < 0.0f || mean_[i] > 255.0f) {
|
|
||||||
std::string err_msg = "NormalizePad: mean vector has incorrect value: " + std::to_string(mean_[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dtype_ != "float32" && dtype_ != "float16") {
|
if (dtype_ != "float32" && dtype_ != "float16") {
|
||||||
std::string err_msg = "NormalizePad: dtype must be float32 or float16, but got: " + dtype_;
|
std::string err_msg = "NormalizePad: dtype must be float32 or float16, but got: " + dtype_;
|
||||||
MS_LOG(ERROR) << err_msg;
|
MS_LOG(ERROR) << err_msg;
|
||||||
|
@ -963,18 +856,8 @@ Status RandomAffineOperation::ValidateParams() {
|
||||||
MS_LOG(ERROR) << err_msg;
|
MS_LOG(ERROR) << err_msg;
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
}
|
}
|
||||||
if (translate_range_[0] < -1 || translate_range_[0] > 1) {
|
RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[0], {-1, 1}, false, false));
|
||||||
std::string err_msg = "RandomAffine: minimum of translate range on x is out of range of [-1, 1], value = " +
|
RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[1], {-1, 1}, false, false));
|
||||||
std::to_string(translate_range_[0]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (translate_range_[1] < -1 || translate_range_[1] > 1) {
|
|
||||||
std::string err_msg = "RandomAffine: maximum of translate range on x is out of range of [-1, 1], value = " +
|
|
||||||
std::to_string(translate_range_[1]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (translate_range_.size() == 4) {
|
if (translate_range_.size() == 4) {
|
||||||
if (translate_range_[2] > translate_range_[3]) {
|
if (translate_range_[2] > translate_range_[3]) {
|
||||||
std::string err_msg = "RandomAffine: minimum of translate range on y is greater than maximum: min = " +
|
std::string err_msg = "RandomAffine: minimum of translate range on y is greater than maximum: min = " +
|
||||||
|
@ -982,45 +865,11 @@ Status RandomAffineOperation::ValidateParams() {
|
||||||
MS_LOG(ERROR) << err_msg;
|
MS_LOG(ERROR) << err_msg;
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
}
|
}
|
||||||
if (translate_range_[2] < -1 || translate_range_[2] > 1) {
|
RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[2], {-1, 1}, false, false));
|
||||||
std::string err_msg = "RandomAffine: minimum of translate range on y is out of range of [-1, 1], value = " +
|
RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[3], {-1, 1}, false, false));
|
||||||
std::to_string(translate_range_[2]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (translate_range_[3] < -1 || translate_range_[3] > 1) {
|
|
||||||
std::string err_msg = "RandomAffine: maximum of translate range on y is out of range of [-1, 1], value = " +
|
|
||||||
std::to_string(translate_range_[3]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Scale
|
// Scale
|
||||||
if (scale_range_.size() != 2) {
|
RETURN_IF_NOT_OK(ValidateVectorScale("RandomAffine", scale_range_));
|
||||||
std::string err_msg = "RandomAffine: scale_range vector has incorrect size: scale_range.size() = " +
|
|
||||||
std::to_string(scale_range_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (scale_range_[0] < 0) {
|
|
||||||
std::string err_msg =
|
|
||||||
"RandomAffine: min scale range must be greater than or equal to 0, got: " + std::to_string(scale_range_[0]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (scale_range_[1] <= 0) {
|
|
||||||
std::string err_msg =
|
|
||||||
"RandomAffine: max scale range must be greater than 0, got: " + std::to_string(scale_range_[1]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (scale_range_[0] > scale_range_[1]) {
|
|
||||||
std::string err_msg =
|
|
||||||
"RandomAffine: minimum of scale range is greater than maximum: min = " + std::to_string(scale_range_[0]) +
|
|
||||||
", max = " + std::to_string(scale_range_[1]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// Shear
|
// Shear
|
||||||
if (shear_ranges_.size() != 2 && shear_ranges_.size() != 4) {
|
if (shear_ranges_.size() != 2 && shear_ranges_.size() != 4) {
|
||||||
std::string err_msg = "RandomAffine: shear_ranges expecting size 2 or 4, got: shear_ranges.size() = " +
|
std::string err_msg = "RandomAffine: shear_ranges expecting size 2 or 4, got: shear_ranges.size() = " +
|
||||||
|
@ -1041,20 +890,7 @@ Status RandomAffineOperation::ValidateParams() {
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
}
|
}
|
||||||
// Fill Value
|
// Fill Value
|
||||||
if (fill_value_.size() != 3) {
|
RETURN_IF_NOT_OK(ValidateVectorFillvalue("RandomAffine", fill_value_));
|
||||||
std::string err_msg =
|
|
||||||
"RandomAffine: fill_value vector has incorrect size: fill_value.size() = " + std::to_string(fill_value_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
for (int32_t i = 0; i < fill_value_.size(); ++i) {
|
|
||||||
if (fill_value_[i] < 0 || fill_value_[i] > 255) {
|
|
||||||
std::string err_msg =
|
|
||||||
"RandomAffine: fill_value has to be between 0 and 255, got:" + std::to_string(fill_value_[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1074,7 +910,6 @@ std::shared_ptr<TensorOp> RandomAffineOperation::Build() {
|
||||||
RandomColorOperation::RandomColorOperation(float t_lb, float t_ub) : t_lb_(t_lb), t_ub_(t_ub) { random_op_ = true; }
|
RandomColorOperation::RandomColorOperation(float t_lb, float t_ub) : t_lb_(t_lb), t_ub_(t_ub) { random_op_ = true; }
|
||||||
|
|
||||||
Status RandomColorOperation::ValidateParams() {
|
Status RandomColorOperation::ValidateParams() {
|
||||||
// Do some input validation.
|
|
||||||
if (t_lb_ < 0 || t_ub_ < 0) {
|
if (t_lb_ < 0 || t_ub_ < 0) {
|
||||||
std::string err_msg =
|
std::string err_msg =
|
||||||
"RandomColor: lower bound or upper bound must be greater than or equal to 0, got t_lb: " + std::to_string(t_lb_) +
|
"RandomColor: lower bound or upper bound must be greater than or equal to 0, got t_lb: " + std::to_string(t_lb_) +
|
||||||
|
@ -1101,89 +936,13 @@ RandomColorAdjustOperation::RandomColorAdjustOperation(std::vector<float> bright
|
||||||
|
|
||||||
Status RandomColorAdjustOperation::ValidateParams() {
|
Status RandomColorAdjustOperation::ValidateParams() {
|
||||||
// brightness
|
// brightness
|
||||||
if (brightness_.empty() || brightness_.size() > 2) {
|
RETURN_IF_NOT_OK(ValidateVectorColorAttribute("RandomColorAdjust", "brightness", brightness_, {0}));
|
||||||
std::string err_msg =
|
|
||||||
"RandomColorAdjust: brightness must be a vector of one or two values, got: " + std::to_string(brightness_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
for (int32_t i = 0; i < brightness_.size(); ++i) {
|
|
||||||
if (brightness_[i] < 0) {
|
|
||||||
std::string err_msg =
|
|
||||||
"RandomColorAdjust: brightness must be greater than or equal to 0, got: " + std::to_string(brightness_[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (brightness_.size() == 2 && (brightness_[0] > brightness_[1])) {
|
|
||||||
std::string err_msg = "RandomColorAdjust: brightness lower bound must be less or equal to upper bound, got lb: " +
|
|
||||||
std::to_string(brightness_[0]) + ", ub: " + std::to_string(brightness_[1]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// contrast
|
// contrast
|
||||||
if (contrast_.empty() || contrast_.size() > 2) {
|
RETURN_IF_NOT_OK(ValidateVectorColorAttribute("RandomColorAdjust", "contrast", contrast_, {0}));
|
||||||
std::string err_msg =
|
|
||||||
"RandomColorAdjust: contrast must be a vector of one or two values, got: " + std::to_string(contrast_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
for (int32_t i = 0; i < contrast_.size(); ++i) {
|
|
||||||
if (contrast_[i] < 0) {
|
|
||||||
std::string err_msg =
|
|
||||||
"RandomColorAdjust: contrast must be greater than or equal to 0, got: " + std::to_string(contrast_[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (contrast_.size() == 2 && (contrast_[0] > contrast_[1])) {
|
|
||||||
std::string err_msg = "RandomColorAdjust: contrast lower bound must be less or equal to upper bound, got lb: " +
|
|
||||||
std::to_string(contrast_[0]) + ", ub: " + std::to_string(contrast_[1]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// saturation
|
// saturation
|
||||||
if (saturation_.empty() || saturation_.size() > 2) {
|
RETURN_IF_NOT_OK(ValidateVectorColorAttribute("RandomColorAdjust", "saturation", saturation_, {0}));
|
||||||
std::string err_msg =
|
|
||||||
"RandomColorAdjust: saturation must be a vector of one or two values, got: " + std::to_string(saturation_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
for (int32_t i = 0; i < saturation_.size(); ++i) {
|
|
||||||
if (saturation_[i] < 0) {
|
|
||||||
std::string err_msg =
|
|
||||||
"RandomColorAdjust: saturation must be greater than or equal to 0, got: " + std::to_string(saturation_[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (saturation_.size() == 2 && (saturation_[0] > saturation_[1])) {
|
|
||||||
std::string err_msg = "RandomColorAdjust: saturation lower bound must be less or equal to upper bound, got lb: " +
|
|
||||||
std::to_string(saturation_[0]) + ", ub: " + std::to_string(saturation_[1]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// hue
|
// hue
|
||||||
if (hue_.empty() || hue_.size() > 2) {
|
RETURN_IF_NOT_OK(ValidateVectorColorAttribute("RandomColorAdjust", "hue", hue_, {-0.5, 0.5}));
|
||||||
std::string err_msg =
|
|
||||||
"RandomColorAdjust: hue must be a vector of one or two values, got: " + std::to_string(hue_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
for (int32_t i = 0; i < hue_.size(); ++i) {
|
|
||||||
if (hue_[i] < -0.5 || hue_[i] > 0.5) {
|
|
||||||
std::string err_msg = "RandomColorAdjust: hue has to be between -0.5 and 0.5, got: " + std::to_string(hue_[i]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hue_.size() == 2 && (hue_[0] > hue_[1])) {
|
|
||||||
std::string err_msg =
|
|
||||||
"RandomColorAdjust: hue lower bound must be less or equal to upper bound, got lb: " + std::to_string(hue_[0]) +
|
|
||||||
", ub: " + std::to_string(hue_[1]);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1239,12 +998,7 @@ RandomCropOperation::RandomCropOperation(std::vector<int32_t> size, std::vector<
|
||||||
|
|
||||||
Status RandomCropOperation::ValidateParams() {
|
Status RandomCropOperation::ValidateParams() {
|
||||||
// size
|
// size
|
||||||
if (size_.empty() || size_.size() > 2) {
|
RETURN_IF_NOT_OK(ValidateVectorSize("RandomCrop", size_));
|
||||||
std::string err_msg = "RandomCrop: size must be a vector of one or two values";
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
RETURN_IF_NOT_OK(ValidateVectorPositive("RandomCrop", size_));
|
|
||||||
// padding
|
// padding
|
||||||
RETURN_IF_NOT_OK(ValidateVectorPadding("RandomCrop", padding_));
|
RETURN_IF_NOT_OK(ValidateVectorPadding("RandomCrop", padding_));
|
||||||
// fill_value
|
// fill_value
|
||||||
|
@ -1352,12 +1106,7 @@ RandomCropWithBBoxOperation::RandomCropWithBBoxOperation(std::vector<int32_t> si
|
||||||
|
|
||||||
Status RandomCropWithBBoxOperation::ValidateParams() {
|
Status RandomCropWithBBoxOperation::ValidateParams() {
|
||||||
// size
|
// size
|
||||||
if (size_.empty() || size_.size() > 2) {
|
RETURN_IF_NOT_OK(ValidateVectorSize("RandomCropWithBBox", size_));
|
||||||
std::string err_msg = "RandomCropWithBBox: size must be a vector of one or two values";
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
RETURN_IF_NOT_OK(ValidateVectorPositive("RandomCropWithBBox", size_));
|
|
||||||
// padding
|
// padding
|
||||||
RETURN_IF_NOT_OK(ValidateVectorPadding("RandomCropWithBBox", padding_));
|
RETURN_IF_NOT_OK(ValidateVectorPadding("RandomCropWithBBox", padding_));
|
||||||
// fill_value
|
// fill_value
|
||||||
|
@ -1418,7 +1167,6 @@ RandomHorizontalFlipOperation::RandomHorizontalFlipOperation(float probability)
|
||||||
|
|
||||||
Status RandomHorizontalFlipOperation::ValidateParams() {
|
Status RandomHorizontalFlipOperation::ValidateParams() {
|
||||||
RETURN_IF_NOT_OK(ValidateProbability("RandomHorizontalFlip", probability_));
|
RETURN_IF_NOT_OK(ValidateProbability("RandomHorizontalFlip", probability_));
|
||||||
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1433,7 +1181,6 @@ RandomHorizontalFlipWithBBoxOperation::RandomHorizontalFlipWithBBoxOperation(flo
|
||||||
|
|
||||||
Status RandomHorizontalFlipWithBBoxOperation::ValidateParams() {
|
Status RandomHorizontalFlipWithBBoxOperation::ValidateParams() {
|
||||||
RETURN_IF_NOT_OK(ValidateProbability("RandomHorizontalFlipWithBBox", probability_));
|
RETURN_IF_NOT_OK(ValidateProbability("RandomHorizontalFlipWithBBox", probability_));
|
||||||
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1482,18 +1229,7 @@ std::shared_ptr<TensorOp> RandomPosterizeOperation::Build() {
|
||||||
RandomResizeOperation::RandomResizeOperation(std::vector<int32_t> size) : TensorOperation(true), size_(size) {}
|
RandomResizeOperation::RandomResizeOperation(std::vector<int32_t> size) : TensorOperation(true), size_(size) {}
|
||||||
|
|
||||||
Status RandomResizeOperation::ValidateParams() {
|
Status RandomResizeOperation::ValidateParams() {
|
||||||
// size
|
RETURN_IF_NOT_OK(ValidateVectorSize("RandomResize", size_));
|
||||||
if (size_.size() != 2 && size_.size() != 1) {
|
|
||||||
std::string err_msg =
|
|
||||||
"RandomResize: size must be a vector of one or two values, got: " + std::to_string(size_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (size_[0] <= 0 || (size_.size() == 2 && size_[1] <= 0)) {
|
|
||||||
std::string err_msg = "RandomResize: size must only contain positive integers.";
|
|
||||||
MS_LOG(ERROR) << "RandomResize: size must only contain positive integers, got: " << size_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1517,18 +1253,7 @@ RandomResizeWithBBoxOperation::RandomResizeWithBBoxOperation(std::vector<int32_t
|
||||||
: TensorOperation(true), size_(size) {}
|
: TensorOperation(true), size_(size) {}
|
||||||
|
|
||||||
Status RandomResizeWithBBoxOperation::ValidateParams() {
|
Status RandomResizeWithBBoxOperation::ValidateParams() {
|
||||||
// size
|
RETURN_IF_NOT_OK(ValidateVectorSize("RandomResizeWithBBox", size_));
|
||||||
if (size_.size() != 2 && size_.size() != 1) {
|
|
||||||
std::string err_msg =
|
|
||||||
"RandomResizeWithBBox: size must be a vector of one or two values, got: " + std::to_string(size_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (size_[0] <= 0 || (size_.size() == 2 && size_[1] <= 0)) {
|
|
||||||
std::string err_msg = "RandomResizeWithBBox: size must only contain positive integers.";
|
|
||||||
MS_LOG(ERROR) << "RandomResizeWithBBox: size must only contain positive integers, got: " << size_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1560,53 +1285,11 @@ RandomResizedCropOperation::RandomResizedCropOperation(std::vector<int32_t> size
|
||||||
|
|
||||||
Status RandomResizedCropOperation::ValidateParams() {
|
Status RandomResizedCropOperation::ValidateParams() {
|
||||||
// size
|
// size
|
||||||
if (size_.size() != 2 && size_.size() != 1) {
|
RETURN_IF_NOT_OK(ValidateVectorSize(Name(), size_));
|
||||||
std::string err_msg = Name() + ": size must be a vector of one or two values, got: " + std::to_string(size_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (size_[0] <= 0 || (size_.size() == 2 && size_[1] <= 0)) {
|
|
||||||
std::string err_msg = Name() + ": size must only contain positive integers.";
|
|
||||||
MS_LOG(ERROR) << Name() + ": size must only contain positive integers, got: " << size_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// scale
|
// scale
|
||||||
if (scale_.size() != 2) {
|
RETURN_IF_NOT_OK(ValidateVectorScale(Name(), scale_));
|
||||||
std::string err_msg = Name() + ": scale must be a vector of two values, got: " + std::to_string(scale_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (scale_[0] < 0) {
|
|
||||||
std::string err_msg = Name() + ": min scale must be greater than or equal to 0.";
|
|
||||||
MS_LOG(ERROR) << Name() + ": min scale must be greater than or equal to 0, got: " + std::to_string(scale_[0]);
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (scale_[1] <= 0) {
|
|
||||||
std::string err_msg = Name() + ": max scale must be greater than 0.";
|
|
||||||
MS_LOG(ERROR) << Name() + ": max scale must be greater than 0, got: " + std::to_string(scale_[1]);
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (scale_[1] < scale_[0]) {
|
|
||||||
std::string err_msg = Name() + ": scale must have a size of two in the format of (min, max).";
|
|
||||||
MS_LOG(ERROR) << Name() + ": scale must have a size of two in the format of (min, max), but got: " << scale_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// ratio
|
// ratio
|
||||||
if (ratio_.size() != 2) {
|
RETURN_IF_NOT_OK(ValidateVectorRatio(Name(), ratio_));
|
||||||
std::string err_msg = Name() + ": ratio must be a vector of two values, got: " + std::to_string(ratio_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (ratio_[0] <= 0 || ratio_[1] <= 0) {
|
|
||||||
std::string err_msg = Name() + ": ratio must be greater than 0.";
|
|
||||||
MS_LOG(ERROR) << Name() + ": ratio must be greater than 0, got: " << ratio_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (ratio_[1] < ratio_[0]) {
|
|
||||||
std::string err_msg = Name() + ": ratio must have a size of two in the format of (min, max).";
|
|
||||||
MS_LOG(ERROR) << Name() + ": ratio must have a size of two in the format of (min, max), but got: " << ratio_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// max_attempts
|
// max_attempts
|
||||||
if (max_attempts_ < 1) {
|
if (max_attempts_ < 1) {
|
||||||
std::string err_msg =
|
std::string err_msg =
|
||||||
|
@ -1639,59 +1322,11 @@ RandomResizedCropWithBBoxOperation::RandomResizedCropWithBBoxOperation(std::vect
|
||||||
|
|
||||||
Status RandomResizedCropWithBBoxOperation::ValidateParams() {
|
Status RandomResizedCropWithBBoxOperation::ValidateParams() {
|
||||||
// size
|
// size
|
||||||
if (size_.size() != 2 && size_.size() != 1) {
|
RETURN_IF_NOT_OK(ValidateVectorSize("RandomResizedCropWithBBox", size_));
|
||||||
std::string err_msg =
|
|
||||||
"RandomResizedCropWithBBox: size must be a vector of one or two values, got: " + std::to_string(size_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (size_[0] <= 0 || (size_.size() == 2 && size_[1] <= 0)) {
|
|
||||||
std::string err_msg = "RandomResizedCropWithBBox: size must only contain positive integers.";
|
|
||||||
MS_LOG(ERROR) << "RandomResizedCropWithBBox: size must only contain positive integers, got: " << size_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// scale
|
// scale
|
||||||
if (scale_.size() != 2) {
|
RETURN_IF_NOT_OK(ValidateVectorScale("RandomResizedCropWithBBox", scale_));
|
||||||
std::string err_msg =
|
|
||||||
"RandomResizedCropWithBBox: scale must be a vector of two values, got: " + std::to_string(scale_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (scale_[0] < 0) {
|
|
||||||
std::string err_msg = "RandomResizedCropWithBBox: min scale must be greater than or equal to 0.";
|
|
||||||
MS_LOG(ERROR) << "RandomResizedCropWithBBox: min scale must be greater than or equal to 0, got: " +
|
|
||||||
std::to_string(scale_[0]);
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (scale_[1] <= 0) {
|
|
||||||
std::string err_msg = "RandomResizedCropWithBBox: max scale must be greater than 0.";
|
|
||||||
MS_LOG(ERROR) << "RandomResizedCropWithBBox: max scale must be greater than 0, got: " + std::to_string(scale_[1]);
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (scale_[1] < scale_[0]) {
|
|
||||||
std::string err_msg = "RandomResizedCropWithBBox: scale must have a size of two in the format of (min, max).";
|
|
||||||
MS_LOG(ERROR) << "RandomResizedCropWithBBox: scale must have a size of two in the format of (min, max), but got: "
|
|
||||||
<< scale_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// ratio
|
// ratio
|
||||||
if (ratio_.size() != 2) {
|
RETURN_IF_NOT_OK(ValidateVectorRatio("RandomResizedCropWithBBox", ratio_));
|
||||||
std::string err_msg =
|
|
||||||
"RandomResizedCropWithBBox: ratio must be a vector of two values, got: " + std::to_string(ratio_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (ratio_[0] <= 0 || ratio_[1] <= 0) {
|
|
||||||
std::string err_msg = "RandomResizedCropWithBBox: ratio must be greater than 0.";
|
|
||||||
MS_LOG(ERROR) << "RandomResizedCropWithBBox: ratio must be greater than 0, got: " << ratio_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (ratio_[1] < ratio_[0]) {
|
|
||||||
std::string err_msg = "RandomResizedCropWithBBox: ratio must have a size of two in the format of (min, max).";
|
|
||||||
MS_LOG(ERROR) << "RandomResizedCropWithBBox: ratio must have a size of two in the format of (min, max), but got: "
|
|
||||||
<< ratio_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// max_attempts
|
// max_attempts
|
||||||
if (max_attempts_ < 1) {
|
if (max_attempts_ < 1) {
|
||||||
std::string err_msg = "RandomResizedCropWithBBox: max_attempts must be greater than or equal to 1, got: " +
|
std::string err_msg = "RandomResizedCropWithBBox: max_attempts must be greater than or equal to 1, got: " +
|
||||||
|
@ -1859,7 +1494,6 @@ Status RandomSharpnessOperation::ValidateParams() {
|
||||||
MS_LOG(ERROR) << "RandomSharpness: degrees must be in the format of (min, max), got: " << degrees_;
|
MS_LOG(ERROR) << "RandomSharpness: degrees must be in the format of (min, max), got: " << degrees_;
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1962,14 +1596,7 @@ ResizeOperation::ResizeOperation(std::vector<int32_t> size, InterpolationMode in
|
||||||
: size_(size), interpolation_(interpolation) {}
|
: size_(size), interpolation_(interpolation) {}
|
||||||
|
|
||||||
Status ResizeOperation::ValidateParams() {
|
Status ResizeOperation::ValidateParams() {
|
||||||
// size
|
RETURN_IF_NOT_OK(ValidateVectorSize("Resize", size_));
|
||||||
if (size_.empty() || size_.size() > 2) {
|
|
||||||
std::string err_msg = "Resize: size must be a vector of one or two values, got: " + std::to_string(size_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
RETURN_IF_NOT_OK(ValidateVectorPositive("Resize", size_));
|
|
||||||
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2012,15 +1639,7 @@ ResizeWithBBoxOperation::ResizeWithBBoxOperation(std::vector<int32_t> size, Inte
|
||||||
: size_(size), interpolation_(interpolation) {}
|
: size_(size), interpolation_(interpolation) {}
|
||||||
|
|
||||||
Status ResizeWithBBoxOperation::ValidateParams() {
|
Status ResizeWithBBoxOperation::ValidateParams() {
|
||||||
// size
|
RETURN_IF_NOT_OK(ValidateVectorSize("ResizeWithBBox", size_));
|
||||||
if (size_.empty() || size_.size() > 2) {
|
|
||||||
std::string err_msg =
|
|
||||||
"ResizeWithBBox: size must be a vector of one or two values, got: " + std::to_string(size_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
RETURN_IF_NOT_OK(ValidateVectorPositive("Resize", size_));
|
|
||||||
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2065,60 +1684,11 @@ SoftDvppDecodeRandomCropResizeJpegOperation::SoftDvppDecodeRandomCropResizeJpegO
|
||||||
|
|
||||||
Status SoftDvppDecodeRandomCropResizeJpegOperation::ValidateParams() {
|
Status SoftDvppDecodeRandomCropResizeJpegOperation::ValidateParams() {
|
||||||
// size
|
// size
|
||||||
if (size_.size() != 2 && size_.size() != 1) {
|
RETURN_IF_NOT_OK(ValidateVectorSize("SoftDvppDecodeRandomCropResizeJpeg", size_));
|
||||||
std::string err_msg = "SoftDvppDecodeRandomCropResizeJpeg: size must be a vector of one or two values, got: " +
|
|
||||||
std::to_string(size_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (size_[0] <= 0 || (size_.size() == 2 && size_[1] <= 0)) {
|
|
||||||
std::string err_msg = "SoftDvppDecodeRandomCropResizeJpeg: size must only contain positive integers.";
|
|
||||||
MS_LOG(ERROR) << "SoftDvppDecodeRandomCropResizeJpeg: size must only contain positive integers, got: " << size_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// scale
|
// scale
|
||||||
if (scale_.size() != 2) {
|
RETURN_IF_NOT_OK(ValidateVectorScale("SoftDvppDecodeRandomCropResizeJpeg", scale_));
|
||||||
std::string err_msg =
|
|
||||||
"SoftDvppDecodeRandomCropResizeJpeg: scale must be a vector of two values, got: " + std::to_string(scale_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (scale_[0] < 0) {
|
|
||||||
std::string err_msg = "SoftDvppDecodeRandomCropResizeJpeg: min scale must be greater than or equal to 0.";
|
|
||||||
MS_LOG(ERROR) << "SoftDvppDecodeRandomCropResizeJpeg: min scale must be greater than or equal to 0, got: " +
|
|
||||||
std::to_string(scale_[0]);
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (scale_[1] <= 0) {
|
|
||||||
std::string err_msg = "SoftDvppDecodeRandomCropResizeJpeg: max scale must be greater than 0.";
|
|
||||||
MS_LOG(ERROR) << "SoftDvppDecodeRandomCropResizeJpeg: max scale must be greater than 0, got: " +
|
|
||||||
std::to_string(scale_[1]);
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (scale_[1] < scale_[0]) {
|
|
||||||
std::string err_msg = "SoftDvppDecodeRandomCropResizeJpeg: scale must be in the format of (min, max).";
|
|
||||||
MS_LOG(ERROR) << "SoftDvppDecodeRandomCropResizeJpeg: scale must be in the format of (min, max), but got: "
|
|
||||||
<< scale_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// ratio
|
// ratio
|
||||||
if (ratio_.size() != 2) {
|
RETURN_IF_NOT_OK(ValidateVectorRatio("SoftDvppDecodeRandomCropResizeJpeg", ratio_));
|
||||||
std::string err_msg =
|
|
||||||
"SoftDvppDecodeRandomCropResizeJpeg: ratio must be a vector of two values, got: " + std::to_string(ratio_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (ratio_[0] <= 0 || ratio_[1] <= 0) {
|
|
||||||
std::string err_msg = "SoftDvppDecodeRandomCropResizeJpeg: ratio must be greater than 0.";
|
|
||||||
MS_LOG(ERROR) << "SoftDvppDecodeRandomCropResizeJpeg: ratio must be greater than 0, got: " << ratio_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
if (ratio_[1] < ratio_[0]) {
|
|
||||||
std::string err_msg = "SoftDvppDecodeRandomCropResizeJpeg: ratio must be in the format of (min, max).";
|
|
||||||
MS_LOG(ERROR) << "SoftDvppDecodeRandomCropResizeJpeg: ratio must be in the format of (min, max), but got: "
|
|
||||||
<< ratio_;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
// max_attempts
|
// max_attempts
|
||||||
if (max_attempts_ < 1) {
|
if (max_attempts_ < 1) {
|
||||||
std::string err_msg = "SoftDvppDecodeRandomCropResizeJpeg: max_attempts must be greater than or equal to 1, got: " +
|
std::string err_msg = "SoftDvppDecodeRandomCropResizeJpeg: max_attempts must be greater than or equal to 1, got: " +
|
||||||
|
@ -2146,15 +1716,7 @@ std::shared_ptr<TensorOp> SoftDvppDecodeRandomCropResizeJpegOperation::Build() {
|
||||||
SoftDvppDecodeResizeJpegOperation::SoftDvppDecodeResizeJpegOperation(std::vector<int32_t> size) : size_(size) {}
|
SoftDvppDecodeResizeJpegOperation::SoftDvppDecodeResizeJpegOperation(std::vector<int32_t> size) : size_(size) {}
|
||||||
|
|
||||||
Status SoftDvppDecodeResizeJpegOperation::ValidateParams() {
|
Status SoftDvppDecodeResizeJpegOperation::ValidateParams() {
|
||||||
// size
|
RETURN_IF_NOT_OK(ValidateVectorSize("SoftDvppDecodeResizeJpeg", size_));
|
||||||
if (size_.empty() || size_.size() > 2) {
|
|
||||||
std::string err_msg =
|
|
||||||
"SoftDvppDecodeResizeJpeg: size must be a vector of one or two values, got: " + std::to_string(size_.size());
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
RETURN_IF_NOT_OK(ValidateVectorPositive("SoftDvppDecodeResizeJpeg", size_));
|
|
||||||
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2195,11 +1757,7 @@ Status UniformAugOperation::ValidateParams() {
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
}
|
}
|
||||||
// num_ops
|
// num_ops
|
||||||
if (num_ops_ <= 0) {
|
RETURN_IF_NOT_OK(ValidateIntScalarPositive("UniformAug", "num_ops", num_ops_));
|
||||||
std::string err_msg = "UniformAug: num_ops must be greater than 0, but got: " + std::to_string(num_ops_);
|
|
||||||
MS_LOG(ERROR) << err_msg;
|
|
||||||
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
|
||||||
}
|
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "minddata/dataset/include/constants.h"
|
#include "minddata/dataset/include/constants.h"
|
||||||
#include "minddata/dataset/include/status.h"
|
#include "minddata/dataset/include/status.h"
|
||||||
|
#include "minddata/dataset/include/tensor.h"
|
||||||
|
|
||||||
#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
||||||
#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
||||||
|
@ -88,24 +89,80 @@ class TensorOperation : public std::enable_shared_from_this<TensorOperation> {
|
||||||
bool random_op_;
|
bool random_op_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper function to validate fill value
|
|
||||||
Status ValidateVectorFillvalue(const std::string &transform_name, const std::vector<uint8_t> &fill_value);
|
|
||||||
|
|
||||||
// Helper function to validate probability
|
// Helper function to validate probability
|
||||||
Status ValidateProbability(const std::string &transform_name, const float &probability);
|
Status ValidateProbability(const std::string &op_name, const float probability);
|
||||||
|
|
||||||
|
// Helper function to positive int scalar
|
||||||
|
Status ValidateIntScalarPositive(const std::string &op_name, const std::string &scalar_name, int32_t scalar);
|
||||||
|
|
||||||
|
// Helper function to positive float scalar
|
||||||
|
Status ValidateFloatScalarPositive(const std::string &op_name, const std::string &scalar_name, float scalar);
|
||||||
|
|
||||||
|
// Helper function to validate scalar
|
||||||
|
template <typename T>
|
||||||
|
Status ValidateScalar(const std::string &op_name, const std::string &scalar_name, const T scalar,
|
||||||
|
const std::vector<T> &range, bool left_open_interval = false, bool right_open_interval = false) {
|
||||||
|
if (range.empty() || range.size() > 2) {
|
||||||
|
std::string err_msg = "Range check expecting size 1 or 2, but got: " + std::to_string(range.size());
|
||||||
|
MS_LOG(ERROR) << err_msg;
|
||||||
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
|
}
|
||||||
|
if ((left_open_interval && scalar <= range[0]) || (!left_open_interval && scalar < range[0])) {
|
||||||
|
std::string interval_description = left_open_interval ? " greater than " : " greater than or equal to ";
|
||||||
|
std::string err_msg = op_name + ":" + scalar_name + " must be" + interval_description + std::to_string(range[0]) +
|
||||||
|
", got: " + std::to_string(scalar);
|
||||||
|
MS_LOG(ERROR) << err_msg;
|
||||||
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
|
}
|
||||||
|
if (range.size() == 2) {
|
||||||
|
if ((right_open_interval && scalar >= range[1]) || (!right_open_interval && scalar > range[1])) {
|
||||||
|
std::string left_bracket = left_open_interval ? "(" : "[";
|
||||||
|
std::string right_bracket = right_open_interval ? ")" : "]";
|
||||||
|
std::string err_msg = op_name + ":" + scalar_name + " is out of range " + left_bracket +
|
||||||
|
std::to_string(range[0]) + ", " + std::to_string(range[1]) + right_bracket +
|
||||||
|
", got: " + std::to_string(scalar);
|
||||||
|
MS_LOG(ERROR) << err_msg;
|
||||||
|
RETURN_STATUS_SYNTAX_ERROR(err_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Status::OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to validate color attribute
|
||||||
|
Status ValidateVectorColorAttribute(const std::string &op_name, const std::string &attr_name,
|
||||||
|
const std::vector<float> &attr, const std::vector<float> &range);
|
||||||
|
|
||||||
|
// Helper function to validate fill value
|
||||||
|
Status ValidateVectorFillvalue(const std::string &op_name, const std::vector<uint8_t> &fill_value);
|
||||||
|
|
||||||
|
// Helper function to validate mean/std value
|
||||||
|
Status ValidateVectorMeanStd(const std::string &op_name, const std::vector<float> &mean, const std::vector<float> &std);
|
||||||
|
|
||||||
// Helper function to validate padding
|
// Helper function to validate padding
|
||||||
Status ValidateVectorPadding(const std::string &transform_name, const std::vector<int32_t> &padding);
|
Status ValidateVectorPadding(const std::string &op_name, const std::vector<int32_t> &padding);
|
||||||
|
|
||||||
// Helper function to validate size
|
// Helper function to validate positive value
|
||||||
Status ValidateVectorPositive(const std::string &transform_name, const std::vector<int32_t> &size);
|
Status ValidateVectorPositive(const std::string &op_name, const std::string &vec_name, const std::vector<int32_t> &vec);
|
||||||
|
|
||||||
|
// Helper function to validate non-negative value
|
||||||
|
Status ValidateVectorNonNegative(const std::string &op_name, const std::string &vec_name,
|
||||||
|
const std::vector<int32_t> &vec);
|
||||||
|
|
||||||
|
// Helper function to validate size of size
|
||||||
|
Status ValidateVectorSize(const std::string &op_name, const std::vector<int32_t> &size);
|
||||||
|
|
||||||
|
// Helper function to validate scale
|
||||||
|
Status ValidateVectorScale(const std::string &op_name, const std::vector<float> &scale);
|
||||||
|
|
||||||
|
// Helper function to validate ratio
|
||||||
|
Status ValidateVectorRatio(const std::string &op_name, const std::vector<float> &ratio);
|
||||||
|
|
||||||
// Helper function to validate transforms
|
// Helper function to validate transforms
|
||||||
Status ValidateVectorTransforms(const std::string &transform_name,
|
Status ValidateVectorTransforms(const std::string &op_name,
|
||||||
const std::vector<std::shared_ptr<TensorOperation>> &transforms);
|
const std::vector<std::shared_ptr<TensorOperation>> &transforms);
|
||||||
|
|
||||||
// Helper function to compare float value
|
// Helper function to compare float value
|
||||||
bool CmpFloat(const float &a, const float &b, float epsilon = 0.0000000001f);
|
bool CmpFloat(const float a, const float b, float epsilon = 0.0000000001f);
|
||||||
|
|
||||||
// Transform operations for performing data transformation.
|
// Transform operations for performing data transformation.
|
||||||
namespace transforms {
|
namespace transforms {
|
||||||
|
|
|
@ -265,6 +265,9 @@ TEST_F(MindDataTestPipeline, TestCropFail) {
|
||||||
// zero height
|
// zero height
|
||||||
crop = mindspore::dataset::vision::Crop({0, 0}, {0, 32});
|
crop = mindspore::dataset::vision::Crop({0, 0}, {0, 32});
|
||||||
EXPECT_EQ(crop, nullptr);
|
EXPECT_EQ(crop, nullptr);
|
||||||
|
// negative coordinates
|
||||||
|
crop = mindspore::dataset::vision::Crop({-1, 0}, {32, 32});
|
||||||
|
EXPECT_EQ(crop, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MindDataTestPipeline, TestCutMixBatchSuccess1) {
|
TEST_F(MindDataTestPipeline, TestCutMixBatchSuccess1) {
|
||||||
|
@ -882,7 +885,7 @@ TEST_F(MindDataTestPipeline, TestNormalize) {
|
||||||
EXPECT_NE(ds, nullptr);
|
EXPECT_NE(ds, nullptr);
|
||||||
|
|
||||||
// Create objects for the tensor ops
|
// Create objects for the tensor ops
|
||||||
std::shared_ptr<TensorOperation> normalize = vision::Normalize({121.0, 115.0, 100.0}, {70.0, 68.0, 71.0});
|
std::shared_ptr<TensorOperation> normalize = vision::Normalize({121.0, 115.0, 0.0}, {70.0, 68.0, 71.0});
|
||||||
EXPECT_NE(normalize, nullptr);
|
EXPECT_NE(normalize, nullptr);
|
||||||
|
|
||||||
// Create a Map operation on ds
|
// Create a Map operation on ds
|
||||||
|
@ -924,6 +927,15 @@ TEST_F(MindDataTestPipeline, TestNormalizeFail) {
|
||||||
std::shared_ptr<TensorOperation> normalize =
|
std::shared_ptr<TensorOperation> normalize =
|
||||||
mindspore::dataset::vision::Normalize({121.0, 115.0, 100.0}, {0.0, 68.0, 71.0});
|
mindspore::dataset::vision::Normalize({121.0, 115.0, 100.0}, {0.0, 68.0, 71.0});
|
||||||
EXPECT_EQ(normalize, nullptr);
|
EXPECT_EQ(normalize, nullptr);
|
||||||
|
// mean out of range
|
||||||
|
normalize = mindspore::dataset::vision::Normalize({121.0, 0.0, 100.0}, {256.0, 68.0, 71.0});
|
||||||
|
EXPECT_EQ(normalize, nullptr);
|
||||||
|
// mean out of range
|
||||||
|
normalize = mindspore::dataset::vision::Normalize({256.0, 0.0, 100.0}, {70.0, 68.0, 71.0});
|
||||||
|
EXPECT_EQ(normalize, nullptr);
|
||||||
|
// mean out of range
|
||||||
|
normalize = mindspore::dataset::vision::Normalize({-1.0, 0.0, 100.0}, {70.0, 68.0, 71.0});
|
||||||
|
EXPECT_EQ(normalize, nullptr);
|
||||||
// normalize with 2 values (not 3 values) for mean
|
// normalize with 2 values (not 3 values) for mean
|
||||||
normalize = mindspore::dataset::vision::Normalize({121.0, 115.0}, {70.0, 68.0, 71.0});
|
normalize = mindspore::dataset::vision::Normalize({121.0, 115.0}, {70.0, 68.0, 71.0});
|
||||||
EXPECT_EQ(normalize, nullptr);
|
EXPECT_EQ(normalize, nullptr);
|
||||||
|
@ -1258,7 +1270,7 @@ TEST_F(MindDataTestPipeline, TestRandomColorAdjust) {
|
||||||
std::shared_ptr<TensorOperation> random_color_adjust4 = vision::RandomColorAdjust();
|
std::shared_ptr<TensorOperation> random_color_adjust4 = vision::RandomColorAdjust();
|
||||||
EXPECT_NE(random_color_adjust4, nullptr);
|
EXPECT_NE(random_color_adjust4, nullptr);
|
||||||
|
|
||||||
// Use subset of explictly set parameters
|
// Use subset of explicitly set parameters
|
||||||
std::shared_ptr<TensorOperation> random_color_adjust5 = vision::RandomColorAdjust({0.0, 0.5}, {0.25});
|
std::shared_ptr<TensorOperation> random_color_adjust5 = vision::RandomColorAdjust({0.0, 0.5}, {0.25});
|
||||||
EXPECT_NE(random_color_adjust5, nullptr);
|
EXPECT_NE(random_color_adjust5, nullptr);
|
||||||
|
|
||||||
|
@ -1295,6 +1307,31 @@ TEST_F(MindDataTestPipeline, TestRandomColorAdjust) {
|
||||||
iter->Stop();
|
iter->Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(MindDataTestPipeline, TestRandomColorAdjustFail) {
|
||||||
|
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomColorAdjustFail.";
|
||||||
|
// brightness out of range
|
||||||
|
std::shared_ptr<TensorOperation> random_color_adjust1 = vision::RandomColorAdjust({-1.0});
|
||||||
|
EXPECT_EQ(random_color_adjust1, nullptr);
|
||||||
|
|
||||||
|
// contrast out of range
|
||||||
|
std::shared_ptr<TensorOperation> random_color_adjust2 = vision::RandomColorAdjust({1.0}, {-0.1});
|
||||||
|
EXPECT_EQ(random_color_adjust2, nullptr);
|
||||||
|
|
||||||
|
// saturation out of range
|
||||||
|
std::shared_ptr<TensorOperation> random_color_adjust3 = vision::RandomColorAdjust({0.0}, {0.0}, {-0.2});
|
||||||
|
EXPECT_EQ(random_color_adjust3, nullptr);
|
||||||
|
|
||||||
|
// hue out of range
|
||||||
|
std::shared_ptr<TensorOperation> random_color_adjust4 = vision::RandomColorAdjust({0.0}, {0.0}, {0.0}, {-0.6});
|
||||||
|
EXPECT_EQ(random_color_adjust4, nullptr);
|
||||||
|
|
||||||
|
std::shared_ptr<TensorOperation> random_color_adjust5 = vision::RandomColorAdjust({0.0}, {0.0}, {0.0}, {-0.5, 0.6});
|
||||||
|
EXPECT_EQ(random_color_adjust5, nullptr);
|
||||||
|
|
||||||
|
std::shared_ptr<TensorOperation> random_color_adjust6 = vision::RandomColorAdjust({0.0}, {0.0}, {0.0}, {0.51});
|
||||||
|
EXPECT_EQ(random_color_adjust6, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(MindDataTestPipeline, TestRandomCropSuccess) {
|
TEST_F(MindDataTestPipeline, TestRandomCropSuccess) {
|
||||||
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomCropSuccess.";
|
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomCropSuccess.";
|
||||||
// Create an VOC Dataset
|
// Create an VOC Dataset
|
||||||
|
@ -1796,13 +1833,17 @@ TEST_F(MindDataTestPipeline, TestRandomResizeFail) {
|
||||||
std::shared_ptr<TensorOperation> random_resize1 = vision::RandomResize({-66, 77});
|
std::shared_ptr<TensorOperation> random_resize1 = vision::RandomResize({-66, 77});
|
||||||
EXPECT_EQ(random_resize1, nullptr);
|
EXPECT_EQ(random_resize1, nullptr);
|
||||||
|
|
||||||
// RandomResize : size must be a vector of one or two values
|
// RandomResize : size must only contain positive integers
|
||||||
std::shared_ptr<TensorOperation> random_resize2 = vision::RandomResize({1, 2, 3});
|
std::shared_ptr<TensorOperation> random_resize2 = vision::RandomResize({0, 77});
|
||||||
EXPECT_EQ(random_resize2, nullptr);
|
EXPECT_EQ(random_resize2, nullptr);
|
||||||
|
|
||||||
// RandomResize : size must be a vector of one or two values
|
// RandomResize : size must be a vector of one or two values
|
||||||
std::shared_ptr<TensorOperation> random_resize3 = vision::RandomResize({});
|
std::shared_ptr<TensorOperation> random_resize3 = vision::RandomResize({1, 2, 3});
|
||||||
EXPECT_EQ(random_resize3, nullptr);
|
EXPECT_EQ(random_resize3, nullptr);
|
||||||
|
|
||||||
|
// RandomResize : size must be a vector of one or two values
|
||||||
|
std::shared_ptr<TensorOperation> random_resize4 = vision::RandomResize({});
|
||||||
|
EXPECT_EQ(random_resize4, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MindDataTestPipeline, TestRandomResizeWithBBoxSuccess1) {
|
TEST_F(MindDataTestPipeline, TestRandomResizeWithBBoxSuccess1) {
|
||||||
|
|
Loading…
Reference in New Issue