From 7b95f981f6b875601e85304c5a7eb413a281e3dc Mon Sep 17 00:00:00 2001 From: Charles_Huan <47875698+CharlesHuan@users.noreply.github.com> Date: Wed, 11 Oct 2023 15:05:01 +0800 Subject: [PATCH] Change resize to letterbox to keep model pre-processing consistent (#1371) * Update model.cpp Fix class mode pooling layer * Change resize to letterbox to keep model pre-processing consistent Change resize to letterbox to keep model pre-processing consistent * Update yolov5_cls.cpp reuse the preprocess function * Update calibrator.cpp * Update calibrator.h * Update yolov5_cls.cpp * Update yolov5_cls.cpp * Update calibrator.h * Update yolov5_cls.cpp --------- Co-authored-by: Wang Xinyu --- yolov5/src/calibrator.cpp | 2 +- yolov5/src/calibrator.h | 3 +++ yolov5/yolov5_cls.cpp | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/yolov5/src/calibrator.cpp b/yolov5/src/calibrator.cpp index ed7ce19..c339e63 100644 --- a/yolov5/src/calibrator.cpp +++ b/yolov5/src/calibrator.cpp @@ -8,7 +8,7 @@ #include #include -static cv::Mat preprocess_img(cv::Mat& img, int input_w, int input_h) { +cv::Mat preprocess_img(cv::Mat& img, int input_w, int input_h) { int w, h, x, y; float r_w = input_w / (img.cols * 1.0); float r_h = input_h / (img.rows * 1.0); diff --git a/yolov5/src/calibrator.h b/yolov5/src/calibrator.h index ed77b5f..9095110 100644 --- a/yolov5/src/calibrator.h +++ b/yolov5/src/calibrator.h @@ -3,6 +3,9 @@ #include "macros.h" #include #include +#include + +cv::Mat preprocess_img(cv::Mat& img, int input_w, int input_h); //! \class Int8EntropyCalibrator2 //! diff --git a/yolov5/yolov5_cls.cpp b/yolov5/yolov5_cls.cpp index 3ea1c81..c1c2546 100644 --- a/yolov5/yolov5_cls.cpp +++ b/yolov5/yolov5_cls.cpp @@ -3,6 +3,7 @@ #include "utils.h" #include "model.h" #include "config.h" +#include "calibrator.h" #include #include @@ -18,7 +19,8 @@ const static int kOutputSize = kClsNumClass; void batch_preprocess(std::vector& imgs, float* output) { for (size_t b = 0; b < imgs.size(); b++) { cv::Mat img; - cv::resize(imgs[b], img, cv::Size(kClsInputW, kClsInputH)); + // cv::resize(imgs[b], img, cv::Size(kClsInputW, kClsInputH)); + img = preprocess_img(imgs[b], kClsInputW, kClsInputH); int i = 0; for (int row = 0; row < img.rows; ++row) { uchar* uc_pixel = img.data + row * img.step;