L4T Multimedia API Reference

27.1 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gie_inference.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA CORPORATION nor the names of its
13  * contributors may be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
48 #ifndef GIE_INFERENCE_H_
49 #define GIE_INFERENCE_H_
50 
51 #include <fstream>
52 #include <queue>
53 #include "NvInfer.h"
54 #include "NvCaffeParser.h"
55 #include "opencv2/video/tracking.hpp"
56 #include "opencv2/imgproc/imgproc.hpp"
57 #include "opencv2/highgui/highgui.hpp"
58 #include <opencv2/objdetect/objdetect.hpp>
59 using namespace nvinfer1;
60 using namespace nvcaffeparser1;
61 using namespace std;
62 
63 // Model Index
64 #define GOOGLENET_SINGLE_CLASS 0
65 #define GOOGLENET_THREE_CLASS 1
66 #define HELNET_THREE_CLASS 2
67 
68 struct {
69  const int classCnt;
70  float THRESHOLD[3];
71  const char *INPUT_BLOB_NAME;
72  const char *OUTPUT_BLOB_NAME;
73  const char *OUTPUT_BBOX_NAME;
74  const int STRIDE;
75  const int WORKSPACE_SIZE;
78 
79  {
81  1,
82  {0.8, 0, 0},
83  "data",
84  "coverage",
85  "bboxes",
86  4,
87  450 * 1024 * 1024,
88  {1, 1, 1, 1}
89  },
90 
91  {
93  3,
94  {0.6, 0.6, 1.0},
95  "data",
96  "Layer16_cov",
97  "Layer16_bbox",
98  16,
99  110 * 1024 * 1024,
100  {-640, -368, 640, 368}
101  },
102 
103  {
105  1,
106  {0.8, 0xffff, 0xffff},
107  "data",
108  "Layer19_cov",
109  "Layer19_bbox",
110  16,
111  450 * 1024 * 1024,
112  {-640, -480, 640, 480}
113  }
114 };
115 
116 class Logger;
117 
118 class Profiler;
119 
121 {
122 public:
124  int getNetWidth() const;
125 
126  int getNetHeight() const;
127 
128  int getBatchSize() const;
129 
130  int getChannel() const;
131 
132  int getModelClassCnt() const;
133 
136  void*& getBuffer(const int& index);
137 
138  float*& getInputBuf();
139 
140  int getNumGieInstances() const;
141 
142  void setForcedFp32(const bool& forced_fp32);
143 
144  void setDumpResult(const bool& dump_result);
145 
146  void setGieProfilerEnabled(const bool& enable_gie_profiler);
147 
148  int getFilterNum() const;
149  void setFilterNum(const unsigned int& filter_num);
150 
151  GIE_Context();
152 
153  void setModelIndex(int modelIndex);
154 
155  void buildGieContext(const string& deployfile,
156  const string& modelfile, bool bUseCPUBuf = false);
157 
158  void doInference(
159  queue< vector<cv::Rect> >* rectList_queue,
160  float *input = NULL);
161 
162  void destroyGieContext(bool bUseCPUBuf = false);
163 
164  ~GIE_Context();
165 
166 private:
167  int net_width;
168  int net_height;
169  int filter_num;
170  void **buffers;
171  float *input_buf;
172  float *output_cov_buf;
173  float *output_bbox_buf;
174  float helnet_scale[4];
175  IRuntime *runtime;
176  ICudaEngine *engine;
177  IExecutionContext *context;
178  uint32_t *pResultArray;
179  int channel; //input file's channel
180  int num_bindings;
181  int gieinstance_num; //inference channel num
182  int batch_size;
183  bool forced_fp32;
184  bool dump_result;
185  ofstream fstream;
186  bool enable_gie_profiler;
187  stringstream gieModelStream;
188  vector<string> outputs;
189  string result_file;
190  Logger *pLogger;
191  Profiler *pProfiler;
192  int frame_num;
193  uint64_t elapsed_frame_num;
194  uint64_t elapsed_time;
195  int inputIndex;
196  int outputIndex;
197  int outputIndexBBOX;
198  Dims3 inputDims;
199  Dims3 outputDims;
200  Dims3 outputDimsBBOX;
201  size_t inputSize;
202  size_t outputSize;
203  size_t outputSizeBBOX;
204 
205  int parseNet(const string& deployfile);
206  void parseBbox(vector<cv::Rect>* rectList, int batch_th);
207  void allocateMemory(bool bUseCPUBuf);
208  void releaseMemory(bool bUseCPUBuf);
209  void caffeToGIEModel(const string& deployfile, const string& modelfile);
210 };
211 
214 #endif
float bbox_output_scales[4]
Definition: gie_inference.h:76
struct @0 gModelNetAttr[3]
const int WORKSPACE_SIZE
Definition: gie_inference.h:75
const int STRIDE
Definition: gie_inference.h:74
const char * OUTPUT_BBOX_NAME
Definition: gie_inference.h:73
const char * OUTPUT_BLOB_NAME
Definition: gie_inference.h:72
const int classCnt
Definition: gie_inference.h:69
const char * INPUT_BLOB_NAME
Definition: gie_inference.h:71
struct @0 * g_pModelNetAttr
float THRESHOLD[3]
Definition: gie_inference.h:70