!27061 dataset: enhance kernel part log

Merge pull request !27061 from ms_yan/kernel_enhance
This commit is contained in:
i-robot 2021-12-03 01:26:07 +00:00 committed by Gitee
commit f9459a871a
21 changed files with 145 additions and 86 deletions

View File

@ -53,9 +53,9 @@ Status ComposeOp::Compute(const TensorRow &inputs, TensorRow *outputs) {
ComposeOp::ComposeOp(const std::vector<std::shared_ptr<TensorOp>> &ops) : ops_(ops) {
if (ops_.empty()) {
MS_LOG(ERROR) << "Compose: op_list is empty, this might lead to Segmentation Fault.";
MS_LOG(ERROR) << "Compose: input 'transforms'(op_list) is empty, this might lead to Segmentation Fault.";
} else if (ops_.size() == 1) {
MS_LOG(WARNING) << "Compose: op_list has only 1 op. Compose is probably not needed.";
MS_LOG(WARNING) << "Compose: input 'transforms'(op_list) has only 1 op. Compose is probably not needed.";
}
}

View File

@ -55,7 +55,8 @@ Status OneHotEncodingUnsigned(const std::shared_ptr<Tensor> &input, std::shared_
} else if (input->type() == DataType::DE_UINT8) {
RETURN_IF_NOT_OK((*output)->SetItemAt<uint8_t>({index, static_cast<dsize_t>(class_idx)}, 1));
} else {
RETURN_STATUS_UNEXPECTED("OneHot: OneHot unsigned only supports unsigned int as input.");
RETURN_STATUS_UNEXPECTED("OneHot: unsigned input case only supports unsigned int as input, but got:" +
input->type().ToString());
}
return Status::OK();
}
@ -81,7 +82,8 @@ Status OneHotEncodingSigned(const std::shared_ptr<Tensor> &input, std::shared_pt
} else if (input->type() == DataType::DE_INT8) {
RETURN_IF_NOT_OK((*output)->SetItemAt<int8_t>({index, static_cast<dsize_t>(class_idx)}, 1));
} else {
RETURN_STATUS_UNEXPECTED("OneHot: OneHot signed only supports signed int as input.");
RETURN_STATUS_UNEXPECTED("OneHot: signed input case only supports signed int as input but got:" +
input->type().ToString());
}
return Status::OK();
}
@ -94,7 +96,7 @@ Status OneHotEncoding(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tens
std::to_string(input->Rank()));
}
if (!input->type().IsInt()) {
RETURN_STATUS_UNEXPECTED("OneHot: OneHot only not support input of int type.");
RETURN_STATUS_UNEXPECTED("OneHot: OneHot only support input of int type, but got:" + input->type().ToString());
}
try {
dsize_t num_elements = 1;
@ -209,7 +211,7 @@ Status FillHelper(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor>
break;
}
case DataType::DE_UNKNOWN: {
RETURN_STATUS_UNEXPECTED("Fill: unknown input datatype.");
RETURN_STATUS_UNEXPECTED("Fill: unknown input datatype, check input datatype of this operator.");
break;
}
default:
@ -228,8 +230,9 @@ Status Fill(const std::shared_ptr<Tensor> input, std::shared_ptr<Tensor> *output
CHECK_FAIL_RETURN_UNEXPECTED(!((fill_type == DataType::DE_STRING) && (input_type != DataType::DE_STRING)),
"Fill: fill datatype is string but the input datatype is not string.");
CHECK_FAIL_RETURN_UNEXPECTED(fill_value->shape() == TensorShape({}),
"Fill: the shape of fill_value is not a scalar.");
CHECK_FAIL_RETURN_UNEXPECTED(
fill_value->shape() == TensorShape({}),
"Fill: the shape of fill_value is not a scalar, got shape:" + fill_value->shape().ToString());
std::shared_ptr<Tensor> out, fill_output;
@ -297,7 +300,8 @@ void CastFrom(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *out
Cast<T, double>(input, output);
break;
case DataType::DE_UNKNOWN:
MS_LOG(ERROR) << "TypeCast: unknown datatype.";
MS_LOG(ERROR) << "TypeCast: unknown datatype of input data, supported datatype is: [bool, int8, uint8, int16, "
"uint16, int32, uint32, int64, uint64, float16, float32, float64].";
break;
}
}
@ -367,8 +371,9 @@ Status ToFloat16(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *
float float16_max = static_cast<float>(std::numeric_limits<float16>::max());
float float16_min = static_cast<float>(std::numeric_limits<float16>::lowest());
if (element > float16_max || element < float16_min) {
RETURN_STATUS_UNEXPECTED("ToFloat16: value " + std::to_string(element) + " is outside of valid float16 range [" +
std::to_string(float16_max) + ", " + std::to_string(float16_min) + "].");
RETURN_STATUS_UNEXPECTED("ToFloat16: value " + std::to_string(element) +
"in input data is outside of valid float16 range [" + std::to_string(float16_max) +
", " + std::to_string(float16_min) + "].");
}
*out_itr = float16(*in_itr);
@ -440,7 +445,9 @@ Status PadEndNumeric(const std::shared_ptr<Tensor> &src, std::shared_ptr<Tensor>
} else if (tensor_type == DataType::DE_FLOAT64) {
RETURN_IF_NOT_OK((*dst)->Fill<double>(static_cast<double>(pad_val)));
} else {
RETURN_STATUS_UNEXPECTED("PadEnd: Incorrect/Unknown datatype");
RETURN_STATUS_UNEXPECTED(
"PadEnd: Incorrect/Unknown datatype, supported datatype is: [bool, int8, uint8, int16, uint16, int32, uint32, "
"int64, uint64, float16, float32, float64].");
}
std::vector<dsize_t> cur_ind(src->Rank(), 0);
RETURN_IF_NOT_OK(PadEndNumericHelper(src, *dst, cur_ind, 0));
@ -535,7 +542,8 @@ Status MaskHelper(const std::shared_ptr<Tensor> &input, const std::shared_ptr<Te
*out_itr = (*in_itr <= value);
break;
default:
RETURN_STATUS_UNEXPECTED("Mask: unknown relational operator.");
RETURN_STATUS_UNEXPECTED(
"Mask: unknown relational operator, supported operator is: equal, notEqual, greater, less, lessEqual.");
}
}
return Status::OK();
@ -546,7 +554,8 @@ Status Mask(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *outpu
CHECK_FAIL_RETURN_UNEXPECTED(input->type().IsNumeric() == value->type().IsNumeric(),
"Mask: input datatype does not match the value datatype, both should be numeric or "
"non-numerical in the same time.");
CHECK_FAIL_RETURN_UNEXPECTED(value->shape() == TensorShape::CreateScalar(), "Mask: value shape is not a scalar");
CHECK_FAIL_RETURN_UNEXPECTED(value->shape() == TensorShape::CreateScalar(),
"Mask: value shape should be a scalar, got shape:" + value->shape().ToString());
RETURN_IF_NOT_OK(Tensor::CreateEmpty(input->shape(), DataType(DataType::DE_BOOL), output));
@ -599,7 +608,9 @@ Status Mask(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *outpu
RETURN_IF_NOT_OK(MaskHelper<std::string_view>(input, *output, casted_value, op));
break;
case DataType::DE_UNKNOWN:
RETURN_STATUS_UNEXPECTED("Mask: unsupported input datatype.");
RETURN_STATUS_UNEXPECTED(
"Mask: unsupported input datatype, support datatype is:[bool, int8, uint8, int16, uint16, int32, uint32, "
"int64, uint64, float16, float32, float64, string].");
break;
}
return Status::OK();
@ -609,7 +620,8 @@ Status Concatenate(const TensorRow &input, TensorRow *output, int8_t axis, std::
std::shared_ptr<Tensor> append) {
CHECK_FAIL_RETURN_UNEXPECTED(input.size() > 0, "Concatenate: input is null");
axis = Tensor::HandleNeg(axis, input[0]->shape().Rank());
CHECK_FAIL_RETURN_UNEXPECTED(axis == 0, "Concatenate: only 1D input supported, got rank: " + std::to_string(axis));
CHECK_FAIL_RETURN_UNEXPECTED(
axis == 0, "Concatenate: only 1D input supported, input 'axis' should be 0, but got: " + std::to_string(axis));
TensorShape t = TensorShape::CreateScalar();
@ -620,10 +632,11 @@ Status Concatenate(const TensorRow &input, TensorRow *output, int8_t axis, std::
if (prepend != nullptr) {
CHECK_FAIL_RETURN_UNEXPECTED(
first_dtype == prepend->type(),
"Concatenate: input datatype does not match the prepend datatype: " + prepend->type().ToString());
"Concatenate: input datatype does not match the prepend datatype, got input datatype: " + first_dtype.ToString() +
", prepend datatype:" + prepend->type().ToString());
CHECK_FAIL_RETURN_UNEXPECTED(
prepend->shape().Rank() == 1,
"Concatenate: only 1D input supported, got rank of input: " + std::to_string(prepend->shape().Rank()));
"Concatenate: only 1D input supported, got rank of prepend: " + std::to_string(prepend->shape().Rank()));
tensor_list.emplace_back(prepend);
}
@ -638,10 +651,11 @@ Status Concatenate(const TensorRow &input, TensorRow *output, int8_t axis, std::
if (append != nullptr) {
CHECK_FAIL_RETURN_UNEXPECTED(
first_dtype == append->type(),
"Concatenate: input datatype does not match the append datatype: " + append->type().ToString());
"Concatenate: input datatype does not match the append datatype, got input datatype: " + first_dtype.ToString() +
", append datatype:" + append->type().ToString());
CHECK_FAIL_RETURN_UNEXPECTED(
append->shape().Rank() == 1,
"Concatenate: only 1D append supported, got rank of input: " + std::to_string(append->shape().Rank()));
"Concatenate: only 1D append supported, got rank of append:" + std::to_string(append->shape().Rank()));
tensor_list.emplace_back(append);
}

View File

@ -24,9 +24,9 @@ namespace dataset {
Status DuplicateOp::Compute(const TensorRow &input, TensorRow *output) {
IO_CHECK_VECTOR(input, output);
CHECK_FAIL_RETURN_UNEXPECTED(
input.size() == 1,
"Duplicate: only supports transform one column each time, got column num: " + std::to_string(input.size()));
CHECK_FAIL_RETURN_UNEXPECTED(input.size() == 1,
"Duplicate: only supports transform one column each time, got column num: " +
std::to_string(input.size()) + ", check 'input_columns' when call this operator.");
std::shared_ptr<Tensor> out;
RETURN_IF_NOT_OK(Tensor::CreateFromTensor(input[0], &out));
output->push_back(input[0]);

View File

@ -85,10 +85,10 @@ Status RandomChoiceOp::Compute(const TensorRow &input, TensorRow *output) {
RandomChoiceOp::RandomChoiceOp(const std::vector<std::shared_ptr<TensorOp>> &ops)
: ops_(ops), gen_(GetSeed()), rand_int_(0, ops.size() - 1) {
if (ops_.empty()) {
MS_LOG(ERROR) << "op_list in RandomChoiceOp is empty.";
MS_LOG(ERROR) << "input 'transforms'(op_list) in RandomChoiceOp is empty.";
}
if (ops_.size() == 1) {
MS_LOG(WARNING) << "op_list has only 1 op, this op would be picked every time.";
MS_LOG(WARNING) << "input 'transforms'(op_list) has only 1 op, this op would be picked every time.";
}
is_deterministic_ = false;
}

View File

@ -44,9 +44,11 @@ Status DecodeOp::Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr<T
if (is_rgb_format_) { // RGB colour mode
return Decode(input, output);
} else { // BGR colour mode
RETURN_STATUS_UNEXPECTED("Decode: only support Decoded into RGB image, check input parameter first.");
RETURN_STATUS_UNEXPECTED(
"Decode: only support Decoded into RGB image, check input parameter 'rgb' first, its value should be 'True'.");
}
}
Status DecodeOp::OutputShape(const std::vector<TensorShape> &inputs, std::vector<TensorShape> &outputs) {
RETURN_IF_NOT_OK(TensorOp::OutputShape(inputs, outputs));
outputs.clear();

View File

@ -156,7 +156,7 @@ Status Resize(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *out
return Status(StatusCode::kMDShapeMisMatch, err_msg);
}
if (output_height == 0 || output_width == 0) {
std::string err_msg = "Resize: the resizing width or height is invalid, width or height is zero.";
std::string err_msg = "Resize: the input value of 'resize' is invalid, width or height is zero.";
return Status(StatusCode::kMDShapeMisMatch, err_msg);
}
@ -378,15 +378,20 @@ Status JpegCropAndDecode(const std::shared_ptr<Tensor> &input, std::shared_ptr<T
return DestroyDecompressAndReturnError(e.what());
}
CHECK_FAIL_RETURN_UNEXPECTED((std::numeric_limits<int32_t>::max() - crop_w) > crop_x,
"JpegCropAndDecode: addition(crop x and crop width) out of bounds.");
"JpegCropAndDecode: addition(crop x and crop width) out of bounds, got crop x:" +
std::to_string(crop_x) + ", and crop width:" + std::to_string(crop_w));
CHECK_FAIL_RETURN_UNEXPECTED((std::numeric_limits<int32_t>::max() - crop_h) > crop_y,
"JpegCropAndDecode: addition(crop y and crop height) out of bounds.");
"JpegCropAndDecode: addition(crop y and crop height) out of bounds, got crop y:" +
std::to_string(crop_y) + ", and crop height:" + std::to_string(crop_h));
if (crop_x == 0 && crop_y == 0 && crop_w == 0 && crop_h == 0) {
crop_w = cinfo.output_width;
crop_h = cinfo.output_height;
} else if (crop_w == 0 || static_cast<unsigned int>(crop_w + crop_x) > cinfo.output_width || crop_h == 0 ||
static_cast<unsigned int>(crop_h + crop_y) > cinfo.output_height) {
return DestroyDecompressAndReturnError("Crop: invalid crop size.");
return DestroyDecompressAndReturnError(
"Crop: invalid crop size, corresponding crop value equal to 0 or too big, got crop width: " +
std::to_string(crop_w) + ", crop height:" + std::to_string(crop_h) +
", and crop x coordinate:" + std::to_string(crop_x) + ", crop y coordinate:" + std::to_string(crop_y));
}
const int mcu_size = cinfo.min_DCT_scaled_size;
CHECK_FAIL_RETURN_UNEXPECTED(mcu_size != 0, "JpegCropAndDecode: divisor mcu_size is zero.");
@ -450,7 +455,8 @@ Status Crop(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *outpu
}
RETURN_IF_NOT_OK(ValidateImageRank("Crop", input_cv->Rank()));
CHECK_FAIL_RETURN_UNEXPECTED((std::numeric_limits<int32_t>::max() - y) > h,
"Crop: addition(x and height) out of bounds.");
"Crop: addition(x and height) out of bounds, got height:" + std::to_string(h) +
", and coordinate y:" + std::to_string(y));
// account for integer overflow
if (y < 0 || (y + h) > input_cv->shape()[0] || (y + h) < 0) {
RETURN_STATUS_UNEXPECTED(
@ -525,7 +531,9 @@ Status HwcToChw(std::shared_ptr<Tensor> input, std::shared_ptr<Tensor> *output)
*output = input;
return Status::OK();
}
CHECK_FAIL_RETURN_UNEXPECTED(input_cv->shape().Size() > CHANNEL_INDEX, "HWC2CHW: invalid shape.");
CHECK_FAIL_RETURN_UNEXPECTED(input_cv->shape().Size() > CHANNEL_INDEX,
"HWC2CHW: rank of input data should be greater than:" + std::to_string(CHANNEL_INDEX) +
", but got:" + std::to_string(input_cv->shape().Size()));
int num_channels = input_cv->shape()[CHANNEL_INDEX];
if (input_cv->shape().Size() < MIN_IMAGE_DIMENSION || input_cv->shape().Size() > DEFAULT_IMAGE_CHANNELS ||
(input_cv->shape().Size() == DEFAULT_IMAGE_CHANNELS && num_channels != DEFAULT_IMAGE_CHANNELS &&
@ -558,12 +566,14 @@ Status MaskWithTensor(const std::shared_ptr<Tensor> &sub_mat, std::shared_ptr<Te
if (CheckTensorShape(*input, 2)) {
RETURN_STATUS_UNEXPECTED(
"CutMixBatch: MaskWithTensor failed: "
"input shape doesn't match <H,W,C> format.");
"input shape doesn't match <H,W,C> format, got shape:" +
(*input)->shape().ToString());
}
if (CheckTensorShape(sub_mat, 2)) {
RETURN_STATUS_UNEXPECTED(
"CutMixBatch: MaskWithTensor failed: "
"sub_mat shape doesn't match <H,W,C> format.");
"sub_mat shape doesn't match <H,W,C> format, got shape:" +
(*input)->shape().ToString());
}
int number_of_channels = (*input)->shape()[CHANNEL_INDEX];
for (int i = 0; i < crop_width; i++) {
@ -577,12 +587,14 @@ Status MaskWithTensor(const std::shared_ptr<Tensor> &sub_mat, std::shared_ptr<Te
if (CheckTensorShape(*input, 0)) {
RETURN_STATUS_UNEXPECTED(
"CutMixBatch: MaskWithTensor failed: "
"input shape doesn't match <C,H,W> format.");
"input shape doesn't match <C,H,W> format, got shape:" +
(*input)->shape().ToString());
}
if (CheckTensorShape(sub_mat, 0)) {
RETURN_STATUS_UNEXPECTED(
"CutMixBatch: MaskWithTensor failed: "
"sub_mat shape doesn't match <C,H,W> format.");
"sub_mat shape doesn't match <C,H,W> format, got shape:" +
(*input)->shape().ToString());
}
int number_of_channels = (*input)->shape()[0];
for (int i = 0; i < crop_width; i++) {
@ -596,12 +608,14 @@ Status MaskWithTensor(const std::shared_ptr<Tensor> &sub_mat, std::shared_ptr<Te
if ((*input)->Rank() != MIN_IMAGE_DIMENSION) {
RETURN_STATUS_UNEXPECTED(
"CutMixBatch: MaskWithTensor failed: "
"input shape doesn't match <H,W> format.");
"input shape doesn't match <H,W> format, got shape:" +
(*input)->shape().ToString());
}
if (sub_mat->Rank() != MIN_IMAGE_DIMENSION) {
RETURN_STATUS_UNEXPECTED(
"CutMixBatch: MaskWithTensor failed: "
"sub_mat shape doesn't match <H,W> format.");
"sub_mat shape doesn't match <H,W> format, got shape:" +
(*input)->shape().ToString());
}
for (int i = 0; i < crop_width; i++) {
for (int j = 0; j < crop_height; j++) {
@ -611,7 +625,8 @@ Status MaskWithTensor(const std::shared_ptr<Tensor> &sub_mat, std::shared_ptr<Te
} else {
RETURN_STATUS_UNEXPECTED(
"CutMixBatch: MaskWithTensor failed: "
"image format must be <C,H,W>, <H,W,C>, or <H,W>.");
"image format must be <C,H,W>, <H,W,C>, or <H,W>, got shape:" +
(*input)->shape().ToString());
}
return Status::OK();
}
@ -641,10 +656,14 @@ Status CopyTensorValue(const std::shared_ptr<Tensor> &source_tensor, std::shared
Status SwapRedAndBlue(std::shared_ptr<Tensor> input, std::shared_ptr<Tensor> *output) {
try {
std::shared_ptr<CVTensor> input_cv = CVTensor::AsCVTensor(std::move(input));
CHECK_FAIL_RETURN_UNEXPECTED(input_cv->shape().Size() > CHANNEL_INDEX, "SwapRedAndBlue: shape is invalid.");
CHECK_FAIL_RETURN_UNEXPECTED(
input_cv->shape().Size() > CHANNEL_INDEX,
"SwapRedAndBlue: rank of input is should greater than:" + std::to_string(CHANNEL_INDEX) +
", but got:" + std::to_string(input_cv->shape().Size()));
int num_channels = input_cv->shape()[CHANNEL_INDEX];
if (input_cv->shape().Size() != 3 || num_channels != DEFAULT_IMAGE_CHANNELS) {
RETURN_STATUS_UNEXPECTED("SwapRedBlue: image shape is not <H,W,C>.");
RETURN_STATUS_UNEXPECTED("SwapRedBlue: image shape should be in <H,W,C> format, but got:" +
input_cv->shape().ToString());
}
std::shared_ptr<CVTensor> output_cv;
RETURN_IF_NOT_OK(CVTensor::CreateEmpty(input_cv->shape(), input_cv->type(), &output_cv));
@ -724,7 +743,9 @@ Status Rotate(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *out
cv::Mat input_img = input_cv->mat();
if (input_img.cols > (MAX_INT_PRECISION * 2) || input_img.rows > (MAX_INT_PRECISION * 2)) {
RETURN_STATUS_UNEXPECTED("Rotate: image is too large and center is not precise.");
RETURN_STATUS_UNEXPECTED("Rotate: image is too large and center is not precise, got image width:" +
std::to_string(input_img.cols) + ", and image height:" + std::to_string(input_img.rows) +
", both should be small than:" + std::to_string(MAX_INT_PRECISION * 2));
}
float fx = 0, fy = 0;
if (center.empty()) {
@ -791,7 +812,9 @@ Status Normalize(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *
RETURN_IF_NOT_OK((*output)->ExpandDim(MIN_IMAGE_DIMENSION));
}
CHECK_FAIL_RETURN_UNEXPECTED((*output)->Rank() == DEFAULT_IMAGE_RANK, "Normalize: image shape is not <H,W,C>.");
CHECK_FAIL_RETURN_UNEXPECTED((*output)->Rank() == DEFAULT_IMAGE_RANK,
"Normalize: output image rank should be:" + std::to_string(DEFAULT_IMAGE_RANK) +
", but got:" + std::to_string((*output)->Rank()));
CHECK_FAIL_RETURN_UNEXPECTED(std.size() == mean.size(),
"Normalize: mean and std vectors are not of same size, got size of std:" +
std::to_string(std.size()) + ", and mean size:" + std::to_string(mean.size()));
@ -948,7 +971,7 @@ Status AdjustContrast(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tens
RETURN_STATUS_UNEXPECTED("[Internal ERROR] AdjustContrast: load image failed.");
}
CHECK_FAIL_RETURN_UNEXPECTED(input_cv->shape().Size() > CHANNEL_INDEX,
"AdjustContrast: image rank should not bigger than:" + std::to_string(CHANNEL_INDEX) +
"AdjustContrast: image rank should bigger than:" + std::to_string(CHANNEL_INDEX) +
", but got: " + std::to_string(input_cv->shape().Size()));
int num_channels = input_cv->shape()[CHANNEL_INDEX];
if (input_cv->Rank() != DEFAULT_IMAGE_CHANNELS || num_channels != DEFAULT_IMAGE_CHANNELS) {
@ -976,7 +999,8 @@ Status AdjustGamma(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor>
try {
int num_channels = 1;
if (input->Rank() < 2) {
RETURN_STATUS_UNEXPECTED("AdjustGamma: input tensor is not in shape of <...,H,W,C> or <H,W>.");
RETURN_STATUS_UNEXPECTED("AdjustGamma: input tensor is not in shape of <...,H,W,C> or <H,W>, got shape:" +
input->shape().ToString());
}
if (input->Rank() > 2) {
num_channels = input->shape()[-1];
@ -1037,7 +1061,7 @@ Status AutoContrast(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor
RETURN_STATUS_UNEXPECTED("[Internal ERROR] AutoContrast: load image failed.");
}
if (input_cv->Rank() != DEFAULT_IMAGE_RANK && input_cv->Rank() != MIN_IMAGE_DIMENSION) {
RETURN_STATUS_UNEXPECTED("AutoContrast: image channel should be 1 or 3, but got: " +
RETURN_STATUS_UNEXPECTED("AutoContrast: image rank should be 2 or 3, but got: " +
std::to_string(input_cv->Rank()));
}
// Reshape to extend dimension if rank is 2 for algorithm to work. then reshape output to be of rank 2 like input
@ -1400,7 +1424,7 @@ Status RgbaToBgr(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *
try {
std::shared_ptr<CVTensor> input_cv = CVTensor::AsCVTensor(std::move(input));
int num_channels = input_cv->shape()[CHANNEL_INDEX];
if (input_cv->shape().Size() != DEFAULT_IMAGE_CHANNELS || num_channels != 4) {
if (input_cv->shape().Size() != DEFAULT_IMAGE_CHANNELS || num_channels != MAX_IMAGE_CHANNELS) {
std::string err_msg = "RgbaToBgr: rank of image is not: " + std::to_string(DEFAULT_IMAGE_CHANNELS) +
", but got: " + std::to_string(input_cv->shape().Size()) +
", or channels of image should be 4, but got: " + std::to_string(num_channels);
@ -1424,7 +1448,7 @@ Status RgbToBgr(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *o
if (!input_cv->mat().data) {
RETURN_STATUS_UNEXPECTED("[Internal ERROR] RgbToBgr: load image failed.");
}
if (input_cv->Rank() != 3 || input_cv->shape()[2] != 3) {
if (input_cv->Rank() != DEFAULT_IMAGE_RANK || input_cv->shape()[2] != DEFAULT_IMAGE_CHANNELS) {
RETURN_STATUS_UNEXPECTED("RgbToBgr: input tensor is not in shape of <H,W,C> or channel is not 3, got rank: " +
std::to_string(input_cv->Rank()) +
", and channel: " + std::to_string(input_cv->shape()[2]));

View File

@ -83,7 +83,7 @@ Status MixUpBatchOp::ComputeLabels(const TensorRow &input, std::shared_ptr<Tenso
Status MixUpBatchOp::Compute(const TensorRow &input, TensorRow *output) {
if (input.size() < 2) {
RETURN_STATUS_UNEXPECTED("MixUpBatch: size of input data should be 2 (including images or labels), but got: " +
std::to_string(input.size()));
std::to_string(input.size()) + ", check 'input_columns' when call this operator.");
}
std::vector<std::shared_ptr<CVTensor>> images;
@ -112,7 +112,8 @@ Status MixUpBatchOp::Compute(const TensorRow &input, TensorRow *output) {
}
if ((image_shape[dimension_one] != value_one && image_shape[dimension_one] != value_three) &&
(image_shape[dimension_three] != value_one && image_shape[dimension_three] != value_three)) {
RETURN_STATUS_UNEXPECTED("MixUpBatch: images shape is not <H,W,C> or <C,H,W>.");
RETURN_STATUS_UNEXPECTED("MixUpBatch: images shape should in <N,H,W,C> or <N,C,H,W>, got shape:" +
input.at(0)->shape().ToString());
}
// Move images into a vector of CVTensors

View File

@ -55,7 +55,8 @@ Status RandomCropAndResizeOp::Compute(const TensorRow &input, TensorRow *output)
RETURN_STATUS_UNEXPECTED(err_msg);
}
if (input[i]->shape()[0] != input[i + 1]->shape()[0] || input[i]->shape()[1] != input[i + 1]->shape()[1]) {
RETURN_STATUS_UNEXPECTED("RandomCropAndResizeOp: Input images must have the same size.");
RETURN_STATUS_UNEXPECTED(
"RandomCropAndResizeOp: Input images in different column of each row must have the same size.");
}
}
}
@ -100,9 +101,11 @@ Status RandomCropAndResizeOp::GetCropBox(int h_in, int w_in, int *x, int *y, int
CHECK_FAIL_RETURN_UNEXPECTED(crop_width != nullptr, "crop_width is nullptr.");
*crop_width = w_in;
*crop_height = h_in;
CHECK_FAIL_RETURN_UNEXPECTED(w_in != 0, "RandomCropAndResize: Width cannot be 0.");
CHECK_FAIL_RETURN_UNEXPECTED(h_in != 0, "RandomCropAndResize: Height cannot be 0.");
CHECK_FAIL_RETURN_UNEXPECTED(aspect_lb_ > 0, "RandomCropAndResize: aspect lower bound must be greater than zero.");
CHECK_FAIL_RETURN_UNEXPECTED(w_in != 0, "RandomCropAndResize: Width of input cannot be 0.");
CHECK_FAIL_RETURN_UNEXPECTED(h_in != 0, "RandomCropAndResize: Height of input cannot be 0.");
CHECK_FAIL_RETURN_UNEXPECTED(
aspect_lb_ > 0,
"RandomCropAndResize: 'ratio'(aspect) lower bound must be greater than 0, but got:" + std::to_string(aspect_lb_));
for (int32_t i = 0; i < max_iter_; i++) {
double const sample_scale = rnd_scale_(rnd_);
// In case of non-symmetrical aspect ratios, use uniform distribution on a logarithmic sample_scale.

View File

@ -128,7 +128,9 @@ Status RandomCropOp::Compute(const TensorRow &input, TensorRow *output) {
RETURN_STATUS_UNEXPECTED(err_msg);
}
if (input[i]->shape()[0] != input[i + 1]->shape()[0] || input[i]->shape()[1] != input[i + 1]->shape()[1]) {
RETURN_STATUS_UNEXPECTED("RandomCropOp: Input images must have the same size.");
RETURN_STATUS_UNEXPECTED(
"RandomCropOp: Input images in different column must have the same shape, check the output shape in "
"specified 'input_columns' before call this operation.");
}
}
}

View File

@ -89,7 +89,7 @@ Status RandomSelectSubpolicyOp::OutputType(const std::vector<DataType> &inputs,
RandomSelectSubpolicyOp::RandomSelectSubpolicyOp(const std::vector<Subpolicy> &policy)
: gen_(GetSeed()), policy_(policy), rand_int_(0, policy.size() - 1), rand_double_(0, 1) {
if (policy_.empty()) {
MS_LOG(ERROR) << "RandomSelectSubpolicy: policy in RandomSelectSubpolicyOp is empty.";
MS_LOG(ERROR) << "RandomSelectSubpolicy: input 'policy' in RandomSelectSubpolicy is empty, check input parameter.";
}
is_deterministic_ = false;
}

View File

@ -29,14 +29,18 @@ SlicePatchesOp::SlicePatchesOp(int32_t num_height, int32_t num_width, SliceMode
Status SlicePatchesOp::Compute(const TensorRow &input, TensorRow *output) {
IO_CHECK_VECTOR(input, output);
CHECK_FAIL_RETURN_UNEXPECTED(input.size() == 1, "Input tensor size should be 1.");
CHECK_FAIL_RETURN_UNEXPECTED(
input.size() == 1,
"size of input should be 1, which means 'input_columns' should be 1 when call this operator, but got:" +
std::to_string(input.size()));
auto in_tensor = input[0];
auto in_type = in_tensor->type();
auto in_shape = in_tensor->shape();
CHECK_FAIL_RETURN_UNEXPECTED(in_type.IsNumeric(), "Input Tensor type should be numeric.");
CHECK_FAIL_RETURN_UNEXPECTED(in_shape.Rank() >= 2, "Input Tensor rank should be greater than 2.");
CHECK_FAIL_RETURN_UNEXPECTED(in_type.IsNumeric(), "Input Tensor type should be numeric, got type is non-numeric.");
CHECK_FAIL_RETURN_UNEXPECTED(
in_shape.Rank() >= 2, "Rank of input data should be greater than 2, but got:" + std::to_string(in_shape.Rank()));
std::vector<std::shared_ptr<Tensor>> out;
RETURN_IF_NOT_OK(SlicePatches(in_tensor, &out, num_height_, num_width_, slice_mode_, fill_value_));

View File

@ -29,8 +29,10 @@ Status SolarizeOp::Compute(const std::shared_ptr<Tensor> &input, std::shared_ptr
uint8_t threshold_min_ = threshold_[0], threshold_max_ = threshold_[1];
CHECK_FAIL_RETURN_UNEXPECTED(threshold_min_ <= threshold_max_,
"Solarize: threshold_min must be smaller or equal to threshold_max.");
CHECK_FAIL_RETURN_UNEXPECTED(
threshold_min_ <= threshold_max_,
"Solarize: threshold[0] must be smaller or equal to threshold[1], got 'threshold' value: (" +
std::to_string(threshold_min_) + "," + std::to_string(threshold_max_) + ").");
try {
std::shared_ptr<CVTensor> input_cv = CVTensor::AsCVTensor(input);

View File

@ -83,18 +83,21 @@ ConcatenateOperation::ConcatenateOperation(int8_t axis, const std::shared_ptr<Te
Status ConcatenateOperation::ValidateParams() {
if (axis_ != 0 && axis_ != -1) {
std::string err_msg = "Concatenate: Only 1D concatenation supported.";
std::string err_msg =
"Concatenate: Only 1D concatenation supported, input 'axis' should be 0 or -1, but got:" + std::to_string(axis_);
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if (prepend_) {
if (prepend_->shape().Size() != 1) {
std::string err_msg = "Concatenate: Can only prepend 1D arrays.";
std::string err_msg = "Concatenate: Can only prepend 1D arrays, rank of input 'prepend' should be 1, but got:" +
std::to_string(prepend_->shape().Size());
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
}
if (append_) {
if (append_->shape().Size() != 1) {
std::string err_msg = "Concatenate: Can only append 1D arrays.";
std::string err_msg = "Concatenate: Can only append 1D arrays, rank of input 'append' should be 1, but got:" +
std::to_string(append_->shape().Size());
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
}
@ -118,7 +121,7 @@ FillOperation::FillOperation(const std::shared_ptr<Tensor> &fill_value) : fill_v
Status FillOperation::ValidateParams() {
if (fill_value_->shape() != TensorShape::CreateScalar()) {
std::string err_msg = "Fill: fill_value is not a scalar tensor.";
std::string err_msg = "Fill: fill_value is not a scalar tensor, got shape:" + fill_value_->shape().ToString();
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
@ -145,7 +148,8 @@ MaskOperation::MaskOperation(RelationalOp op, const std::shared_ptr<Tensor> &con
Status MaskOperation::ValidateParams() {
if (!dtype_.IsBool() && !dtype_.IsFloat() && !dtype_.IsInt()) {
std::string err_msg = "Mask: Only supports bool or numeric datatype for generated mask type.";
std::string err_msg =
"Mask: Only supports bool or numeric datatype for generated mask type, but got:" + dtype_.ToString();
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
return Status::OK();

View File

@ -44,7 +44,7 @@ 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());
std::string err_msg = op_name + ": expecting range size 1 or 2, but got: " + std::to_string(range.size());
MS_LOG(ERROR) << err_msg;
return Status(StatusCode::kMDSyntaxError, __LINE__, __FILE__, err_msg);
}

View File

@ -38,7 +38,7 @@ std::string AutoContrastOperation::Name() const { return kAutoContrastOperation;
Status AutoContrastOperation::ValidateParams() {
if (cutoff_ < 0 || cutoff_ > 100) {
std::string err_msg = "AutoContrast: cutoff has to be between 0 and 100, got: " + std::to_string(cutoff_);
std::string err_msg = "AutoContrast: 'cutoff' has to be between 0 and 100, got: " + std::to_string(cutoff_);
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
@ -46,7 +46,7 @@ Status AutoContrastOperation::ValidateParams() {
for (uint32_t single_ignore : ignore_) {
if (single_ignore > kMaxIgnoreSize) {
std::string err_msg =
"AutoContrast: invalid size, ignore has to be between 0 and 255, got: " + std::to_string(single_ignore);
"AutoContrast: invalid size, 'ignore' has to be between 0 and 255, got: " + std::to_string(single_ignore);
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
}

View File

@ -37,7 +37,7 @@ Status CropOperation::ValidateParams() {
constexpr size_t size_two = 2;
if (coordinates_.size() != size_two) {
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.";
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
RETURN_IF_NOT_OK(ValidateVectorNonNegative("Crop", "coordinates", coordinates_));

View File

@ -67,12 +67,12 @@ Status RandomAffineOperation::ValidateParams() {
}
// Translate
if (translate_range_.size() != size_two && translate_range_.size() != size_four) {
std::string err_msg = "RandomAffine: translate_range expecting size 2 or 4, got: translate_range.size() = " +
std::string err_msg = "RandomAffine: 'translate'(translate_range) expecting size 2 or 4, got size: " +
std::to_string(translate_range_.size());
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if (translate_range_[dimension_zero] > translate_range_[dimension_one]) {
std::string err_msg = "RandomAffine: minimum of translate range on x is greater than maximum: min = " +
std::string err_msg = "RandomAffine: minimum of 'translate'(translate_range) on x is greater than maximum: min = " +
std::to_string(translate_range_[dimension_zero]) +
", max = " + std::to_string(translate_range_[dimension_one]);
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
@ -82,9 +82,10 @@ Status RandomAffineOperation::ValidateParams() {
RETURN_IF_NOT_OK(ValidateScalar("RandomAffine", "translate", translate_range_[dimension_one], {-1, 1}, false, false));
if (translate_range_.size() == size_four) {
if (translate_range_[dimension_two] > translate_range_[dimension_three]) {
std::string err_msg = "RandomAffine: minimum of translate range on y is greater than maximum: min = " +
std::to_string(translate_range_[dimension_two]) +
", max = " + std::to_string(translate_range_[dimension_three]);
std::string err_msg =
"RandomAffine: minimum of 'translate'(translate range) on y is greater than maximum: min = " +
std::to_string(translate_range_[dimension_two]) +
", max = " + std::to_string(translate_range_[dimension_three]);
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
RETURN_IF_NOT_OK(
@ -96,18 +97,18 @@ Status RandomAffineOperation::ValidateParams() {
RETURN_IF_NOT_OK(ValidateVectorScale("RandomAffine", scale_range_));
// Shear
if (shear_ranges_.size() != size_two && shear_ranges_.size() != size_four) {
std::string err_msg = "RandomAffine: shear_ranges expecting size 2 or 4, got: shear_ranges.size() = " +
std::to_string(shear_ranges_.size());
std::string err_msg =
"RandomAffine: 'shear'(shear_range) expecting size 2 or 4, got size:" + std::to_string(shear_ranges_.size());
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if (shear_ranges_[dimension_zero] > shear_ranges_[dimension_one]) {
std::string err_msg = "RandomAffine: minimum of horizontal shear range is greater than maximum: min = " +
std::string err_msg = "RandomAffine: minimum of horizontal 'shear'(shear_range) is greater than maximum: min = " +
std::to_string(shear_ranges_[dimension_zero]) +
", max = " + std::to_string(shear_ranges_[dimension_one]);
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if (shear_ranges_.size() == size_four && shear_ranges_[dimension_two] > shear_ranges_[dimension_three]) {
std::string err_msg = "RandomAffine: minimum of vertical shear range is greater than maximum: min = " +
std::string err_msg = "RandomAffine: minimum of vertical 'shear'(shear_range) is greater than maximum: min = " +
std::to_string(shear_ranges_[dimension_two]) +
", max = " + std::to_string(scale_range_[dimension_three]);
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);

View File

@ -39,14 +39,14 @@ std::string RandomColorOperation::Name() const { return kRandomColorOperation; }
Status RandomColorOperation::ValidateParams() {
if (t_lb_ < 0 || t_ub_ < 0) {
std::string err_msg =
"RandomColor: lower bound or upper bound must be greater than or equal to 0, got t_lb: " + std::to_string(t_lb_) +
", t_ub: " + std::to_string(t_ub_);
"RandomColor: lower bound or upper bound must be greater than or equal to 0, got 'degree'(t_lb): " +
std::to_string(t_lb_) + ", 'degree'(t_ub): " + std::to_string(t_ub_);
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
if (t_lb_ > t_ub_) {
std::string err_msg =
"RandomColor: lower bound must be less or equal to upper bound, got t_lb: " + std::to_string(t_lb_) +
", t_ub: " + std::to_string(t_ub_);
"RandomColor: lower bound must be less or equal to upper bound, got 'degree'(t_lb): " + std::to_string(t_lb_) +
", 'degree'(t_ub): " + std::to_string(t_ub_);
LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
return Status::OK();

View File

@ -26,7 +26,8 @@ Status PluginOp::PluginToTensorRow(const std::vector<plugin::Tensor> &in_row, Te
for (const auto &tensor : in_row) {
std::shared_ptr<Tensor> output;
DataType tp = DataType(tensor.type_);
CHECK_FAIL_RETURN_UNEXPECTED(tp.IsNumeric() && tp != DataType::DE_UNKNOWN, "Unsupported type: " + tensor.type_);
CHECK_FAIL_RETURN_UNEXPECTED(tp.IsNumeric() && tp != DataType::DE_UNKNOWN,
"Input datatype should be numeric, got Unsupported type: " + tensor.type_);
RETURN_IF_NOT_OK(Tensor::CreateFromMemory(TensorShape(tensor.shape_), tp, tensor.buffer_.data(), &output));
out_row->emplace_back(output);
}

View File

@ -93,7 +93,8 @@ ComputeReturn:
ShapeMisMatch:
ret = Status(StatusCode::kMDShapeMisMatch, __LINE__, __FILE__,
"PyFunc should return a numpy array or a numpy array tuple");
"PyFunc should return a numpy array or a numpy array tuple, check data type of return value in user "
"defined python function.");
goto ComputeReturn;
TimeoutError:

View File

@ -161,7 +161,7 @@ TEST_F(MindDataTestSolarizeOp, TestOp6) {
Status s = op->Compute(test_input_tensor, &test_output_tensor);
EXPECT_TRUE(s.IsError());
EXPECT_NE(s.ToString().find("Solarize: threshold_min must be smaller or equal to threshold_max."),
EXPECT_NE(s.ToString().find("Solarize: threshold[0] must be smaller or equal to threshold[1], got 'threshold' value"),
std::string::npos);
ASSERT_TRUE(s.StatusCode() == StatusCode::kMDUnexpectedError);
}