!12796 AIpp config file generator bug fix

From: @lizhenglong1992
Reviewed-by: @liucunwei,@heleiwang
Signed-off-by: @liucunwei
This commit is contained in:
mindspore-ci-bot 2021-03-03 15:04:02 +08:00 committed by Gitee
commit 4b7e76b4fb
3 changed files with 37 additions and 12 deletions

View File

@ -390,13 +390,21 @@ Status Execute::operator()(const std::vector<MSTensor> &input_tensor_list, std::
std::vector<uint32_t> AippSizeFilter(const std::vector<uint32_t> &resize_para, const std::vector<uint32_t> &crop_para) {
std::vector<uint32_t> aipp_size;
// Special condition where (no Crop and no Resize) or (no Crop and resize with fixed ratio) will lead to dynamic input
if ((resize_para.size() == 0 || resize_para.size() == 1) && crop_para.size() == 0) {
aipp_size = {0, 0};
MS_LOG(WARNING) << "Dynamic input shape is not supported, incomplete aipp config file will be generated. Please "
"checkout your TensorTransform input, both src_image_size_h and src_image_size will be 0";
return aipp_size;
}
if (resize_para.size() == 0) { // If only Crop operator exists
aipp_size = crop_para;
} else if (crop_para.size() == 0) { // If only Resize operator exists
} else if (crop_para.size() == 0) { // If only Resize operator with 2 parameters exists
aipp_size = resize_para;
} else { // If both of them exist
if (resize_para.size() == 1) {
aipp_size = *min_element(crop_para.begin(), crop_para.end()) < *resize_para.begin() ? crop_para : resize_para;
aipp_size = crop_para;
} else {
aipp_size =
*min_element(resize_para.begin(), resize_para.end()) < *min_element(crop_para.begin(), crop_para.end())
@ -440,7 +448,7 @@ Status AippInfoCollection(std::map<std::string, std::string> *aipp_options, cons
// Several aipp config parameters
aipp_options->insert(std::make_pair("related_input_rank", "0"));
aipp_options->insert(std::make_pair("src_image_size_w", std::to_string(aipp_size[1])));
aipp_options->insert(std::make_pair("src_image_size_h", std::to_string(aipp_size[1])));
aipp_options->insert(std::make_pair("src_image_size_h", std::to_string(aipp_size[0])));
aipp_options->insert(std::make_pair("crop", "false"));
aipp_options->insert(std::make_pair("input_format", "YUV420SP_U8"));
aipp_options->insert(std::make_pair("aipp_mode", "static"));
@ -526,19 +534,28 @@ std::string Execute::AippCfgGenerator() {
// Process resize parameters and crop parameters to find out the final size of input data
std::vector<uint32_t> resize_paras;
std::vector<uint32_t> crop_paras;
// Find resize parameters
auto iter = info_->aipp_cfg_.find(vision::kDvppResizeJpegOperation);
if (iter != info_->aipp_cfg_.end()) {
std::map<std::string, std::vector<uint32_t>>::iterator iter;
if (info_->aipp_cfg_.find(vision::kDvppResizeJpegOperation) != info_->aipp_cfg_.end()) {
iter = info_->aipp_cfg_.find(vision::kDvppResizeJpegOperation);
resize_paras = iter->second;
} else if (info_->aipp_cfg_.find(vision::kDvppDecodeResizeOperation) != info_->aipp_cfg_.end()) {
iter = info_->aipp_cfg_.find(vision::kDvppDecodeResizeOperation);
resize_paras = iter->second;
}
// Find crop parameters
if (info_->aipp_cfg_.find(vision::kDvppCropJpegOperation) != info_->aipp_cfg_.end()) {
iter = info_->aipp_cfg_.find(vision::kDvppCropJpegOperation);
if (iter != info_->aipp_cfg_.end()) {
crop_paras = iter->second;
} else if (info_->aipp_cfg_.find(vision::kDvppDecodeResizeCropOperation) != info_->aipp_cfg_.end()) {
iter = info_->aipp_cfg_.find(vision::kDvppDecodeResizeCropOperation);
crop_paras = iter->second;
}
if (crop_paras.size() == 1) {
crop_paras.emplace_back(crop_paras[0]);
}
}
std::vector<uint32_t> aipp_size = AippSizeFilter(resize_paras, crop_paras);

View File

@ -283,8 +283,14 @@ std::shared_ptr<TensorOp> DvppNormalizeOperation::Build() {
Status DvppNormalizeOperation::to_json(nlohmann::json *out_json) {
nlohmann::json args;
args["mean"] = mean_;
args["std"] = std_;
std::vector<uint32_t> enlarge_mean_;
std::vector<uint32_t> enlarge_std_;
std::transform(mean_.begin(), mean_.end(), std::back_inserter(enlarge_mean_),
[](float i) -> uint32_t { return static_cast<uint32_t>(10000 * i); });
std::transform(std_.begin(), std_.end(), std::back_inserter(enlarge_std_),
[](float j) -> uint32_t { return static_cast<uint32_t>(10000 * j); });
args["mean"] = enlarge_mean_;
args["std"] = enlarge_std_;
*out_json = args;
return Status::OK();
}

View File

@ -78,6 +78,8 @@ TEST_F(TestDE, TestDvpp) {
// Apply transform on images
Status rc = Transform(image, &image);
std::string aipp_cfg = Transform.AippCfgGenerator();
ASSERT_EQ(aipp_cfg, "./aipp.cfg");
// Check image info
ASSERT_TRUE(rc.IsOk());