Skip to content

Commit d21479c

Browse files
committed
fix bug
1 parent 823ec82 commit d21479c

File tree

4 files changed

+22
-78
lines changed

4 files changed

+22
-78
lines changed

FaceAlgorithm/face_detect_yolov5face/detector_yolov5face.cpp

+14-68
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ HZFLAG Detector_Yolov5Face::InitDetector_Yolov5Face(Config& config)
8282
CHECK(cudaMallocHost((void**)&img_host, config.yolov5face_detect_bs*MAX_IMAGE_INPUT_SIZE_THRESH * 3*sizeof(uint8_t)));
8383
// prepare input data cache in device memory
8484
CHECK(cudaMalloc((void**)&img_device, config.yolov5face_detect_bs*MAX_IMAGE_INPUT_SIZE_THRESH * 3*sizeof(uint8_t)));
85+
86+
87+
prob=new float[config.yolov5face_detect_bs * OUTPUT_SIZE];
88+
8589
return HZ_SUCCESS;
8690
}
8791

@@ -91,34 +95,25 @@ HZFLAG Detector_Yolov5Face::Detect_Yolov5Face(std::vector<cv::Mat>&ImgVec,std::v
9195
// prepare input data ---------------------------
9296
int detector_batchsize=ImgVec.size();
9397
float* buffer_idx = (float*)buffers[inputIndex];
94-
std::vector<cv::Mat> imgs_buffer(detector_batchsize);
9598
for (int b = 0; b < detector_batchsize; b++)
9699
{
97100
if (ImgVec[b].empty()||ImgVec[b].data==NULL)
98101
{
99102
continue;
100103
}
101-
imgs_buffer[b] = ImgVec[b].clone();
102-
size_t size_image = imgs_buffer[b].cols * imgs_buffer[b].rows * 3*sizeof(uint8_t);
104+
ImgVec[b] = ImgVec[b].clone();
105+
size_t size_image = ImgVec[b].cols * ImgVec[b].rows * 3*sizeof(uint8_t);
103106
size_t size_image_dst = INPUT_H * INPUT_W * 3*sizeof(uint8_t);
104107
//copy data to pinned memory
105-
memcpy(img_host,imgs_buffer[b].data,size_image);
108+
memcpy(img_host,ImgVec[b].data,size_image);
106109
//copy data to device memory
107-
CHECK(cudaMemcpyAsync(img_device,img_host,size_image,cudaMemcpyHostToDevice,stream));
108-
preprocess_kernel_img_yolov5_face(img_device,imgs_buffer[b].cols,imgs_buffer[b].rows, buffer_idx, INPUT_W, INPUT_H, stream);
110+
CHECK(cudaMemcpy(img_device,img_host,size_image,cudaMemcpyHostToDevice));
111+
preprocess_kernel_img_yolov5_face(img_device,ImgVec[b].cols,ImgVec[b].rows, buffer_idx, INPUT_W, INPUT_H, stream);
109112
buffer_idx += size_image_dst;
110113
}
111114
// Run inference
112-
float *prob=new float[detector_batchsize * OUTPUT_SIZE];
115+
113116
doInference(*context,stream,(void**)buffers,prob,detector_batchsize);
114-
// std::fstream writetxt;
115-
// writetxt.open("12.txt",std::ios::out);
116-
// for (size_t k = 0; k < detector_batchsize * OUTPUT_SIZE; k++)
117-
// {
118-
// writetxt<<prob[k]<<std::endl;
119-
// }
120-
// writetxt.close();
121-
122117
for (int b = 0; b < detector_batchsize; b++)
123118
{
124119
std::vector<decodeplugin_yolov5face::Detection> res;
@@ -132,25 +127,12 @@ HZFLAG Detector_Yolov5Face::Detect_Yolov5Face(std::vector<cv::Mat>&ImgVec,std::v
132127
}
133128
Det det;
134129
det.confidence=res[j].class_confidence;
135-
get_rect_adapt_landmark(imgs_buffer[b], INPUT_W, INPUT_H, res[j].bbox, res[j].landmark,det);
130+
get_rect_adapt_landmark(ImgVec[b], INPUT_W, INPUT_H, res[j].bbox, res[j].landmark,det);
136131
Imgdet.push_back(det);
137132
}
138-
// for (size_t j = 0; j < Imgdet.size(); j++)
139-
// {
140-
// cv::rectangle(ImgVec[b], cv::Point( Imgdet[j].bbox.xmin, Imgdet[j].bbox.ymin),
141-
// cv::Point( Imgdet[j].bbox.xmax, Imgdet[j].bbox.ymax), cv::Scalar(255, 0, 0), 2, 8, 0);
142-
// cv::circle(ImgVec[b], cv::Point2f( Imgdet[j].key_points[0], Imgdet[j].key_points[1]), 2, cv::Scalar(255, 0, 0), 1);
143-
// cv::circle(ImgVec[b], cv::Point2f( Imgdet[j].key_points[2], Imgdet[j].key_points[3]), 2, cv::Scalar(0, 0, 255), 1);
144-
// cv::circle(ImgVec[b], cv::Point2f( Imgdet[j].key_points[4], Imgdet[j].key_points[5]), 2, cv::Scalar(0, 255, 0), 1);
145-
// cv::circle(ImgVec[b], cv::Point2f( Imgdet[j].key_points[6], Imgdet[j].key_points[7]), 2, cv::Scalar(255, 0, 255), 1);
146-
// cv::circle(ImgVec[b], cv::Point2f( Imgdet[j].key_points[8], Imgdet[j].key_points[9]), 2, cv::Scalar(0, 255, 255), 1);
147-
// }
148-
// cv::imshow("show", ImgVec[b]);
149-
// cv::waitKey(0);
150133
dets.push_back(Imgdet);
151134
}
152-
delete []prob;
153-
prob=NULL;
135+
154136
return HZ_SUCCESS;
155137

