diff --git a/deploy/cpp/include/preprocess_op.h b/deploy/cpp/include/preprocess_op.h index 1e6c8844e8c25345cc60085e8bea87b256a9f9d9..bb2d0ca3eea6b58dc9ca064fb29cd3ea30acbb74 100644 --- a/deploy/cpp/include/preprocess_op.h +++ b/deploy/cpp/include/preprocess_op.h @@ -39,6 +39,8 @@ class ImageBlob { std::vector ori_im_size_f_; // Evaluation image width and height std::vector eval_im_size_f_; + // Scale factor for image size to origin image size + std::vector scale_factor_f_; }; // Abstraction of preprocessing opration class diff --git a/deploy/cpp/src/object_detector.cc b/deploy/cpp/src/object_detector.cc index 7b660127d9433714c65a52245f4bf38006d06720..c8aaedeb4dafa104a4227c24e46cc9d9d9176091 100644 --- a/deploy/cpp/src/object_detector.cc +++ b/deploy/cpp/src/object_detector.cc @@ -140,7 +140,7 @@ void ObjectDetector::Postprocess( int ymax = (output_data_[5 + j * 6] * rh); int wd = xmax - xmin; int hd = ymax - ymin; - if (score > threshold_) { + if (score > threshold_ && class_id > -1) { ObjectResult result_item; result_item.rect = {xmin, xmax, ymin, ymax}; result_item.class_id = class_id; @@ -172,6 +172,9 @@ void ObjectDetector::Predict(const cv::Mat& im, } else if (tensor_name == "im_shape") { in_tensor->Reshape({1, 3}); in_tensor->copy_from_cpu(inputs_.ori_im_size_f_.data()); + } else if (tensor_name == "scale_factor") { + in_tensor->Reshape({1, 4}); + in_tensor->copy_from_cpu(inputs_.scale_factor_f_.data()); } } // Run predictor diff --git a/deploy/cpp/src/preprocess_op.cc b/deploy/cpp/src/preprocess_op.cc index b3bc27528affe0ba4f83cd247daa59aa20d1cd25..f572bac74039767a8a79747dab67ea504bd1d273 100644 --- a/deploy/cpp/src/preprocess_op.cc +++ b/deploy/cpp/src/preprocess_op.cc @@ -78,6 +78,12 @@ void Resize::Run(cv::Mat* im, ImageBlob* data) { static_cast(im->cols), resize_scale.first }; + data->scale_factor_f_ = { + resize_scale.first, + resize_scale.second, + resize_scale.first, + resize_scale.second + }; } std::pair Resize::GenerateScale(const cv::Mat& im) { diff --git a/tools/infer.py b/tools/infer.py index f7783d20b5e892aea5ac7fabbe16707597548184..034e33e66a4a422a70bf5d746d4c472618baa5e1 100644 --- a/tools/infer.py +++ b/tools/infer.py @@ -178,6 +178,8 @@ def main(): for k, v in zip(keys, outs) } logger.info('Infer iter {}'.format(iter_id)) + if 'TTFNet' in cfg.architecture: + res['bbox'][1].append([len(res['bbox'][0])]) bbox_results = None mask_results = None @@ -256,4 +258,4 @@ if __name__ == '__main__': default="vdl_log_dir/image", help='VisualDL logging directory for image.') FLAGS = parser.parse_args() - main() \ No newline at end of file + main()