From: @lizhenglong1992
Reviewed-by: @pandoublefeng,@heleiwang,@liucunwei
Signed-off-by: @liucunwei
pull/10186/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit a177de60ff

@ -679,27 +679,42 @@ DvppDecodeResizeCropOperation::DvppDecodeResizeCropOperation(const std::vector<u
Status DvppDecodeResizeCropOperation::ValidateParams() {
// size
if (crop_.empty() || crop_.size() > 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);
}

@ -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;

@ -15,6 +15,7 @@
*/
#include <string>
#include <vector>
#include <cmath>
#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<std::shared_ptr<Tensor>> images;
MindDataEager::LoadImageFromDir("/root/Dvpp_Unit_Dev/val2014_test/", &images);
MindDataEager Solo({DvppDecodeResizeCropJpeg({224, 224}, {256, 256})});
std::vector<uint32_t> crop_size = {224, 224};
std::vector<uint32_t> 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);
}

Loading…
Cancel
Save