28 #ifndef TRT_INFERENCE_H_
29 #define TRT_INFERENCE_H_
34 #include "NvCaffeParser.h"
35 #include "NvOnnxParser.h"
36 #include "opencv2/video/tracking.hpp"
37 #include "opencv2/imgproc/imgproc.hpp"
38 #include "opencv2/highgui/highgui.hpp"
39 #include <opencv2/objdetect/objdetect.hpp>
40 using namespace nvinfer1;
41 using namespace nvcaffeparser1;
42 using namespace nvonnxparser;
46 #define GOOGLENET_SINGLE_CLASS 0
47 #define GOOGLENET_THREE_CLASS 1
48 #define RESNET_THREE_CLASS 2
58 int getNetWidth()
const;
60 int getNetHeight()
const;
62 uint32_t getBatchSize()
const;
64 int getChannel()
const;
66 int getModelClassCnt()
const;
68 void* getScales()
const;
70 void* getOffsets()
const;
74 void*& getBuffer(
const int& index);
76 float*& getInputBuf();
78 uint32_t getNumTrtInstances()
const;
81 void setMode(
const int& mode);
83 void setBatchSize(
const uint32_t& batchsize);
85 void setDumpResult(
const bool& dump_result);
87 void setTrtProfilerEnabled(
const bool& enable_trt_profiler);
89 int getFilterNum()
const;
90 void setFilterNum(
const unsigned int& filter_num);
94 void setModelIndex(
int modelIndex);
96 void buildTrtContext(
const string& deployfile,
97 const string& modelfile,
bool bUseCPUBuf =
false,
bool isOnnxModel =
false);
100 queue< vector<cv::Rect> >* rectList_queue,
101 float *input = NULL);
103 void destroyTrtContext(
bool bUseCPUBuf =
false);
113 float *output_cov_buf;
114 float *output_bbox_buf;
117 float helnet_scale[4];
120 IExecutionContext *context;
121 uint32_t *pResultArray;
129 bool enable_trt_profiler;
131 IHostMemory *trtModelStream{
nullptr};
132 vector<string> outputs;
137 uint64_t elapsed_frame_num;
138 uint64_t elapsed_time;
144 Dims3 outputDimsBBOX;
147 size_t outputSizeBBOX;
158 float input_scale[3];
159 float bbox_output_scales[4];
161 } *g_pModelNetAttr, gModelNetAttr[4] = {
188 {-640, -368, 640, 368},
202 {0.0039215697906911373, 0.0039215697906911373, 0.0039215697906911373},
203 {-640, -368, 640, 368},
212 int parseNet(
const string& deployfile);
213 void parseBbox(vector<cv::Rect>* rectList,
int batch_th);
214 void ParseResnet10Bbox(vector<cv::Rect>* rectList,
int batch_th);
215 void allocateMemory(
bool bUseCPUBuf);
216 void releaseMemory(
bool bUseCPUBuf);
217 void caffeToTRTModel(
const string& deployfile,
const string& modelfile);
218 void onnxToTRTModel(
const string& modelfile);