-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathresnet_main.cpp
73 lines (62 loc) · 2.35 KB
/
resnet_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
// Created by luozhiwang ([email protected])
// Date: 2020/5/6
#include "resnet.h"
void initInputParams(common::InputParams &inputParams){
inputParams.ImgH = 224;
inputParams.ImgW = 224;
inputParams.ImgC = 3;
inputParams.BatchSize = 1;
inputParams.IsPadding = true;
inputParams.InputTensorNames = std::vector<std::string>{"0"};
inputParams.OutputTensorNames = std::vector<std::string>{"466"};
inputParams.pFunction = [](const unsigned char &x){return static_cast<float>(x) /255;};
}
void initTrtParams(common::TrtParams &trtParams){
trtParams.ExtraWorkSpace = 0;
trtParams.FP32 = true;
trtParams.FP16 = false;
trtParams.Int32 = false;
trtParams.Int8 = false;
trtParams.MaxBatch = 100;
trtParams.MinTimingIteration = 1;
trtParams.AvgTimingIteration = 2;
trtParams.CalibrationTablePath = "/work/tensorRT-7/data/resnetInt8.calibration";
trtParams.CalibrationImageDir = "";
trtParams.OnnxPath = "/work/tensorRT-7/data/onnx/resnet.onnx";
trtParams.SerializedPath = "/work/tensorRT-7/data/onnx/resnet.serialized";
}
void initClassificationParams(common::ClassificationParams &classifactionParams){
classifactionParams.NumClass = 4;
}
int getMaxProb(const std::vector<float> &prob){
int cid = 0;
float max_prob = 0;
for(auto i=0; i<prob.size(); ++i){
printf("cid ===> %d prob ===> %f\n", i, prob[i]);
if(max_prob < prob[i]){
max_prob = prob[i];
cid = i;
}
}
printf("Cid is %d, Prob is %f\n", cid, max_prob);
}
int main(int args, char **argv){
common::InputParams inputParams;
common::TrtParams trtParams;
common::ClassificationParams classifactionParams;
initInputParams(inputParams);
initTrtParams(trtParams);
initClassificationParams(classifactionParams);
Resnet resnet(inputParams, trtParams, classifactionParams);
resnet.initSession(0);
cv::Mat image = cv::imread("/work/tensorRT-7/data/image/blue.jpg");
const auto start_t = std::chrono::high_resolution_clock::now();
std::vector<float> prob = resnet.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;
getMaxProb(prob);
return 0;
}