!7729 [MD] Fix log of vision and dataset in C++ api

Merge pull request !7729 from luoyang/pylint
pull/7729/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit 0124eef185

@ -962,13 +962,14 @@ Status ValidateDatasetColumnParam(const std::string &dataset_name, const std::st
for (uint32_t i = 0; i < columns.size(); ++i) {
if (columns[i].empty()) {
std::string err_msg = dataset_name + ":" + column_param + "[" + std::to_string(i) + "] must not be empty";
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
}
std::set<std::string> columns_set(columns.begin(), columns.end());
if (columns_set.size() != columns.size()) {
// others";
std::string err_msg = dataset_name + ":" + column_param + ": Every column name should not be same with others";
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}
return Status::OK();

@ -63,9 +63,9 @@ std::shared_ptr<TypeCastOperation> TypeCast(std::string data_type) {
OneHotOperation::OneHotOperation(int32_t num_classes) : num_classes_(num_classes) {}
Status OneHotOperation::ValidateParams() {
if (num_classes_ < 0) {
if (num_classes_ <= 0) {
std::string err_msg =
"OneHot: Number of classes cannot be negative. Number of classes: " + std::to_string(num_classes_);
"OneHot: Number of classes must be greater than 0. num_classes: " + std::to_string(num_classes_);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_SYNTAX_ERROR(err_msg);
}

File diff suppressed because it is too large Load Diff

@ -75,8 +75,8 @@ std::shared_ptr<CenterCropOperation> CenterCrop(std::vector<int32_t> size);
std::shared_ptr<CropOperation> Crop(std::vector<int32_t> coordinates, std::vector<int32_t> size);
/// \brief Function to apply CutMix on a batch of images
/// \notes Masks a random section of each image with the corresponding part of another randomly selected image in
/// that batch
/// \notes Masks a random section of each image with the corresponding part of another randomly
/// selected image in that batch
/// \param[in] image_batch_format The format of the batch
/// \param[in] alpha The hyperparameter of beta distribution (default = 1.0)
/// \param[in] prob The probability by which CutMix is applied to each image (default = 1.0)
@ -103,8 +103,8 @@ std::shared_ptr<DecodeOperation> Decode(bool rgb = true);
std::shared_ptr<HwcToChwOperation> HWC2CHW();
/// \brief Function to create a MixUpBatch TensorOperation.
/// \notes Apply MixUp transformation on an input batch of images and labels. The labels must be in one-hot format and
/// Batch must be called before calling this function.
/// \notes Apply MixUp transformation on an input batch of images and labels. The labels must be in
/// one-hot format and Batch must be called before calling this function.
/// \param[in] alpha hyperparameter of beta distribution (default = 1.0)
/// \return Shared pointer to the current TensorOperation.
std::shared_ptr<MixUpBatchOperation> MixUpBatch(float alpha = 1);
@ -112,7 +112,9 @@ std::shared_ptr<MixUpBatchOperation> MixUpBatch(float alpha = 1);
/// \brief Function to create a Normalize TensorOperation.
/// \notes Normalize the input image with respect to mean and standard deviation.
/// \param[in] mean A vector of mean values for each channel, w.r.t channel order.
/// The mean values must be in range (0.0, 255.0].
/// \param[in] std A vector of standard deviations for each channel, w.r.t. channel order.
/// The standard deviation values must be in range (0.0, 255.0]
/// \return Shared pointer to the current TensorOperation.
std::shared_ptr<NormalizeOperation> Normalize(std::vector<float> mean, std::vector<float> std);
@ -146,8 +148,8 @@ std::shared_ptr<PadOperation> Pad(std::vector<int32_t> padding, std::vector<uint
/// if size is 4, (min_dx, max_dx, min_dy, max_dy)
/// all values are in range [-1, 1]
/// \param[in] scale_range A float vector of size 2, representing the starting and ending scales in the range.
/// \param[in] shear_ranges A float vector of size 2 or 4, representing the starting and ending shear degrees vertically
/// and horizontally.
/// \param[in] shear_ranges A float vector of size 2 or 4, representing the starting and ending shear degrees
/// vertically and horizontally.
/// if size is 2, (min_shear_x, max_shear_x, 0, 0)
/// if size is 4, (min_shear_x, max_shear_x, min_shear_y, max_shear_y)
/// \param[in] interpolation An enum for the mode of interpolation
@ -202,14 +204,14 @@ std::shared_ptr<RandomCropOperation> RandomCrop(std::vector<int32_t> size, std::
/// \brief Function to create a RandomCropDecodeResize TensorOperation.
/// \notes Equivalent to RandomResizedCrop, but crops before decodes.
/// \param[in] size - a vector representing the output size of the cropped image.
/// \param[in] size A vector representing the output size of the cropped image.
/// If size is a single value, a square crop of size (size, size) is returned.
/// If size has 2 values, it should be (height, width).
/// \param[in] scale - range [min, max) of respective size of the
/// \param[in] scale Range [min, max) of respective size of the
/// original size to be cropped (default=(0.08, 1.0))
/// \param[in] ratio - range [min, max) of aspect ratio to be
/// \param[in] ratio Range [min, max) of aspect ratio to be
/// cropped (default=(3. / 4., 4. / 3.))
/// \param[in] interpolation - an enum for the mode of interpolation
/// \param[in] interpolation An enum for the mode of interpolation
/// \param[in] The maximum number of attempts to propose a valid crop_area (default=10).
/// If exceeded, fall back to use center_crop instead.
/// \return Shared pointer to the current TensorOperation.
@ -266,14 +268,15 @@ std::shared_ptr<RandomRotationOperation> RandomRotation(
std::shared_ptr<RandomSharpnessOperation> RandomSharpness(std::vector<float> degrees = {0.1, 1.9});
/// \brief Function to create a RandomSolarize TensorOperation.
/// \notes Invert pixels within specified range. If min=max, then it inverts all pixel above that threshold
/// \notes Invert pixels randomly within specified range. If min=max, it is a single fixed magnitude operation
/// to inverts all pixel above that threshold
/// \param[in] threshold A vector with two elements specifying the pixel range to invert.
/// \return Shared pointer to the current TensorOperation.
std::shared_ptr<RandomSolarizeOperation> RandomSolarize(std::vector<uint8_t> threshold = {0, 255});
/// \brief Function to create a RandomVerticalFlip TensorOperation.
/// \notes Tensor operation to perform random vertical flip.
/// \param[in] prob - float representing the probability of flip.
/// \param[in] prob A float representing the probability of flip.
/// \return Shared pointer to the current TensorOperation.
std::shared_ptr<RandomVerticalFlipOperation> RandomVerticalFlip(float prob = 0.5);

@ -175,6 +175,18 @@ TEST_F(MindDataTestPipeline, TestOneHotSuccess2) {
iter->Stop();
}
TEST_F(MindDataTestPipeline, TestOneHotFail) {
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestOneHotFail with invalid params.";
// incorrect num_class
std::shared_ptr<TensorOperation> one_hot_op1 = transforms::OneHot(0);
EXPECT_EQ(one_hot_op1, nullptr);
// incorrect num_class
std::shared_ptr<TensorOperation> one_hot_op2 = transforms::OneHot(-5);
EXPECT_EQ(one_hot_op2, nullptr);
}
TEST_F(MindDataTestPipeline, TestTypeCastSuccess) {
MS_LOG(INFO) << "Doing MindDataTestPipeline-TestTypeCastSuccess.";

Loading…
Cancel
Save