codekingpro/portable-devtools
115k
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 1993-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NV_INFER_PLUGIN_UTILS_H
19#define NV_INFER_PLUGIN_UTILS_H
20
21#include "NvInferRuntimeCommon.h"
22
23//!
24//! \file NvInferPluginUtils.h
25//!
26//! This is the API for the Nvidia provided TensorRT plugin utilities.
27//! It lists all the parameters utilized by the TensorRT plugins.
28//!
29
30namespace nvinfer1
31{
32namespace plugin
33{
34
35//!
36//! \struct PriorBoxParameters
37//!
38//! \brief The PriorBox plugin layer generates the prior boxes of designated sizes and aspect ratios across all
39//! dimensions (H x W).
40//!
41//! PriorBoxParameters defines a set of parameters for creating the PriorBox plugin layer.
42//!
43struct PriorBoxParameters
44{
45 float *minSize; //!< Minimum box size in pixels. Can not be nullptr.
46 float *maxSize; //!< Maximum box size in pixels. Can be nullptr.
47 float *aspectRatios; //!< Aspect ratios of the boxes. Can be nullptr.
48 int32_t numMinSize; //!< Number of elements in minSize. Must be larger than 0.
49 int32_t numMaxSize; //!< Number of elements in maxSize. Can be 0 or same as numMinSize.
50 int32_t numAspectRatios; //!< Number of elements in aspectRatios. Can be 0.
51 bool flip; //!< If true, will flip each aspect ratio. For example,
52 //!< if there is an aspect ratio "r", the aspect ratio "1.0/r" will be generated as well.
53 bool clip; //!< If true, will clip the prior so that it is within [0,1].
54 float variance[4]; //!< Variance for adjusting the prior boxes.
55 int32_t imgH; //!< Image height. If 0, then the H dimension of the data tensor will be used.
56 int32_t imgW; //!< Image width. If 0, then the W dimension of the data tensor will be used.
57 float stepH; //!< Step in H. If 0, then (float)imgH/h will be used where h is the H dimension of the 1st input tensor.
58 float stepW; //!< Step in W. If 0, then (float)imgW/w will be used where w is the W dimension of the 1st input tensor.
59 float offset; //!< Offset to the top left corner of each cell.
60};
61
62//!
63//! \struct RPROIParams
64//!
65//! \brief RPROIParams is used to create the RPROIPlugin instance.
66//!
67struct RPROIParams
68{
69 int32_t poolingH; //!< Height of the output in pixels after ROI pooling on feature map.
70 int32_t poolingW; //!< Width of the output in pixels after ROI pooling on feature map.
71 int32_t featureStride; //!< Feature stride; ratio of input image size to feature map size.
72 //!< Assuming that max pooling layers in the neural network use square filters.
73 int32_t preNmsTop; //!< Number of proposals to keep before applying NMS.
74 int32_t nmsMaxOut; //!< Number of remaining proposals after applying NMS.
75 int32_t anchorsRatioCount; //!< Number of anchor box ratios.
76 int32_t anchorsScaleCount; //!< Number of anchor box scales.
77 float iouThreshold; //!< IoU (Intersection over Union) threshold used for the NMS step.
78 float minBoxSize; //!< Minimum allowed bounding box size before scaling, used for anchor box calculation.
79 float spatialScale; //!< Spatial scale between the input image and the last feature map.
80};
81
82//!
83//! \struct GridAnchorParameters
84//!
85//! \brief The Anchor Generator plugin layer generates the prior boxes of designated sizes and aspect ratios across all dimensions (H x W).
86//! GridAnchorParameters defines a set of parameters for creating the plugin layer for all feature maps.
87//!
88struct GridAnchorParameters
89{
90 float minSize; //!< Scale of anchors corresponding to finest resolution.
91 float maxSize; //!< Scale of anchors corresponding to coarsest resolution.
92 float* aspectRatios; //!< List of aspect ratios to place on each grid point.
93 int32_t numAspectRatios; //!< Number of elements in aspectRatios.
94 int32_t H; //!< Height of feature map to generate anchors for.
95 int32_t W; //!< Width of feature map to generate anchors for.
96 float variance[4]; //!< Variance for adjusting the prior boxes.
97};
98
99//!
100//! \enum CodeTypeSSD
101//!
102//! \brief The type of encoding used for decoding the bounding boxes and loc_data.
103//!
104//! \deprecated Deprecated in TensorRT 10.0. DetectionOutput plugin is deprecated.
105//!
106enum class CodeTypeSSD : int32_t
107{
108 CORNER TRT_DEPRECATED_ENUM = 0, //!< Use box corners.
109 CENTER_SIZE TRT_DEPRECATED_ENUM = 1, //!< Use box centers and size.
110 CORNER_SIZE TRT_DEPRECATED_ENUM = 2, //!< Use box centers and size.
111 TF_CENTER TRT_DEPRECATED_ENUM = 3 //!< Use box centers and size but flip x and y coordinates.
112};
113
114//!
115//! \struct DetectionOutputParameters
116//!
117//! \brief The DetectionOutput plugin layer generates the detection output
118//! based on location and confidence predictions by doing non maximum suppression.
119//!
120//! This plugin first decodes the bounding boxes based on the anchors generated.
121//! It then performs non_max_suppression on the decoded bounding boxes.
122//! DetectionOutputParameters defines a set of parameters for creating the DetectionOutput plugin layer.
123//!
124//! \deprecated Deprecated in TensorRT 10.0. DetectionOutput plugin is deprecated.
125//!
126struct TRT_DEPRECATED DetectionOutputParameters
127{
128 bool shareLocation; //!< If true, bounding box are shared among different classes.
129 bool varianceEncodedInTarget; //!< If true, variance is encoded in target.
130 //!< Otherwise we need to adjust the predicted offset accordingly.
131 int32_t backgroundLabelId; //!< Background label ID. If there is no background class, set it as -1.
132 int32_t numClasses; //!< Number of classes to be predicted.
133 int32_t topK; //!< Number of boxes per image with top confidence scores that are fed
134 //!< into the NMS algorithm.
135 int32_t keepTopK; //!< Number of total bounding boxes to be kept per image after NMS step.
136 float confidenceThreshold; //!< Only consider detections whose confidences are larger than a threshold.
137 float nmsThreshold; //!< Threshold to be used in NMS.
138 CodeTypeSSD codeType; //!< Type of coding method for bbox.
139 int32_t inputOrder[3]; //!< Specifies the order of inputs {loc_data, conf_data, priorbox_data}.
140 bool confSigmoid; //!< Set to true to calculate sigmoid of confidence scores.
141 bool isNormalized; //!< Set to true if bounding box data is normalized by the network.
142 bool isBatchAgnostic{true}; //!< Defaults to true. Set to false if prior boxes are unique per batch.
143};
144
145//!
146//! \brief When performing yolo9000, softmaxTree is helping to do softmax on confidence scores,
147//! for element to get the precise classification through word-tree structured classification definition.
148//!
149struct softmaxTree
150{
151 int32_t* leaf;
152 int32_t n;
153 int32_t* parent;
154 int32_t* child;
155 int32_t* group;
156 char** name;
157 int32_t groups;
158 int32_t* groupSize;
159 int32_t* groupOffset;
160};
161
162//!
163//! \brief The Region plugin layer performs region proposal calculation.
164//!
165//! Generate 5 bounding boxes per cell (for yolo9000, generate 3 bounding boxes per cell).
166//! For each box, calculating its probabilities of objects detections from 80 pre-defined classifications
167//! (yolo9000 has 9418 pre-defined classifications, and these 9418 items are organized as work-tree structure).
168//! RegionParameters defines a set of parameters for creating the Region plugin layer.
169//!
170struct RegionParameters
171{
172 int32_t num; //!< Number of predicted bounding box for each grid cell.
173 int32_t coords; //!< Number of coordinates for a bounding box.
174 int32_t classes; //!< Number of classifications to be predicted.
175 softmaxTree* smTree; //!< Helping structure to do softmax on confidence scores.
176};
177
178//!
179//! \brief The NMSParameters are used by the BatchedNMSPlugin for performing
180//! the non_max_suppression operation over boxes for object detection networks.
181//!
182//! \deprecated Deprecated in TensorRT 10.0. BatchedNMSPlugin plugin is deprecated.
183//!
184struct TRT_DEPRECATED NMSParameters
185{
186 bool shareLocation; //!< If set to true, the boxes inputs are shared across all classes.
187 //!< If set to false, the boxes input should account for per class box data.
188 int32_t backgroundLabelId; //!< Label ID for the background class.
189 //!< If there is no background class, set it as -1
190 int32_t numClasses; //!< Number of classes in the network.
191 int32_t topK; //!< Number of bounding boxes to be fed into the NMS step.
192 int32_t keepTopK; //!< Number of total bounding boxes to be kept per image after NMS step.
193 //!< Should be less than or equal to the topK value.
194 float scoreThreshold; //!< Scalar threshold for score (low scoring boxes are removed).
195 float iouThreshold; //!< A scalar threshold for IOU (new boxes that have high IOU overlap
196 //!< with previously selected boxes are removed).
197 bool isNormalized; //!< Set to false, if the box coordinates are not normalized,
198 //!< i.e. not in the range [0,1]. Defaults to false.
199};
200
201} // namespace plugin
202} // namespace nvinfer1
203
204#endif // NV_INFER_PLUGIN_UTILS_H
205 