NVIDIA DeepStream SDK API Reference

9.1 Release
sources/includes/nvdsinfer_custom_impl.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2017-2026 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 
115 #ifndef _NVDSINFER_CUSTOM_IMPL_H_
116 #define _NVDSINFER_CUSTOM_IMPL_H_
117 
118 #include <string>
119 #include <vector>
120 
121 #include "nvdsinfer.h"
122 #include <NvInfer.h>
123 #include <NvInferRuntime.h>
124 #include <NvOnnxParser.h>
125 
126 /*
127  * C++ interfaces
128  */
129 #ifdef __cplusplus
130 
140 class IModelParser
141 {
142 public:
143  IModelParser() = default;
146  virtual ~IModelParser() = default;
147 
156  virtual NvDsInferStatus parseModel(
157  nvinfer1::INetworkDefinition& network) = 0;
158 
162  virtual bool hasFullDimsSupported() const = 0;
163 
168  virtual const char* getModelName() const = 0;
169 };
170 #endif
171 
172 /*
173  * C interfaces
174  */
175 
176 #ifdef __cplusplus
177 extern "C"
178 {
179 #endif
180 
184 typedef struct
185 {
189  unsigned int numClassesConfigured;
195  std::vector<float> perClassPreclusterThreshold;
196  /* Per-class threshold to be applied after the clustering operation. */
197  std::vector<float> perClassPostclusterThreshold;
198 
201  std::vector<float> &perClassThreshold = perClassPreclusterThreshold;
203 
215 typedef bool (* NvDsInferParseCustomFunc) (
216  std::vector<NvDsInferLayerInfo> const &outputLayersInfo,
217  NvDsInferNetworkInfo const &networkInfo,
218  NvDsInferParseDetectionParams const &detectionParams,
219  std::vector<NvDsInferObjectDetectionInfo> &objectList);
220 
225 #define CHECK_CUSTOM_PARSE_FUNC_PROTOTYPE(customParseFunc) \
226  static void checkFunc_ ## customParseFunc (NvDsInferParseCustomFunc func = customParseFunc) \
227  { checkFunc_ ## customParseFunc (); }; \
228  extern "C" bool customParseFunc (std::vector<NvDsInferLayerInfo> const &outputLayersInfo, \
229  NvDsInferNetworkInfo const &networkInfo, \
230  NvDsInferParseDetectionParams const &detectionParams, \
231  std::vector<NvDsInferObjectDetectionInfo> &objectList);
232 
245  std::vector<NvDsInferLayerInfo> const &outputLayersInfo,
246  NvDsInferNetworkInfo const &networkInfo,
247  NvDsInferParseDetectionParams const &detectionParams,
248  std::vector<NvDsInferInstanceMaskInfo> &objectList);
249 
254 #define CHECK_CUSTOM_INSTANCE_MASK_PARSE_FUNC_PROTOTYPE(customParseFunc) \
255  static void checkFunc_ ## customParseFunc (NvDsInferInstanceMaskParseCustomFunc func = customParseFunc) \
256  { checkFunc_ ## customParseFunc (); }; \
257  extern "C" bool customParseFunc (std::vector<NvDsInferLayerInfo> const &outputLayersInfo, \
258  NvDsInferNetworkInfo const &networkInfo, \
259  NvDsInferParseDetectionParams const &detectionParams, \
260  std::vector<NvDsInferInstanceMaskInfo> &objectList);
261 
276  std::vector<NvDsInferLayerInfo> const &outputLayersInfo,
277  NvDsInferNetworkInfo const &networkInfo,
278  float classifierThreshold,
279  std::vector<NvDsInferAttribute> &attrList,
280  std::string &descString);
281 
286 #define CHECK_CUSTOM_CLASSIFIER_PARSE_FUNC_PROTOTYPE(customParseFunc) \
287  static void checkFunc_ ## customParseFunc (NvDsInferClassiferParseCustomFunc func = customParseFunc) \
288  { checkFunc_ ## customParseFunc (); }; \
289  extern "C" bool customParseFunc (std::vector<NvDsInferLayerInfo> const &outputLayersInfo, \
290  NvDsInferNetworkInfo const &networkInfo, \
291  float classifierThreshold, \
292  std::vector<NvDsInferAttribute> &attrList, \
293  std::string &descString);
294 
313  std::vector<NvDsInferLayerInfo> const &outputLayersInfo,
314  NvDsInferNetworkInfo const &networkInfo,
315  float segmentationThreshold,
316  unsigned int numClasses,
317  int* classificationMap,
318  float*& classProbabilityMap);
319 
324 #define CHECK_CUSTOM_SEM_SEGMENTATION_PARSE_FUNC_PROTOTYPE(customParseFunc) \
325  static void checkFunc_ ## customParseFunc (NvDsInferSemSegmentationParseCustomFunc func = customParseFunc) \
326  { checkFunc_ ## customParseFunc (); }; \
327  extern "C" bool customParseFunc (std::vector<NvDsInferLayerInfo> const &outputLayersInfo, \
328  NvDsInferNetworkInfo const &networkInfo, \
329  float segmentationThreshold, \
330  unsigned int numClasses, \
331  int* classificationMap, \
332  float*& classProbabilityMap);
333 
335 
368  nvinfer1::IBuilder * const builder, nvinfer1::IBuilderConfig * const builderConfig,
369  const NvDsInferContextInitParams * const initParams,
370  nvinfer1::DataType dataType,
371  nvinfer1::ICudaEngine *& cudaEngine);
372 
377 #define CHECK_CUSTOM_ENGINE_CREATE_FUNC_PROTOTYPE(customEngineCreateFunc) \
378  static void checkFunc_ ## customEngineCreateFunc (NvDsInferEngineCreateCustomFunc = customEngineCreateFunc) \
379  { checkFunc_ ## customEngineCreateFunc(); }; \
380  extern "C" bool customEngineCreateFunc ( \
381  nvinfer1::IBuilder * const builder, \
382  nvinfer1::IBuilderConfig * const builderConfig, \
383  const NvDsInferContextInitParams * const initParams, \
384  nvinfer1::DataType dataType, \
385  nvinfer1::ICudaEngine *& cudaEngine);
386 
397 bool NvDsInferPluginFactoryRuntimeGet (nvinfer1::IPluginFactory *& pluginFactory);
398 
406 void NvDsInferPluginFactoryRuntimeDestroy (nvinfer1::IPluginFactory * pluginFactory);
407 
423 bool NvDsInferInitializeInputLayers (std::vector<NvDsInferLayerInfo> const &inputLayersInfo,
424  NvDsInferNetworkInfo const &networkInfo,
425  unsigned int maxBatchSize);
430 bool NvDsInferCudaEngineGet(nvinfer1::IBuilder *builder,
431  NvDsInferContextInitParams *initParams,
432  nvinfer1::DataType dataType,
433  nvinfer1::ICudaEngine *& cudaEngine)
434  __attribute__((deprecated("Use 'engine-create-func-name' config parameter instead")));
435 
445 IModelParser* NvDsInferCreateModelParser(
446  const NvDsInferContextInitParams* initParams);
447 
448 #ifdef __cplusplus
449 }
450 #endif
451 
452 #endif
453 
NvDsInferClassiferParseCustomFunc
bool(* NvDsInferClassiferParseCustomFunc)(std::vector< NvDsInferLayerInfo > const &outputLayersInfo, NvDsInferNetworkInfo const &networkInfo, float classifierThreshold, std::vector< NvDsInferAttribute > &attrList, std::string &descString)
Type definition for the custom classifier output parsing function.
Definition: sources/includes/nvdsinfer_custom_impl.h:275
NvDsInferSemSegmentationParseCustomFunc
bool(* NvDsInferSemSegmentationParseCustomFunc)(std::vector< NvDsInferLayerInfo > const &outputLayersInfo, NvDsInferNetworkInfo const &networkInfo, float segmentationThreshold, unsigned int numClasses, int *classificationMap, float *&classProbabilityMap)
Type definition for the custom semantic segmentation output parsing function.
Definition: sources/includes/nvdsinfer_custom_impl.h:312
NvDsInferCreateModelParser
IModelParser * NvDsInferCreateModelParser(const NvDsInferContextInitParams *initParams)
Create a customized neural network parser for user-defined models.
_NvDsInferContextInitParams::maxBatchSize
unsigned int maxBatchSize
Holds the maximum number of frames to be inferred together in a batch.
Definition: sources/includes/nvdsinfer_context.h:296
ds3d::DataType
DataType
Definition: sources/includes/ds3d/common/idatatype.h:82
NvDsInferParseDetectionParams::numClassesConfigured
unsigned int numClassesConfigured
Holds the number of classes requested to be parsed, starting with class ID 0.
Definition: sources/includes/nvdsinfer_custom_impl.h:189
NvDsInferPluginFactoryRuntimeDestroy
void NvDsInferPluginFactoryRuntimeDestroy(nvinfer1::IPluginFactory *pluginFactory)
Destroys a Plugin Factory instance created by NvDsInferPluginFactoryRuntimeGet().
NvDsInferInstanceMaskParseCustomFunc
bool(* NvDsInferInstanceMaskParseCustomFunc)(std::vector< NvDsInferLayerInfo > const &outputLayersInfo, NvDsInferNetworkInfo const &networkInfo, NvDsInferParseDetectionParams const &detectionParams, std::vector< NvDsInferInstanceMaskInfo > &objectList)
Type definition for the custom bounding box and instance mask parsing function.
Definition: sources/includes/nvdsinfer_custom_impl.h:244
__attribute__
__attribute__((weak)) gchar *g_nvds_last_error_message
NvDsInferParseDetectionParams
Holds the detection parameters required for parsing objects.
Definition: sources/includes/nvdsinfer_custom_impl.h:184
nvdsinfer.h
NvDsInferInitializeInputLayers
bool NvDsInferInitializeInputLayers(std::vector< NvDsInferLayerInfo > const &inputLayersInfo, NvDsInferNetworkInfo const &networkInfo, unsigned int maxBatchSize)
Initializes the input layers for inference.
NvDsInferNetworkInfo
Holds information about the model network.
Definition: sources/includes/nvdsinfer.h:119
NvDsInferParseDetectionParams::perClassPostclusterThreshold
std::vector< float > perClassPostclusterThreshold
Definition: sources/includes/nvdsinfer_custom_impl.h:197
NvDsInferParseDetectionParams::perClassPreclusterThreshold
std::vector< float > perClassPreclusterThreshold
Holds a per-class vector of detection confidence thresholds to be applied prior to the clustering ope...
Definition: sources/includes/nvdsinfer_custom_impl.h:195
NvDsInferPluginFactoryRuntimeGet
bool NvDsInferPluginFactoryRuntimeGet(nvinfer1::IPluginFactory *&pluginFactory)
Returns a new instance of a Plugin Factory interface to be used during parsing deserialization of CUD...
NvDsInferEngineCreateCustomFunc
bool(* NvDsInferEngineCreateCustomFunc)(nvinfer1::IBuilder *const builder, nvinfer1::IBuilderConfig *const builderConfig, const NvDsInferContextInitParams *const initParams, nvinfer1::DataType dataType, nvinfer1::ICudaEngine *&cudaEngine)
Type definition for functions that build and return a CudaEngine for custom models.
Definition: sources/includes/nvdsinfer_custom_impl.h:367
NvDsInferCudaEngineGet
bool NvDsInferCudaEngineGet(nvinfer1::IBuilder *builder, NvDsInferContextInitParams *initParams, nvinfer1::DataType dataType, nvinfer1::ICudaEngine *&cudaEngine) __attribute__((deprecated("Use 'engine-create-func-name' config parameter instead")))
The NvDsInferCudaEngineGet interface has been deprecated and has been replaced by NvDsInferEngineCrea...
_NvDsInferContextInitParams
Holds the initialization parameters required for the NvDsInferContext interface.
Definition: sources/includes/nvdsinfer_context.h:246
NvDsInferParseCustomFunc
bool(* NvDsInferParseCustomFunc)(std::vector< NvDsInferLayerInfo > const &outputLayersInfo, NvDsInferNetworkInfo const &networkInfo, NvDsInferParseDetectionParams const &detectionParams, std::vector< NvDsInferObjectDetectionInfo > &objectList)
Type definition for the custom bounding box parsing function.
Definition: sources/includes/nvdsinfer_custom_impl.h:215
NvDsInferStatus
NvDsInferStatus
Enum for the status codes returned by NvDsInferContext.
Definition: sources/includes/nvdsinfer.h:231