TensorRT
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
NvInferPlugin.h
Go to the documentation of this file.
1 /*
2  * Copyright 1993-2016 NVIDIA Corporation. All rights reserved.
3  *
4  * NOTICE TO LICENSEE:
5  *
6  * This source code and/or documentation ("Licensed Deliverables") are
7  * subject to NVIDIA intellectual property rights under U.S. and
8  * international Copyright laws.
9  *
10  * These Licensed Deliverables contained herein is PROPRIETARY and
11  * CONFIDENTIAL to NVIDIA and is being provided under the terms and
12  * conditions of a form of NVIDIA software license agreement by and
13  * between NVIDIA and Licensee ("License Agreement") or electronically
14  * accepted by Licensee. Notwithstanding any terms or conditions to
15  * the contrary in the License Agreement, reproduction or disclosure
16  * of the Licensed Deliverables to any third party without the express
17  * written consent of NVIDIA is prohibited.
18  *
19  * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
20  * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE
21  * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS
22  * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.
23  * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED
24  * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY,
25  * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
26  * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
27  * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY
28  * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
29  * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
30  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
31  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
32  * OF THESE LICENSED DELIVERABLES.
33  *
34  * U.S. Government End Users. These Licensed Deliverables are a
35  * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT
36  * 1995), consisting of "commercial computer software" and "commercial
37  * computer software documentation" as such terms are used in 48
38  * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government
39  * only as a commercial end item. Consistent with 48 C.F.R.12.212 and
40  * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all
41  * U.S. Government End Users acquire the Licensed Deliverables with
42  * only those rights set forth herein.
43  *
44  * Any use of the Licensed Deliverables in individual and commercial
45  * software must include, in the user documentation and internal
46  * comments to the code, the above Disclaimer and U.S. Government End
47  * Users Notice.
48  */
49 
50 #ifndef NV_INFER_PLUGIN_H
51 #define NV_INFER_PLUGIN_H
52 
53 #include "NvInfer.h"
54 
61 namespace nvinfer1
62 {
70  enum class PluginType : int
71  {
72  kFASTERRCNN = 0,
73  kNORMALIZE = 1,
74  kPERMUTE = 2,
75  kPRIORBOX = 3,
77  kCONCAT = 5,
78  kPRELU = 6,
79  kYOLOREORG = 7,
80  kYOLOREGION = 8,
81  };
82  template<> inline int EnumMax<PluginType>() { return 9; }
83 namespace plugin
84 {
95  class INvPlugin : public IPlugin
96  {
97  public:
103  virtual PluginType getPluginType() const = 0;
104 
113  virtual const char *getName() const = 0;
114 
120  virtual void destroy() = 0;
121  protected:
122  ~INvPlugin() {}
123  }; // INvPlugin
124 
142  INvPlugin * createFasterRCNNPlugin(int featureStride, int preNmsTop,
143  int nmsMaxOut, float iouThreshold, float minBoxSize,
144  float spatialScale, DimsHW pooling,
145  Weights anchorRatios, Weights anchorScales);
146  INvPlugin * createFasterRCNNPlugin(const void * data, size_t length);
147 
148 
149  /*
150  * \brief The Normalize plugin layer normalizes the input to have L2 norm of 1 with scale learnable.
151  * \params scales scale weights that are applied to the output tensor
152  * \params acrossSpatial whether to compute the norm over adjacent channels (acrossSpatial is true) or nearby spatial locations (within channel in which case acrossSpatial is false)
153  * \params channelShared whether the scale weight(s) is shared across channels
154  * \params eps epsilon for not diviiding by zero
155  */
156  INvPlugin * createSSDNormalizePlugin(const Weights *scales, bool acrossSpatial, bool channelShared, float eps);
157  INvPlugin * createSSDNormalizePlugin(const void * data, size_t length);
158 
159  /*
160  * \brief The Permute plugin layer permutes the input tensor by changing the memory order of the data.
161  * Quadruple defines a structure that contains an array of 4 integers. They can represent the permute orders or the strides in each dimension.
162  */
163  typedef struct
164  {
165  int data[4];
166  } Quadruple;
167  /*
168  * \params permuteOrder <The new orders that are used to permute the data.>
169  */
170  INvPlugin * createSSDPermutePlugin(Quadruple permuteOrder);
171  INvPlugin * createSSDPermutePlugin(const void * data, size_t length);
172 
173  /*
174  * \brief The PriorBox plugin layer generates the prior boxes of designated sizes and aspect ratios across all dimensions @f$ (H \times W) @f$.
175  * PriorBoxParameters defines a set of parameters for creating the PriorBox plugin layer.
176  * It contains:
177  * \params minSize minimum box size in pixels. Can not be nullptr
178  * \params maxSize maximum box size in pixels. Can be nullptr
179  * \params aspectRatios aspect ratios of the boxes. Can be nullptr
180  * \params numMinSize number of elements in minSize. Must be larger than 0
181  * \params numMaxSize number of elements in maxSize. Can be 0 or same as numMinSize
182  * \params numAspectRatios number of elements in aspectRatios. Can be 0
183  * \params flip If true, will flip each aspect ratio. For example, if there is aspect ratio "r", the aspect ratio "1.0/r" will be generated as well.
184  * \params clip If true, will clip the prior so that it is within [0,1]
185  * \params variance variance for adjusting the prior boxes.
186  * \params imgH image height. If 0, then the H dimension of the data tensor will be used
187  * \params imgW image width. If 0, then the W dimension of the data tensor will be used
188  * \params stepH step in H. If 0, then (float)imgH/h will be used where h is the H dimension of the 1st input tensor
189  * \params stepW step in W. If 0, then (float)imgW/w will be used where w is the W dimension of the 1st input tensor
190  * \params offset offset to the top left corner of each cell
191  */
193  {
194  float *minSize, *maxSize, *aspectRatios;
195  int numMinSize, numMaxSize, numAspectRatios;
196  bool flip;
197  bool clip;
198  float variance[4];
199  int imgH, imgW;
200  float stepH, stepW;
201  float offset;
202  };
203 
204  /*
205  * \params param set of parameters for creating the PriorBox plugin layer
206  */
207 
208  INvPlugin * createSSDPriorBoxPlugin(PriorBoxParameters param);
209  INvPlugin * createSSDPriorBoxPlugin(const void * data, size_t length);
210 
211 
212  /*
213  * \brief The DetectionOutput plugin layer generates the detection output based on location and confidence predictions by doing non maximum suppression.
214  * DetectionOutputParameters defines a set of parameters for creating the DetectionOutput plugin layer.
215  * It contains:
216  * \params shareLocation If true, bouding box are shared among different classes
217  * \params varianceEncodedInTarget If true, variance is encoded in target. Otherwise we need to adjust the predicted offset accordingly
218  * \params backgroundLabelId background label ID. If there is no background class, set it as -1
219  * \params numClasses number of classes to be predicted
220  * \params topK number of boxes per image with top confidence scores that are fed into the NMS algorithm
221  * \params keepTopK number of total bounding boxes to be kept per image after NMS step
222  * \params confidenceThreshold only consider detections whose confidences are larger than a threshold
223  * \params nmsThreshold threshold to be used in NMS
224  * \params codeType type of coding method for bbox
225  */
226  typedef enum
227  {
228  CORNER = 1,
229  CENTER_SIZE = 2,
230  CORNER_SIZE = 3
231  } CodeType_t;
232 
234  {
235  bool shareLocation, varianceEncodedInTarget;
236  int backgroundLabelId, numClasses, topK, keepTopK;
237  float confidenceThreshold, nmsThreshold;
238  CodeType_t codeType;
239  };
240 
241  /*
242  * \params param set of parameters for creating the DetectionOutput plugin layer
243  */
244 
245  INvPlugin * createSSDDetectionOutputPlugin(DetectionOutputParameters param);
246  INvPlugin * createSSDDetectionOutputPlugin(const void * data, size_t length);
247 
248  /*
249  * \brief The Concat plugin layer basically performs the concatention for 4D tensors. Unlike the Concatenation layer in early version of TensorRT, it allows the user to specify the axis along which to concatenate. The axis can be 1 (across channel), 2 (across H), or 3 (across W). More particularly, this Concat plugin layer also implements the "ignoring the batch dimension" switch. If turned on, all the input tensors will be treated as if their batch sizes were 1.
250  * \params concatAxis axis along which to concatenate. Can't be the "N" dimension
251  * \params ignoreBatch If true, all the input tensors will be treated as if their batch sizes were 1
252  */
253 
254  INvPlugin * createConcatPlugin(int concatAxis, bool ignoreBatch);
255  INvPlugin * createConcatPlugin(const void * data, size_t length);
256 
257 
258  /*
259  * \brief The PReLu plugin layer performs leaky ReLU for 4D tensors. Give an input value x, the PReLU layer computes the output as x if x > 0 and negative_slope * x if x <= 0.
260  * \params negSlope negative_slope value
261  */
262 
263  INvPlugin * createPReLUPlugin(float negSlope);
264  INvPlugin * createPReLUPlugin(const void * data, size_t length);
265 
266  /*
267  * \brief The Reorg plugin layer maps the 512x26x26 feature map onto a 2048x13x13 feature map, so that it can be concatenated with the feature maps at 13x13 resolution.
268  * \params stride strides in H and W
269  */
270 
271  INvPlugin * createYOLOReorgPlugin(int stride);
272  INvPlugin * createYOLOReorgPlugin(const void * data, size_t length);
273 
274  /*
275  * \brief The Region plugin layer performs region proposal calculation: generate 5 bounding boxes per cell (for yolo9000, generate 3 bounding boxes per cell). For each box, calculating its probablities of objects detections from 80 pre-defined classifications (yolo9000 has 9416 pre-defined classifications, and these 9416 items are organized as work-tree structure).
276  * RegionParameters defines a set of parameters for creating the Region plugin layer.
277  * \params num number of predicted bounding box for each grid cell
278  * \params coords number of coordinates for a bounding box
279  * \params classes number of classfications to be predicted
280  * \params softmaxTree when performing yolo9000, softmaxTree is helping to do softmax on confidence scores, for element to get the precise classfication through word-tree structured classfication definition.
281  */
282 
283  typedef struct{
284  int *leaf;
285  int n;
286  int *parent;
287  int *child;
288  int *group;
289  char **name;
290 
291  int groups;
292  int *groupSize;
293  int *groupOffset;
294  } softmaxTree; // softmax tree
295 
297  {
298  int num;
299  int coords;
300  int classes;
301  softmaxTree * smTree;
302  };
303 
304  INvPlugin * createYOLORegionPlugin(RegionParameters params);
305  INvPlugin * createYOLORegionPlugin(const void * data, size_t length);
306 
307 } // end plugin namespace
308 } // end nvinfer1 namespace
309 #endif // NV_INFER_PLUGIN_H
Definition: NvInferPlugin.h:163
YOLO PReLU Plugin.
virtual const char * getName() const =0
get the name of the plugin from the ID
PluginType
the type values for the various plugins
Definition: NvInferPlugin.h:70
virtual PluginType getPluginType() const =0
get the parameter plugin ID.
plugin class for user-implemented layers
Definition: NvInfer.h:1713
Common interface for the NVidia created plugins.
Definition: NvInferPlugin.h:95
FasterRCNN fused plugin (RPN + ROI pooling)
SSD DetectionOutput plugin.
int EnumMax< PluginType >()
maximum number of elements in PluginType enum.
Definition: NvInferPlugin.h:82
Definition: NvInferPlugin.h:192
virtual void destroy()=0
destroy the plugin
an array of weights used as a layer parameter
Definition: NvInfer.h:381
Definition: NvInferPlugin.h:283
Definition: NvInferPlugin.h:296
descriptor for two-dimensional spatial data
Definition: NvInfer.h:156
Definition: NvInferPlugin.h:233