156138
}
@@ -164,6 +146,8 @@ HZFLAG Detector_Yolov5Face::ReleaseDetector_Yolov5Face()
164146
context->destroy();
165147
engine->destroy();
166148
runtime->destroy();
149+
delete []prob;
150+
prob=NULL;
167151
return HZ_SUCCESS;
168152
}
169153

@@ -266,44 +250,6 @@ void Detector_Yolov5Face::nms(std::vector<decodeplugin_yolov5face::Detection>& r
266250
}
267251
}
268252
}
269-
270-
// void Detector_Yolov5Face::get_rect_adapt_landmark(cv::Mat& img, int input_w, int input_h, float bbox[4], float lmk[10],Det&det)
271-
// {
272-
// int l, r, t, b;
273-
// float r_w = input_w / (img.cols * 1.0);
274-
// float r_h = input_h / (img.rows * 1.0);
275-
// if (r_h > r_w)
276-
// {
277-
// l = bbox[0] / r_w;
278-
// r = bbox[2] / r_w;
279-
// t = (bbox[1] - (input_h - r_w * img.rows) / 2) / r_w;
280-
// b = (bbox[3] - (input_h - r_w * img.rows) / 2) / r_w;
281-
// for (int i = 0; i < 10; i += 2)
282-
// {
283-
// det.key_points.push_back(lmk[i]/r_w);
284-
// det.key_points.push_back((lmk[i + 1] - (input_h - r_w * img.rows) / 2) / r_w);
285-
// }
286-
// }
287-
// else
288-
// {
289-
// l = (bbox[0] - (input_w - r_h * img.cols) / 2) / r_h;
290-
// r = (bbox[2] - (input_w - r_h * img.cols) / 2) / r_h;
291-
// t = bbox[1] / r_h;
292-
// b = bbox[3] / r_h;
293-
// for (int i = 0; i < 10; i += 2)
294-
// {
295-
// det.key_points.push_back((lmk[i] - (input_w - r_h * img.cols) / 2) / r_h);
296-
// det.key_points.push_back(lmk[i + 1]/r_h);
297-
// }
298-
// }
299-
// det.bbox.xmin=l>1?l:1;
300-
// det.bbox.ymin=t>1?t:1;
301-
// det.bbox.xmax=r>det.bbox.xmin?r:det.bbox.xmin+1;
302-
// det.bbox.xmax=det.bbox.xmax<img.cols?det.bbox.xmax:img.cols-1;
303-
// det.bbox.ymax=b>det.bbox.ymin?b:det.bbox.ymin+1;
304-
// det.bbox.ymax=det.bbox.ymax<img.rows?det.bbox.ymax:img.rows-1;
305-
// return ;
306-
// }
307253
void Detector_Yolov5Face::get_rect_adapt_landmark(cv::Mat& img, int input_w, int input_h, float bbox[4], float lmk[10],Det&det)
308254
{
309255
int l, r, t, b;

FaceAlgorithm/face_detect_yolov5face/detector_yolov5face.h

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class Detector_Yolov5Face
7272
char* INPUT_BLOB_NAME;
7373
char* OUTPUT_BLOB_NAME;
7474
char *trtModelStream{nullptr};
75+
float *prob=nullptr;
7576

7677

7778
public:

FaceAlgorithm/face_detect_yolov7face/detector_yolov7face.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ HZFLAG Detector_Yolov7Face::Detect_Yolov7Face(std::vector<cv::Mat>&ImgVec,std::v
109109
{
110110
// prepare input data ---------------------------
111111
int detector_batchsize=ImgVec.size();
112-
std::vector<cv::Mat> imgs_buffer(detector_batchsize);
113-
//cv::Mat img=cv::imread("/home/pcb/FaceRecognition_Linux_Release/FaceAlgorithm/8.jpg");
114112
float* buffer_idx = (float*)this->buffers[inputIndex];
115113
for (int b = 0; b < detector_batchsize; b++)
116114
{
@@ -120,15 +118,14 @@ HZFLAG Detector_Yolov7Face::Detect_Yolov7Face(std::vector<cv::Mat>&ImgVec,std::v
120118
}
121119
//proprecess
122120
affineMatrix afmt;
123-
imgs_buffer[b] = ImgVec[b].clone();
124-
getd2i(afmt,cv::Size(INPUT_W,INPUT_H),cv::Size(imgs_buffer[b].cols,imgs_buffer[b].rows));
125-
size_t size_image = imgs_buffer[b].cols * imgs_buffer[b].rows * 3*sizeof(uint8_t);
121+
getd2i(afmt,cv::Size(INPUT_W,INPUT_H),cv::Size(ImgVec[b].cols,ImgVec[b].rows));
122+
size_t size_image = ImgVec[b].cols * ImgVec[b].rows * 3*sizeof(uint8_t);
126123
size_t size_image_dst = INPUT_H * INPUT_W * 3*sizeof(uint8_t);
127124
memcpy(affine_matrix_d2i_host,afmt.d2i,sizeof(afmt.d2i));
128-
memcpy(img_host, imgs_buffer[b].data, size_image);
129-
CHECK(cudaMemcpyAsync(img_device, img_host, size_image, cudaMemcpyHostToDevice, stream));
130-
CHECK(cudaMemcpyAsync(affine_matrix_d2i_device[b],affine_matrix_d2i_host,sizeof(afmt.d2i),cudaMemcpyHostToDevice,stream));
131-
yolov7face_preprocess_kernel_img(img_device, imgs_buffer[b].cols, imgs_buffer[b].rows, buffer_idx, INPUT_W, INPUT_H,affine_matrix_d2i_device[b], stream);
125+
memcpy(img_host, ImgVec[b].data, size_image);
126+
CHECK(cudaMemcpy(img_device, img_host, size_image, cudaMemcpyHostToDevice));
127+
CHECK(cudaMemcpy(affine_matrix_d2i_device[b],affine_matrix_d2i_host,sizeof(afmt.d2i),cudaMemcpyHostToDevice));
128+
yolov7face_preprocess_kernel_img(img_device, ImgVec[b].cols, ImgVec[b].rows, buffer_idx, INPUT_W, INPUT_H,affine_matrix_d2i_device[b], stream);
132129
buffer_idx += size_image_dst;
133130
}
134131
//inference

FaceAlgorithm/lib/FaceRecognition.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ HZFLAG FaceRecognition::Yolov7Face_Detect(std::vector<cv::Mat>&img, std::vector<
386386
facedet.confidence = temp_det[i][j].confidence;
387387
facedet.label = -1;
388388
cv::Point temp_keypoint[7];
389-
for (int k=0;k<7;k++)
389+
for (int k=0;k<5;k++)
390390
{
391391
cv::Point2f point111;
392392
point111.x = temp_det[i][j].key_points[2*k];

0 commit comments

Comments
 (0)