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 <shaywxy@gmail.com>
This commit is contained in:
Charles_Huan 2023-10-11 15:05:01 +08:00 committed by GitHub
parent 3271725dd4
commit 7b95f981f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View File

@ -8,7 +8,7 @@
#include <opencv2/opencv.hpp>
#include <opencv2/dnn/dnn.hpp>
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);

View File

@ -3,6 +3,9 @@
#include "macros.h"
#include <string>
#include <vector>
#include <opencv2/opencv.hpp>
cv::Mat preprocess_img(cv::Mat& img, int input_w, int input_h);
//! \class Int8EntropyCalibrator2
//!

View File

@ -3,6 +3,7 @@
#include "utils.h"
#include "model.h"
#include "config.h"
#include "calibrator.h"
#include <iostream>
#include <chrono>
@ -18,7 +19,8 @@ const static int kOutputSize = kClsNumClass;
void batch_preprocess(std::vector<cv::Mat>& 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;