Skip to content

Commit 7b95f98

Browse files
Change resize to letterbox to keep model pre-processing consistent (wang-xinyu#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 <[email protected]>
1 parent 3271725 commit 7b95f98

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

yolov5/src/calibrator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <opencv2/opencv.hpp>
99
#include <opencv2/dnn/dnn.hpp>
1010

11-
static cv::Mat preprocess_img(cv::Mat& img, int input_w, int input_h) {
11+
cv::Mat preprocess_img(cv::Mat& img, int input_w, int input_h) {
1212
int w, h, x, y;
1313
float r_w = input_w / (img.cols * 1.0);
1414
float r_h = input_h / (img.rows * 1.0);

yolov5/src/calibrator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include "macros.h"
44
#include <string>
55
#include <vector>
6+
#include <opencv2/opencv.hpp>
7+
8+
cv::Mat preprocess_img(cv::Mat& img, int input_w, int input_h);
69

710
//! \class Int8EntropyCalibrator2
811
//!

yolov5/yolov5_cls.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "utils.h"
44
#include "model.h"
55
#include "config.h"
6+
#include "calibrator.h"
67

78
#include <iostream>
89
#include <chrono>
@@ -18,7 +19,8 @@ const static int kOutputSize = kClsNumClass;
1819
void batch_preprocess(std::vector<cv::Mat>& imgs, float* output) {
1920
for (size_t b = 0; b < imgs.size(); b++) {
2021
cv::Mat img;
21-
cv::resize(imgs[b], img, cv::Size(kClsInputW, kClsInputH));
22+
// cv::resize(imgs[b], img, cv::Size(kClsInputW, kClsInputH));
23+
img = preprocess_img(imgs[b], kClsInputW, kClsInputH);
2224
int i = 0;
2325
for (int row = 0; row < img.rows; ++row) {
2426
uchar* uc_pixel = img.data + row * img.step;

0 commit comments

Comments
 (0)