diff --git a/configs/face_detection/blazeface.yml b/configs/face_detection/blazeface.yml index c52478690b7aed89e5b62f14633dfd19172be9a3..d9701541a8dc914c1a140d71291fefc9e8f4b52e 100644 --- a/configs/face_detection/blazeface.yml +++ b/configs/face_detection/blazeface.yml @@ -96,11 +96,12 @@ EvalReader: - !DecodeImage to_rgb: true - !NormalizeBox {} - - !Permute {} - !NormalizeImage + is_channel_first: false is_scale: false - mean: [104, 117, 123] + mean: [123, 117, 104] std: [127.502231, 127.502231, 127.502231] + - !Permute {} batch_size: 1 TestReader: @@ -112,9 +113,10 @@ TestReader: sample_transforms: - !DecodeImage to_rgb: true - - !Permute {} - !NormalizeImage + is_channel_first: false is_scale: false - mean: [104, 117, 123] + mean: [123, 117, 104] std: [127.502231, 127.502231, 127.502231] + - !Permute {} batch_size: 1 diff --git a/configs/face_detection/blazeface_keypoint.yml b/configs/face_detection/blazeface_keypoint.yml index 07481f409833a69e5f9ec02d55027df1c6eb5e0b..5d6aa44497d124b2a3e43baee52a03f61903ce9d 100644 --- a/configs/face_detection/blazeface_keypoint.yml +++ b/configs/face_detection/blazeface_keypoint.yml @@ -104,11 +104,12 @@ EvalReader: - !DecodeImage to_rgb: true - !NormalizeBox {} - - !Permute {} - !NormalizeImage + is_channel_first: false is_scale: false - mean: [104, 117, 123] + mean: [123, 117, 104] std: [127.502231, 127.502231, 127.502231] + - !Permute {} batch_size: 1 TestReader: @@ -120,9 +121,10 @@ TestReader: sample_transforms: - !DecodeImage to_rgb: true - - !Permute {} - !NormalizeImage + is_channel_first: false is_scale: false - mean: [104, 117, 123] + mean: [123, 117, 104] std: [127.502231, 127.502231, 127.502231] + - !Permute {} batch_size: 1 diff --git a/configs/face_detection/blazeface_nas.yml b/configs/face_detection/blazeface_nas.yml index 5e0f81b23600fc4f62a8edc61f899223417ab462..c19a3a12bbff0e424e7ef93bde43ab9fe7aed47e 100644 --- a/configs/face_detection/blazeface_nas.yml +++ b/configs/face_detection/blazeface_nas.yml @@ -98,11 +98,12 @@ EvalReader: - !DecodeImage to_rgb: true - !NormalizeBox {} - - !Permute {} - !NormalizeImage + is_channel_first: false is_scale: false - mean: [104, 117, 123] + mean: [123, 117, 104] std: [127.502231, 127.502231, 127.502231] + - !Permute {} batch_size: 1 TestReader: @@ -114,9 +115,10 @@ TestReader: sample_transforms: - !DecodeImage to_rgb: true - - !Permute {} - !NormalizeImage + is_channel_first: false is_scale: false - mean: [104, 117, 123] + mean: [123, 117, 104] std: [127.502231, 127.502231, 127.502231] + - !Permute {} batch_size: 1 diff --git a/configs/face_detection/blazeface_nas_v2.yml b/configs/face_detection/blazeface_nas_v2.yml index f13c6c37a6e9799734bae6891b672ebd134d69e5..48593460b61be3333530b474c8852d8aff96bdc0 100644 --- a/configs/face_detection/blazeface_nas_v2.yml +++ b/configs/face_detection/blazeface_nas_v2.yml @@ -98,11 +98,12 @@ EvalReader: - !DecodeImage to_rgb: true - !NormalizeBox {} - - !Permute {} - !NormalizeImage + is_channel_first: false is_scale: false - mean: [104, 117, 123] + mean: [123, 117, 104] std: [127.502231, 127.502231, 127.502231] + - !Permute {} batch_size: 1 TestReader: @@ -114,9 +115,10 @@ TestReader: sample_transforms: - !DecodeImage to_rgb: true - - !Permute {} - !NormalizeImage + is_channel_first: false is_scale: false - mean: [104, 117, 123] + mean: [123, 117, 104] std: [127.502231, 127.502231, 127.502231] + - !Permute {} batch_size: 1 diff --git a/configs/face_detection/faceboxes.yml b/configs/face_detection/faceboxes.yml index 92b0a39b20132b5d53ef84da8e86fe07f3ae7948..c0e189e2340de6582d64de1605f3400e2a598634 100644 --- a/configs/face_detection/faceboxes.yml +++ b/configs/face_detection/faceboxes.yml @@ -97,11 +97,13 @@ EvalReader: sample_transforms: - !DecodeImage to_rgb: true - - !Permute {} + - !NormalizeBox {} - !NormalizeImage + is_channel_first: false is_scale: false - mean: [104, 117, 123] + mean: [123, 117, 104] std: [127.502231, 127.502231, 127.502231] + - !Permute {} TestReader: inputs_def: @@ -112,9 +114,10 @@ TestReader: sample_transforms: - !DecodeImage to_rgb: true - - !Permute {} - !NormalizeImage + is_channel_first: false is_scale: false - mean: [104, 117, 123] + mean: [123, 117, 104] std: [127.502231, 127.502231, 127.502231] + - !Permute {} batch_size: 1 diff --git a/configs/face_detection/faceboxes_lite.yml b/configs/face_detection/faceboxes_lite.yml index fd346eb1d071224dc639451f9d57699c18752084..dbda51021f48bf841f045d2ec5f8eda06bd8382b 100644 --- a/configs/face_detection/faceboxes_lite.yml +++ b/configs/face_detection/faceboxes_lite.yml @@ -98,11 +98,13 @@ EvalReader: - !DecodeImage to_rgb: true - !NormalizeBox {} - - !Permute {} - !NormalizeImage + is_channel_first: false is_scale: false - mean: [104, 117, 123] + mean: [123, 117, 104] std: [127.502231, 127.502231, 127.502231] + - !Permute {} + TestReader: inputs_def: @@ -113,9 +115,10 @@ TestReader: sample_transforms: - !DecodeImage to_rgb: true - - !Permute {} - !NormalizeImage + is_channel_first: false is_scale: false - mean: [104, 117, 123] + mean: [123, 117, 104] std: [127.502231, 127.502231, 127.502231] + - !Permute {} batch_size: 1 diff --git a/deploy/cpp/include/preprocess_op.h b/deploy/cpp/include/preprocess_op.h index af672ea817cbf1f664fc0cc7cea2976d3b05a1e1..1ec10061eaece8ab47cb2520701f3edf4bc057db 100644 --- a/deploy/cpp/include/preprocess_op.h +++ b/deploy/cpp/include/preprocess_op.h @@ -50,6 +50,12 @@ class PreprocessOp { virtual void Run(cv::Mat* im, ImageBlob* data) = 0; }; +class InitInfo : public PreprocessOp{ + public: + virtual void Init(const YAML::Node& item, const std::string& arch) {} + virtual void Run(cv::Mat* im, ImageBlob* data); +}; + class Normalize : public PreprocessOp { public: virtual void Init(const YAML::Node& item, const std::string& arch) { @@ -127,6 +133,8 @@ class Preprocessor { public: void Init(const YAML::Node& config_node, const std::string& arch) { arch_ = arch; + // initialize image info at first + ops_["InitInfo"] = std::make_shared(); for (const auto& item : config_node) { auto op_name = item["type"].as(); ops_[op_name] = CreateOp(op_name); diff --git a/deploy/cpp/src/preprocess_op.cc b/deploy/cpp/src/preprocess_op.cc index f572bac74039767a8a79747dab67ea504bd1d273..cec3feb7a11c3b1e6de0aef24ae3eba0037b8152 100644 --- a/deploy/cpp/src/preprocess_op.cc +++ b/deploy/cpp/src/preprocess_op.cc @@ -19,6 +19,24 @@ namespace PaddleDetection { +void InitInfo::Run(cv::Mat* im, ImageBlob* data) { + data->ori_im_size_ = { + static_cast(im->rows), + static_cast(im->cols) + }; + data->ori_im_size_f_ = { + static_cast(im->rows), + static_cast(im->cols), + 1.0 + }; + data->eval_im_size_f_ = { + static_cast(im->rows), + static_cast(im->cols), + 1.0 + }; + data->scale_factor_f_ = {1., 1., 1., 1.}; +} + void Normalize::Run(cv::Mat* im, ImageBlob* data) { double e = 1.0; if (is_scale_) { @@ -44,20 +62,12 @@ void Permute::Run(cv::Mat* im, ImageBlob* data) { (data->im_data_).resize(rc * rh * rw); float* base = (data->im_data_).data(); for (int i = 0; i < rc; ++i) { - cv::extractChannel(*im, cv::Mat(rh, rw, CV_32FC1, base + i * rh * rw), i); + int cur_c = to_bgr_ ? rc - i - 1 : i; + cv::extractChannel(*im, cv::Mat(rh, rw, CV_32FC1, base + cur_c * rh * rw), i); } } void Resize::Run(cv::Mat* im, ImageBlob* data) { - data->ori_im_size_ = { - static_cast(im->rows), - static_cast(im->cols) - }; - data->ori_im_size_f_ = { - static_cast(im->rows), - static_cast(im->cols), - 1.0 - }; auto resize_scale = GenerateScale(*im); cv::resize( *im, *im, cv::Size(), resize_scale.first, resize_scale.second, interp_); @@ -137,7 +147,7 @@ void PadStride::Run(cv::Mat* im, ImageBlob* data) { // Preprocessor op running order const std::vector Preprocessor::RUN_ORDER = { - "Resize", "Normalize", "PadStride", "Permute" + "InitInfo", "Resize", "Normalize", "PadStride", "Permute" }; void Preprocessor::Run(cv::Mat* im, ImageBlob* data) {