NVIDIA DeepStream SDK API Reference

4.0.2 Release

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nvdsinfer_custom_impl.h File Reference

Detailed Description

Copyright (c) 2017-2019, NVIDIA CORPORATION.

All rights reserved.

NVIDIA Corporation and its licensors retain all intellectual property and proprietary rights in and to this software, related documentation and any modifications thereto. Any use, reproduction, disclosure or distribution of this software and related documentation without an express license agreement from NVIDIA Corporation is strictly prohibited.

NVIDIA DeepStream Specification for Custom Method Implementations for custom models

Description: This file specifies the APIs and function definitions to implement custom methods required by DeepStream nvinfer GStreamer plugin to infer using custom models.

All the custom functionality must be implemented in an independent shared library. This library will be dynamically loaded (dlopen()) by "nvinfer" and implemented custom methods will be called as required. The custom library can be specified in the nvinfer element configuration file through the custom-lib-name property.

Custom Detector Output Parsing Function

This section describes the custom bounding box parsing function for custom detector models.

The custom parsing function should be of the type NvDsInferParseCustomFunc. The custom parsing function can be specified in the nvinfer element configuration file using the property parse-bbox-func-name (Name of the parsing function) in addition to custom-lib-name and setting parse-func to 0 (custom).

The nvinfer plugin loads the library and looks for the custom parsing function symbol. The function is called after each inference call is executed.

The macro CHECK_CUSTOM_PARSE_FUNC_PROTOTYPE() can be called after the function definition to validate the function definition.

TensorRT Plugin Factory interface for DeepStream

Based on the type of the model (Caffe or UFF), the library must implement one of the two functions NvDsInferPluginFactoryCaffeGet or NvDsInferPluginFactoryUffGet. During model parsing, the DeepStream "nvinfer" plugin will look for one of the two symbols in the custom library based on the model framework. If the symbol is found, the plugin will call the "Get" function to get a pointer to PluginFactory instance required for parsing.

If the IPluginFactory needs to be used during deserialization of cuda engines, the library must implement NvDsInferPluginFactoryRuntimeGet.

All the three Get functions have a corresponding Destroy functions which will be called if defined when the returned PluginFactory need to be destroyed.

Libraries implementing this interface must use the same function names as in the header file. The "nvinfer" plugin will dynamically load the library and look for the same symbol names.

Refer the FasterRCNN sample provided with the SDK for a sample implementation of the interface.

Input Layers Initialization

By default "nvinfer" works with networks having only one input layer for video frames. If the network has more than one input layer, the custom library can implement NvDsInferInitializeInputLayers interface for initializing the other input layers. "nvinfer" assumes that the other input layers have static input information and hence this method is called only once before the first inference.

Refer the FasterRCNN sample provided with the SDK for a sample implementation of the interface.

Interface for building Custom Networks

The NvDsInferCudaEngineGet interface can be used to create and build custom networks not directly supported by nvinfer.

The "nvinfer" plugin will dynamically load the custom library and look for the "NvDsInferCudaEngineGet" symbol.

The interface implementation shall build and return the CudaEngine interface using the supplied nvinfer1::IBuilder instance. The builder instance will already be configured with properties like MaxBatchSize, MaxWorkspaceSize, INT8/FP16 precision parameters etc. The builder instance is managed by "nvinfer" and should not be destroyed by the implementation.

The path to the config file for nvinfer instance is supplied to the interface. Custom properties required by the model can be added to the config file and parsed in the interface implementation.

Definition in file nvdsinfer_custom_impl.h.

Go to the source code of this file.

Data Structures

struct  NvDsInferParseDetectionParams
 Holds the detection parameters required for parsing objects. More...
 
union  NvDsInferPluginFactoryCaffe
 Holds the pointer to a heap allocated Plugin Factory object required during Caffemodel parsing. More...
 
union  NvDsInferPluginFactoryUff
 Holds the pointer to a heap allocated Plugin Factory object required during UFF model parsing. More...
 

Macros

#define CHECK_CUSTOM_PARSE_FUNC_PROTOTYPE(customParseFunc)
 Macro to validate the custom parser function definition. More...
 
