From 04da5bae5d527236a1e717c7389f7aadc689de47 Mon Sep 17 00:00:00 2001 From: Zhenglong Li Date: Fri, 18 Dec 2020 16:46:21 +0800 Subject: [PATCH] Fix dvpp parameter validation bug and make information clear, besides, modify Dvpp ut. --- .../ccsrc/minddata/dataset/api/vision.cc | 27 +++++++++++++++---- .../kernels/image/dvpp/utils/DvppCommon.cc | 4 +-- tests/cxx_st/dataset/test_de.cc | 13 ++++++--- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/api/vision.cc b/mindspore/ccsrc/minddata/dataset/api/vision.cc index afffb47fa4..ac32a60a24 100644 --- a/mindspore/ccsrc/minddata/dataset/api/vision.cc +++ b/mindspore/ccsrc/minddata/dataset/api/vision.cc @@ -679,27 +679,42 @@ DvppDecodeResizeCropOperation::DvppDecodeResizeCropOperation(const std::vector 2) { - std::string err_msg = "DvppDecodeResizeCropJpeg: crop size must be a vector of one or two elements, got: " + + std::string err_msg = "DvppDecodeResizeCropJpeg: crop resolution must be a vector of one or two elements, got: " + std::to_string(crop_.size()); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } if (resize_.empty() || resize_.size() > 2) { - std::string err_msg = "DvppDecodeResizeCropJpeg: resize size must be a vector of one or two elements, got: " + + std::string err_msg = "DvppDecodeResizeCropJpeg: resize resolution must be a vector of one or two elements, got: " + std::to_string(resize_.size()); MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } + if (*min_element(crop_.begin(), crop_.end()) < 32 || *max_element(crop_begin(), crop_.end()) > 2048) { + std::string err_msg = "Dvpp module supports crop image with resolution in range [32, 2048], got Crop Parameters: "; + MS_LOG(ERROR) << err_msg << crop_; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } + if (*min_element(resize_.begin(), resize_.end()) < 32 || *max_element(resize_begin(), resize_.end()) > 2048) { + std::string err_msg = + "Dvpp module supports resize image with resolution in range [32, 2048], got Crop Parameters: "; + MS_LOG(ERROR) << err_msg << resize_; + RETURN_STATUS_SYNTAX_ERROR(err_msg); + } if (crop_.size() < resize_.size()) { if (crop_[0] > MIN(resize_[0], resize_[1])) { - std::string err_msg = "crop size must be smaller than resize size"; + std::string err_msg = + "Each value of crop parameter must be smaller than corresponding resize parameter, for example: x[0] <= " + "y[0], and x[1] <= y[1], please verify your input parameters."; MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } } if (crop_.size() > resize_.size()) { if (MAX(crop_[0], crop_[1]) > resize_[0]) { - std::string err_msg = "crop size must be smaller than resize size"; + std::string err_msg = + "Each value of crop parameter must be smaller than corresponding resize parameter, for example: x[0] <= " + "y[0], and x[1] <= y[1], please verify your input parameters."; MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } @@ -707,7 +722,9 @@ Status DvppDecodeResizeCropOperation::ValidateParams() { if (crop_.size() == resize_.size()) { for (int32_t i = 0; i < crop_.size(); ++i) { if (crop_[i] > resize_[i]) { - std::string err_msg = "crop size must be smaller than resize size"; + std::string err_msg = + "Each value of crop parameter must be smaller than corresponding resize parameter, for example: x[0] <= " + "y[0], and x[1] <= y[1], please verify your input parameters."; MS_LOG(ERROR) << err_msg; RETURN_STATUS_SYNTAX_ERROR(err_msg); } diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/dvpp/utils/DvppCommon.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/dvpp/utils/DvppCommon.cc index 76ad45628b..93d0e06936 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/dvpp/utils/DvppCommon.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/dvpp/utils/DvppCommon.cc @@ -380,12 +380,12 @@ APP_ERROR DvppCommon::CheckResizeParams(const DvppDataInfo &input, const DvppDat } if (((float)output.height / input.height) < MIN_RESIZE_SCALE || ((float)output.height / input.height) > MAX_RESIZE_SCALE) { - MS_LOG(ERROR) << "Resize scale should be in range [1/16, 32], which is " << (output.height / input.height) << "."; + MS_LOG(ERROR) << "Resize scale should be in range [1/16, 16], which is " << (output.height / input.height) << "."; return APP_ERR_COMM_INVALID_PARAM; } if (((float)output.width / input.width) < MIN_RESIZE_SCALE || ((float)output.width / input.width) > MAX_RESIZE_SCALE) { - MS_LOG(ERROR) << "Resize scale should be in range [1/16, 32], which is " << (output.width / input.width) << "."; + MS_LOG(ERROR) << "Resize scale should be in range [1/16, 16], which is " << (output.width / input.width) << "."; return APP_ERR_COMM_INVALID_PARAM; } return APP_ERR_OK; diff --git a/tests/cxx_st/dataset/test_de.cc b/tests/cxx_st/dataset/test_de.cc index 510324867e..506435961d 100644 --- a/tests/cxx_st/dataset/test_de.cc +++ b/tests/cxx_st/dataset/test_de.cc @@ -15,6 +15,7 @@ */ #include #include +#include #include "common/common_test.h" #include "include/api/types.h" #include "minddata/dataset/include/minddata_eager.h" @@ -72,13 +73,17 @@ TEST_F(TestDE, ResNetPreprocess) { TEST_F(TestDE, TestDvpp) { std::vector> images; MindDataEager::LoadImageFromDir("/root/Dvpp_Unit_Dev/val2014_test/", &images); - - MindDataEager Solo({DvppDecodeResizeCropJpeg({224, 224}, {256, 256})}); - + std::vector crop_size = {224, 224}; + std::vector resize_size = {256, 256}; + MindDataEager Solo({DvppDecodeResizeCropJpeg(crop_size, resize_size)}); for (auto &img : images) { img = Solo(img); ASSERT_EQ(images[0]->Shape().size(), 3); - ASSERT_EQ(images[0]->Shape()[0], 224 * 224 * 1.5); + if (crop_size.size() == 1) { + ASSERT_EQ(images[0]->Shape()[0], pow(crop_size[0], 2) 1.5); + } else { + ASSERT_EQ(images[0]->Shape()[0], crop_size[0] * crop_size[1] * 1.5); + } ASSERT_EQ(images[0]->Shape()[1], 1); ASSERT_EQ(images[0]->Shape()[2], 1); }