From 07dd752e1e8ad57d11e2df743935c5a5827ad748 Mon Sep 17 00:00:00 2001 From: Zhenglong Li Date: Tue, 2 Mar 2021 17:57:25 +0800 Subject: [PATCH] Fix aipp config file generator bug --- .../ccsrc/minddata/dataset/api/execute.cc | 37 ++++++++++++++----- .../kernels/ir/vision/ascend_vision_ir.cc | 10 ++++- tests/st/cpp/dataset/test_de.cc | 2 + 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/api/execute.cc b/mindspore/ccsrc/minddata/dataset/api/execute.cc index 03246b4496..55ce4c2c48 100644 --- a/mindspore/ccsrc/minddata/dataset/api/execute.cc +++ b/mindspore/ccsrc/minddata/dataset/api/execute.cc @@ -392,13 +392,21 @@ Status Execute::operator()(const std::vector &input_tensor_list, std:: std::vector AippSizeFilter(const std::vector &resize_para, const std::vector &crop_para) { std::vector 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()) @@ -442,7 +450,7 @@ Status AippInfoCollection(std::map *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")); @@ -528,18 +536,27 @@ std::string Execute::AippCfgGenerator() { // Process resize parameters and crop parameters to find out the final size of input data std::vector resize_paras; std::vector crop_paras; + // Find resize parameters - auto iter = info_->aipp_cfg_.find(vision::kDvppResizeJpegOperation); - if (iter != info_->aipp_cfg_.end()) { + std::map>::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 - iter = info_->aipp_cfg_.find(vision::kDvppCropJpegOperation); - if (iter != info_->aipp_cfg_.end()) { + if (info_->aipp_cfg_.find(vision::kDvppCropJpegOperation) != info_->aipp_cfg_.end()) { + iter = info_->aipp_cfg_.find(vision::kDvppCropJpegOperation); crop_paras = iter->second; - if (crop_paras.size() == 1) { - crop_paras.emplace_back(crop_paras[0]); - } + } 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 aipp_size = AippSizeFilter(resize_paras, crop_paras); diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/ascend_vision_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/ascend_vision_ir.cc index 12023063e7..77b71205f3 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/ascend_vision_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/ascend_vision_ir.cc @@ -283,8 +283,14 @@ std::shared_ptr DvppNormalizeOperation::Build() { Status DvppNormalizeOperation::to_json(nlohmann::json *out_json) { nlohmann::json args; - args["mean"] = mean_; - args["std"] = std_; + std::vector enlarge_mean_; + std::vector enlarge_std_; + std::transform(mean_.begin(), mean_.end(), std::back_inserter(enlarge_mean_), + [](float i) -> uint32_t { return static_cast(10000 * i); }); + std::transform(std_.begin(), std_.end(), std::back_inserter(enlarge_std_), + [](float j) -> uint32_t { return static_cast(10000 * j); }); + args["mean"] = enlarge_mean_; + args["std"] = enlarge_std_; *out_json = args; return Status::OK(); } diff --git a/tests/st/cpp/dataset/test_de.cc b/tests/st/cpp/dataset/test_de.cc index 994315b25b..c4b66f6889 100644 --- a/tests/st/cpp/dataset/test_de.cc +++ b/tests/st/cpp/dataset/test_de.cc @@ -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());