Skip to content

Commit 918db59

Browse files
Initial yolo refactoring: Changed private and public members
1 parent 698b305 commit 918db59

File tree

2 files changed

+24
-32
lines changed

2 files changed

+24
-32
lines changed

inc/yolo_inference.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,18 @@ class YOLO_V8
6868

6969
const char* RunSession(const cv::Mat& iImg, std::vector<DL_RESULT>& oResult);
7070

71+
std::vector<std::string> classes{};
72+
73+
private:
7174
char* WarmUpSession();
7275

76+
// Note: The logic is on the .cpp file since its a private method.
7377
template<typename N>
7478
char* TensorProcess(clock_t& starttime_1, const cv::Mat& iImg, N& blob, std::vector<int64_t>& inputNodeDims,
7579
std::vector<DL_RESULT>& oResult);
7680

7781
char* PreProcess(const cv::Mat& iImg, std::vector<int> iImgSize, cv::Mat& oImg);
7882

79-
std::vector<std::string> classes{};
80-
81-
private:
8283
Ort::Env env;
8384
std::unique_ptr<Ort::Session> session;
8485
bool cudaEnable;

src/yolo_inference.cpp

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22
#include <regex>
33

44
#define benchmark
5-
#define min(a,b) (((a) < (b)) ? (a) : (b))
6-
YOLO_V8::YOLO_V8() {
5+
#define min(a, b) (((a) < (b)) ? (a) : (b))
76

7+
YOLO_V8::YOLO_V8()
8+
{
89
}
910

10-
11-
YOLO_V8::~YOLO_V8() {
12-
for (auto& name : inputNodeNames) {
13-
delete[] name;
14-
}
15-
for (auto& name : outputNodeNames) {
16-
delete[] name;
17-
}
11+
YOLO_V8::~YOLO_V8()
12+
{
1813
}
1914

2015
#ifdef USE_CUDA
@@ -25,9 +20,14 @@ namespace Ort
2520
}
2621
#endif
2722

28-
29-
// Definition: Flattened image to blob (and normalizaed) for deep learning inference. Also reorganize from HWC to CHW.
30-
// Note: Not in the header file since it is not used outside of this file.
23+
/**
24+
* @brief Flattened image to blob (and normalized) for deep learning inference. Also reorganize from HWC to CHW.
25+
*
26+
* @tparam T
27+
* @param iImg
28+
* @param iBlob
29+
* @return char*
30+
*/
3131
template<typename T>
3232
char* BlobFromImage(const cv::Mat& iImg, T& iBlob) {
3333
int channels = iImg.channels();
@@ -66,7 +66,7 @@ char* YOLO_V8::PreProcess(const cv::Mat& iImg, std::vector<int> iImgSize, cv::Ma
6666
case YOLO_DETECT_V8:
6767
case YOLO_POSE:
6868
case YOLO_DETECT_V8_HALF:
69-
case YOLO_POSE_V8_HALF://LetterBox
69+
case YOLO_POSE_V8_HALF: // LetterBox and Top Left Crop
7070
{
7171
if (iImg.cols >= iImg.rows)
7272
{
@@ -83,7 +83,7 @@ char* YOLO_V8::PreProcess(const cv::Mat& iImg, std::vector<int> iImgSize, cv::Ma
8383
oImg = tempImg;
8484
break;
8585
}
86-
case YOLO_CLS://CenterCrop
86+
case YOLO_CLS: // CenterCrop
8787
{
8888
int h = iImg.rows;
8989
int w = iImg.cols;
@@ -100,9 +100,9 @@ char* YOLO_V8::PreProcess(const cv::Mat& iImg, std::vector<int> iImgSize, cv::Ma
100100

101101
const char* YOLO_V8::CreateSession(DL_INIT_PARAM& iParams) {
102102
const char* Ret = RET_OK;
103-
if (session) {
104-
105-
// Clear node names
103+
if (session)
104+
{
105+
// Clear node names from previous declaration
106106
for (auto& name : inputNodeNames) {
107107
delete[] name;
108108
}
@@ -117,7 +117,7 @@ const char* YOLO_V8::CreateSession(DL_INIT_PARAM& iParams) {
117117
bool result = std::regex_search(iParams.modelPath, pattern);
118118
if (result)
119119
{
120-
Ret = "[YOLO_V8]:Your model path is error.Change your model path without chinese characters.";
120+
Ret = "[YOLO_V8]:Your model path is error. Change your model path without chinese characters.";
121121
std::cout << Ret << std::endl;
122122
return Ret;
123123
}
@@ -140,16 +140,7 @@ const char* YOLO_V8::CreateSession(DL_INIT_PARAM& iParams) {
140140
sessionOption.SetIntraOpNumThreads(iParams.intraOpNumThreads);
141141
sessionOption.SetLogSeverityLevel(iParams.logSeverityLevel);
142142

143-
#ifdef _WIN32
144-
int ModelPathSize = MultiByteToWideChar(CP_UTF8, 0, iParams.modelPath.c_str(), static_cast<int>(iParams.modelPath.length()), nullptr, 0);
145-
wchar_t* wide_cstr = new wchar_t[ModelPathSize + 1];
146-
MultiByteToWideChar(CP_UTF8, 0, iParams.modelPath.c_str(), static_cast<int>(iParams.modelPath.length()), wide_cstr, ModelPathSize);
147-
wide_cstr[ModelPathSize] = L'\0';
148-
const wchar_t* modelPath = wide_cstr;
149-
#else
150-
const char* modelPath = iParams.modelPath.c_str();
151-
#endif // _WIN32
152-
143+
const char *modelPath = iParams.modelPath.c_str();
153144
session = std::make_unique<Ort::Session>(env, modelPath, sessionOption);
154145
Ort::AllocatorWithDefaultOptions allocator;
155146
size_t inputNodesNum = session->GetInputCount();

0 commit comments

Comments
 (0)