-
Notifications
You must be signed in to change notification settings - Fork 111
/
retinaface_main.cpp
88 lines (80 loc) · 3.1 KB
/
retinaface_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Created by luozhiwang (luozw1994@outlook.com)
// Date: 2020/5/20
#include "retinaface.h"
void initInputParams(common::InputParams &inputParams){
inputParams.ImgH = 640;
inputParams.ImgW = 640;
inputParams.ImgC = 3;
inputParams.BatchSize = 1;
inputParams.IsPadding = true;
inputParams.InputTensorNames = std::vector<std::string>{"input0"};
inputParams.OutputTensorNames = std::vector<std::string>{"output0", "588", "587"};
inputParams.pFunction = [](const unsigned char &x){return static_cast<float>(x) - 118;};
}
void initTrtParams(common::TrtParams &trtParams){
trtParams.ExtraWorkSpace = 0;
trtParams.FP32 = true;
trtParams.FP16 = false;
trtParams.Int32 = false;
trtParams.Int8 = false;
trtParams.worker = 4;
trtParams.MaxBatch = 100;
trtParams.MinTimingIteration = 1;
trtParams.AvgTimingIteration = 2;
trtParams.CalibrationTablePath = "/work/tensorRT-7/data/retinafaceInt8.calibration";
trtParams.CalibrationImageDir = "/data/dataset/coco/images/train2017";
trtParams.OnnxPath = "/work/tensorRT-7/data/onnx/retinaface.onnx";
trtParams.SerializedPath = "/work/tensorRT-7/data/onnx/retinaface.serialized";
}
std::vector<common::Anchor> initAnchors(){
std::vector<common::Anchor> anchors;
common::Anchor anchor;
// [16, 32, 64, 128, 256, 512]
anchor.width = anchor.height = 16;
anchors.emplace_back(anchor);
anchor.width = anchor.height = 32;
anchors.emplace_back(anchor);
anchor.width = anchor.height = 64;
anchors.emplace_back(anchor);
anchor.width = anchor.height = 128;
anchors.emplace_back(anchor);
anchor.width = anchor.height = 256;
anchors.emplace_back(anchor);
anchor.width = anchor.height = 512;
anchors.emplace_back(anchor);
return anchors;
}
void initDetectParams(common::DetectParams &detectParams){
detectParams.Strides = std::vector<int> {8, 16, 32};
detectParams.AnchorPerScale = 2;
detectParams.NumClass = 2;
detectParams.NMSThreshold = 0.5;
detectParams.PostThreshold = 0.6;
detectParams.Anchors = initAnchors();
}
int main(int args, char **argv){
// 差不多预处理11-12ms, 后处理3.5-4ms
// 27fps ===> 50fps
common::InputParams inputParams;
common::TrtParams trtParams;
common::DetectParams yoloParams;
initInputParams(inputParams);
initTrtParams(trtParams);
initDetectParams(yoloParams);
Retinaface retinaface(inputParams, trtParams, yoloParams);
retinaface.initSession(0);
cv::Mat image = cv::imread("/work/tensorRT-7/data/image/coco_1.jpg");
std::vector<common::Bbox> bboxes;
for(int i=0; i<20; ++i){
const auto start_t = std::chrono::high_resolution_clock::now();
bboxes = retinaface.predOneImage(image);
const auto end_t = std::chrono::high_resolution_clock::now();
std::cout
<< "Wall clock time passed: "
<< std::chrono::duration<double, std::milli>(end_t-start_t).count()<<"ms"
<< std::endl;
}
image = renderBoundingBox(image, bboxes);
cv::imwrite("/work/tensorRT-7/data/image/render.jpg", image);
return 0;
}