Skip to content

Commit 6a74b88

Browse files
Huang ZhuangZhuangAdmin
andauthored
update retinaface_trt del cvtColor and increase THRESH (wang-xinyu#535)
* update retinaface_trt del cvtColor and increase THRESH * update macro in retinafce_xx.cpp and preprocess_image description * retinaface_xx.cpp add a space after * HRESH for CONF and THRESHOLD for IOU is unified --THRESH Co-authored-by: Admin <[email protected]>
1 parent 2c4fdea commit 6a74b88

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

retinaface/retina_mnet.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#define USE_FP16 // set USE_INT8 or USE_FP16 or USE_FP32
1313
#define DEVICE 0 // GPU id
1414
#define BATCH_SIZE 1
15-
#define VIS_THRESH 0.6
15+
#define CONF_THRESH = 0.75
16+
#define IOU_THRESH = 0.4
1617

1718
// stuff we know about the network and the input/output blobs
1819
static const int INPUT_H = decodeplugin::INPUT_H; // H, W must be able to be divided by 32.
@@ -349,13 +350,13 @@ int main(int argc, char** argv) {
349350

350351
for (int b = 0; b < BATCH_SIZE; b++) {
351352
std::vector<decodeplugin::Detection> res;
352-
nms(res, &prob[b * OUTPUT_SIZE]);
353+
nms(res, &prob[b * OUTPUT_SIZE], IOU_THRESH);
353354
std::cout << "number of detections -> " << prob[b * OUTPUT_SIZE] << std::endl;
354355
std::cout << " -> " << prob[b * OUTPUT_SIZE + 10] << std::endl;
355356
std::cout << "after nms -> " << res.size() << std::endl;
356357
cv::Mat tmp = img.clone();
357358
for (size_t j = 0; j < res.size(); j++) {
358-
if (res[j].class_confidence < VIS_THRESH) continue;
359+
if (res[j].class_confidence < CONF_THRESH) continue;
359360
cv::Rect r = get_rect_adapt_landmark(tmp, INPUT_W, INPUT_H, res[j].bbox, res[j].landmark);
360361
cv::rectangle(tmp, r, cv::Scalar(0x27, 0xC1, 0x36), 2);
361362
//cv::putText(tmp, std::to_string((int)(res[j].class_confidence * 100)) + "%", cv::Point(r.x, r.y - 1), cv::FONT_HERSHEY_PLAIN, 1.2, cv::Scalar(0xFF, 0xFF, 0xFF), 1);

retinaface/retina_r50.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#define USE_INT8 // set USE_INT8 or USE_FP16 or USE_FP32
1313
#define DEVICE 0 // GPU id
1414
#define BATCH_SIZE 1
15+
#define CONF_THRESH = 0.75
16+
#define IOU_THRESH = 0.4
1517

1618
// stuff we know about the network and the input/output blobs
1719
static const int INPUT_H = decodeplugin::INPUT_H; // H, W must be able to be divided by 32.
@@ -369,13 +371,13 @@ int main(int argc, char** argv) {
369371

370372
for (int b = 0; b < BATCH_SIZE; b++) {
371373
std::vector<decodeplugin::Detection> res;
372-
nms(res, &prob[b * OUTPUT_SIZE]);
374+
nms(res, &prob[b * OUTPUT_SIZE], IOU_THRESH);
373375
std::cout << "number of detections -> " << prob[b * OUTPUT_SIZE] << std::endl;
374376
std::cout << " -> " << prob[b * OUTPUT_SIZE + 10] << std::endl;
375377
std::cout << "after nms -> " << res.size() << std::endl;
376378
cv::Mat tmp = img.clone();
377379
for (size_t j = 0; j < res.size(); j++) {
378-
if (res[j].class_confidence < 0.1) continue;
380+
if (res[j].class_confidence < CONF_THRESH) continue;
379381
cv::Rect r = get_rect_adapt_landmark(tmp, INPUT_W, INPUT_H, res[j].bbox, res[j].landmark);
380382
cv::rectangle(tmp, r, cv::Scalar(0x27, 0xC1, 0x36), 2);
381383
//cv::putText(tmp, std::to_string((int)(res[j].class_confidence * 100)) + "%", cv::Point(r.x, r.y - 1), cv::FONT_HERSHEY_PLAIN, 1.2, cv::Scalar(0xFF, 0xFF, 0xFF), 1);

retinaface/retinaface_trt.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
INPUT_H = 480 #defined in decode.h
2121
INPUT_W = 640
22-
CONF_THRESH = 0.4
23-
IOU_THRESHOLD = 0.1
22+
CONF_THRESH = 0.75
23+
IOU_THRESHOLD = 0.4
2424
np.set_printoptions(threshold=np.inf)
2525

2626
def plot_one_box(x, landmark,img, color=None, label=None, line_thickness=None):
@@ -180,9 +180,8 @@ def destroy(self):
180180

181181
def preprocess_image(self, input_image_path):
182182
"""
183-
description: Read an image from image path, convert it to RGB,
184-
resize and pad it to target size, normalize to [0,1],
185-
transform to NCHW format.
183+
description: Read an image from image path, resize and pad it to target size,
184+
normalize to [0,1],transform to NCHW format.
186185
param:
187186
input_image_path: str, image path
188187
return:
@@ -193,8 +192,7 @@ def preprocess_image(self, input_image_path):
193192
"""
194193
image_raw = cv2.imread(input_image_path)
195194
h, w, c = image_raw.shape
196-
image = cv2.cvtColor(image_raw, cv2.COLOR_BGR2RGB)
197-
image = cv2.resize(image, (INPUT_W, INPUT_H))
195+
image = cv2.resize(image_raw, (INPUT_W, INPUT_H))
198196

199197
image = image.astype(np.float32)
200198

0 commit comments

Comments
 (0)