未验证 提交 64a2a78e 编写于 作者: W wangguanzhong 提交者: GitHub

fix cpp inference without resize (#1073)

上级 c4219c27
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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<InitInfo>();
for (const auto& item : config_node) {
auto op_name = item["type"].as<std::string>();
ops_[op_name] = CreateOp(op_name);
......
......@@ -19,6 +19,24 @@
namespace PaddleDetection {
void InitInfo::Run(cv::Mat* im, ImageBlob* data) {
data->ori_im_size_ = {
static_cast<int>(im->rows),
static_cast<int>(im->cols)
};
data->ori_im_size_f_ = {
static_cast<float>(im->rows),
static_cast<float>(im->cols),
1.0
};
data->eval_im_size_f_ = {
static_cast<float>(im->rows),
static_cast<float>(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<int>(im->rows),
static_cast<int>(im->cols)
};
data->ori_im_size_f_ = {
static_cast<float>(im->rows),
static_cast<float>(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<std::string> Preprocessor::RUN_ORDER = {
"Resize", "Normalize", "PadStride", "Permute"
"InitInfo", "Resize", "Normalize", "PadStride", "Permute"
};
void Preprocessor::Run(cv::Mat* im, ImageBlob* data) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册