#define CHECK_CUSTOM_CLASSIFIER_PARSE_FUNC_PROTOTYPE(customParseFunc)
 Macro to validate the classifier custom parser function definition. More...
 

Typedefs

typedef bool(* NvDsInferParseCustomFunc )(std::vector< NvDsInferLayerInfo > const &outputLayersInfo, NvDsInferNetworkInfo const &networkInfo, NvDsInferParseDetectionParams const &detectionParams, std::vector< NvDsInferObjectDetectionInfo > &objectList)
 Function definition for the custom bounding box parsing function. More...
 
typedef bool(* NvDsInferClassiferParseCustomFunc )(std::vector< NvDsInferLayerInfo > const &outputLayersInfo, NvDsInferNetworkInfo const &networkInfo, float classifierThreshold, std::vector< NvDsInferAttribute > &attrList, std::string &descString)
 Function definition for the custom classifier output parsing function. More...
 
typedef struct
_NvDsInferContextInitParams 
NvDsInferContextInitParams
 

Enumerations

enum  NvDsInferPluginFactoryType {
  PLUGIN_FACTORY,
  PLUGIN_FACTORY_EXT,
  PLUGIN_FACTORY_V2
}
 Specifies the type of the Plugin Factory. More...
 

Functions

bool NvDsInferPluginFactoryCaffeGet (NvDsInferPluginFactoryCaffe &pluginFactory, NvDsInferPluginFactoryType &type)
 Returns an instance of a newly allocated Plugin Factory interface to be used during parsing of caffe models. More...
 
void NvDsInferPluginFactoryCaffeDestroy (NvDsInferPluginFactoryCaffe &pluginFactory)
 Destroy the Plugin Factory instance returned in NvDsInferPluginFactoryCaffeGet More...
 
bool NvDsInferPluginFactoryUffGet (NvDsInferPluginFactoryUff &pluginFactory, NvDsInferPluginFactoryType &type)
 Returns an instance of a newly allocated Plugin Factory interface to be used during parsing of UFF models. More...
 
void NvDsInferPluginFactoryUffDestroy (NvDsInferPluginFactoryUff &pluginFactory)
 Destroy the Plugin Factory instance returned in NvDsInferPluginFactoryUffGet More...
 
bool NvDsInferPluginFactoryRuntimeGet (nvinfer1::IPluginFactory *&pluginFactory)
 Returns an instance of a newly allocated Plugin Factory interface to be used during parsing deserialization of cuda engines. More...
 
void NvDsInferPluginFactoryRuntimeDestroy (nvinfer1::IPluginFactory *pluginFactory)
 Destroy the PluginFactory instance returned in NvDsInferPluginFactoryRuntimeGet More...
 
bool NvDsInferInitializeInputLayers (std::vector< NvDsInferLayerInfo > const &inputLayersInfo, NvDsInferNetworkInfo const &networkInfo, unsigned int maxBatchSize)
 Initialize the input layers for inference. More...
 
bool NvDsInferCudaEngineGet (nvinfer1::IBuilder *builder, NvDsInferContextInitParams *initParams, nvinfer1::DataType dataType, nvinfer1::ICudaEngine *&cudaEngine)
 Build and return CudaEngine for custom models. More...
 

Macro Definition Documentation

#define CHECK_CUSTOM_CLASSIFIER_PARSE_FUNC_PROTOTYPE (   customParseFunc)
Value:
static void checkFunc_ ## customParseFunc (NvDsInferClassiferParseCustomFunc func = customParseFunc) \
{ checkFunc_ ## customParseFunc (); }; \
extern "C" bool customParseFunc (std::vector<NvDsInferLayerInfo> const &outputLayersInfo, \
NvDsInferNetworkInfo const &networkInfo, \
float classifierThreshold, \
std::vector<NvDsInferAttribute> &attrList, \
std::string &descString);
bool(* NvDsInferClassiferParseCustomFunc)(std::vector< NvDsInferLayerInfo > const &outputLayersInfo, NvDsInferNetworkInfo const &networkInfo, float classifierThreshold, std::vector< NvDsInferAttribute > &attrList, std::string &descString)
Function definition for the custom classifier output parsing function.
Holds information about the model network.
Definition: nvdsinfer.h:94

Macro to validate the classifier custom parser function definition.

Should be called after defining the function.

Definition at line 181 of file nvdsinfer_custom_impl.h.

#define CHECK_CUSTOM_PARSE_FUNC_PROTOTYPE (   customParseFunc)
Value:
static void checkFunc_ ## customParseFunc (NvDsInferParseCustomFunc func = customParseFunc) \
{ checkFunc_ ## customParseFunc (); }; \
extern "C" bool customParseFunc (std::vector<NvDsInferLayerInfo> const &outputLayersInfo, \
NvDsInferNetworkInfo const &networkInfo, \
NvDsInferParseDetectionParams const &detectionParams, \
std::vector<NvDsInferObjectDetectionInfo> &objectList);
Holds the detection parameters required for parsing objects.
bool(* NvDsInferParseCustomFunc)(std::vector< NvDsInferLayerInfo > const &outputLayersInfo, NvDsInferNetworkInfo const &networkInfo, NvDsInferParseDetectionParams const &detectionParams, std::vector< NvDsInferObjectDetectionInfo > &objectList)
Function definition for the custom bounding box parsing function.
Holds information about the model network.
Definition: nvdsinfer.h:94

Macro to validate the custom parser function definition.

Should be called after defining the function.

Definition at line 150 of file nvdsinfer_custom_impl.h.

Typedef Documentation

typedef bool(* NvDsInferClassiferParseCustomFunc)(std::vector< NvDsInferLayerInfo > const &outputLayersInfo, NvDsInferNetworkInfo const &networkInfo, float classifierThreshold, std::vector< NvDsInferAttribute > &attrList, std::string &descString)

Function definition for the custom classifier output parsing function.

Parameters
[in]outputLayersInfoVector containing information on the output layers of the model.
[in]networkInfoNetwork information.
[in]classifierThresholdClassification confidence threshold
[out]attrListReference to a vector in which the function should add the parsed attributes.
[out]descStringReference to a string object in which the function may place a description string.

Definition at line 170 of file nvdsinfer_custom_impl.h.

typedef bool(* NvDsInferParseCustomFunc)(std::vector< NvDsInferLayerInfo > const &outputLayersInfo, NvDsInferNetworkInfo const &networkInfo, NvDsInferParseDetectionParams const &detectionParams, std::vector< NvDsInferObjectDetectionInfo > &objectList)

Function definition for the custom bounding box parsing function.

Parameters
[in]outputLayersInfoVector containing information on the output layers of the model.
[in]networkInfoNetwork information.
[in]detectionParamsDetection parameters required for parsing objects.
[out]objectListReference to a vector in which the function should add the parsed objects.

Definition at line 140 of file nvdsinfer_custom_impl.h.

Enumeration Type Documentation

Specifies the type of the Plugin Factory.

Enumerator
PLUGIN_FACTORY 

nvcaffeparser1::IPluginFactory / nvuffparser::IPluginFactory

PLUGIN_FACTORY_EXT 

nvcaffeparser1::IPluginFactoryExt / nvuffparser::IPluginFactoryExt

PLUGIN_FACTORY_V2 

Only for caffe models.

nvcaffeparser1::IPluginFactoryV2

Definition at line 193 of file nvdsinfer_custom_impl.h.

Function Documentation

bool NvDsInferCudaEngineGet ( nvinfer1::IBuilder *  builder,
NvDsInferContextInitParams initParams,
nvinfer1::DataType  dataType,
nvinfer1::ICudaEngine *&  cudaEngine 
)

Build and return CudaEngine for custom models.

The implementation of this interface should build the nvinfer1::ICudaEngine instance using supplied nvinfer1::IBuilder instance. The builder instance is managed by the caller. The implementation should not destroy the instance.

Properties like MaxBatchSize, MaxWorkspaceSize, INT8/FP16 precision parameters, DLA parameters if applicable will already be set on the builder before being passed to the interface. The corresponding Get functions of nvinfer1::IBuilder interface can be used to get the property values.

The implementation should make sure not to reduce the MaxBatchSize of the returned CudaEngine.

Parameters
[in]buildernvinfer1::IBuilder instance
[in]initParamsPointer to the structure used for initializing the NvDsInferContext instance.
[in]dataTypeData precision
[out]cudaEnginePointer to the built nvinfer1::ICudaEngine instance.
Returns
Boolean indicating that engine build was successful.
bool NvDsInferInitializeInputLayers ( std::vector< NvDsInferLayerInfo > const &  inputLayersInfo,
NvDsInferNetworkInfo const &  networkInfo,
unsigned int  maxBatchSize 
)

Initialize the input layers for inference.

This function is only called once during before the first inference call.

Parameters
[in]inputLayersInfoVector containing information on the input layers of the model. This does not contain the NvDsInferLayerInfo structure for the layer for video frame input.
[in]networkInfoNetwork information.
[in]maxBatchSizeMaximum batch size for inference. The buffers for input layers are allocated for this batch size.
Returns
Boolean indicating that input layers were successfully initialized.
void NvDsInferPluginFactoryCaffeDestroy ( NvDsInferPluginFactoryCaffe pluginFactory)

Destroy the Plugin Factory instance returned in NvDsInferPluginFactoryCaffeGet

Parameters
[in]pluginFactoryReference to NvDsInferPluginFactoryCaffe union holding the pointer to the Plugin Factory instance returned in NvDsInferPluginFactoryCaffeGet.
bool NvDsInferPluginFactoryCaffeGet ( NvDsInferPluginFactoryCaffe pluginFactory,
NvDsInferPluginFactoryType type 
)

Returns an instance of a newly allocated Plugin Factory interface to be used during parsing of caffe models.

The function must set the correct type and the correct field inside the NvDsInferPluginFactoryCaffe union based on the type of the Plugin Factory (i.e. one of pluginFactory, pluginFactoryExt or pluginFactoryV2).

Parameters
[out]pluginFactoryA reference to the NvDsInferPluginFactoryCaffe union
[out]typeEnum indicating the type of the returned Plugin Factory instance (i.e. the valid field in the NvDsInferPluginFactoryCaffe union)
Returns
Boolean indicating that the creation of the Plugin Factory was successful.
void NvDsInferPluginFactoryRuntimeDestroy ( nvinfer1::IPluginFactory *  pluginFactory)

Destroy the PluginFactory instance returned in NvDsInferPluginFactoryRuntimeGet

Parameters
[in]pluginFactoryPluginFactory instance returned in NvDsInferPluginFactoryRuntimeGet
bool NvDsInferPluginFactoryRuntimeGet ( nvinfer1::IPluginFactory *&  pluginFactory)

Returns an instance of a newly allocated Plugin Factory interface to be used during parsing deserialization of cuda engines.

Parameters
[out]pluginFactoryA reference to nvinfer1::IPluginFactory* in which the function must place the pointer to the instance.
Returns
Boolean indicating that the creation of the Plugin Factory was successful.
void NvDsInferPluginFactoryUffDestroy ( NvDsInferPluginFactoryUff pluginFactory)

Destroy the Plugin Factory instance returned in NvDsInferPluginFactoryUffGet

Parameters
[in]pluginFactoryReference to NvDsInferPluginFactoryUff union holding the pointer to the Plugin Factory instance returned in NvDsInferPluginFactoryUffGet.
bool NvDsInferPluginFactoryUffGet ( NvDsInferPluginFactoryUff pluginFactory,
NvDsInferPluginFactoryType type 
)

Returns an instance of a newly allocated Plugin Factory interface to be used during parsing of UFF models.

The function must set the correct type and the correct field inside the NvDsInferPluginFactoryUff union based on the type of the Plugin Factory (i.e. one of pluginFactory or pluginFactoryExt)

Parameters
[out]pluginFactoryA reference to the NvDsInferPluginFactoryUff union
[out]typeEnum indicating the type of the returned Plugin Factory instance (i.e. the valid field in the NvDsInferPluginFactoryUff union)
Returns
Boolean indicating that the creation of the Plugin Factory was successful.