|
NVIDIA DeepStream SDK API Reference
|
6.4 Release
|
Go to the documentation of this file.
12 #ifndef __NVDSINFER_CONTEXT_IMPL_H__
13 #define __NVDSINFER_CONTEXT_IMPL_H__
16 #include <condition_variable>
25 #include <NvCaffeParser.h>
27 #include <cuda_runtime_api.h>
29 #pragma GCC diagnostic push
31 #pragma GCC diagnostic ignored "-Wclass-memaccess"
34 #include <opencv2/objdetect/objdetect.hpp>
36 #pragma GCC diagnostic pop
60 unsigned int m_BatchSize = 0;
61 std::unique_ptr<CudaEvent> m_OutputCopyDoneEvent =
nullptr;
62 bool m_BuffersWithContext =
true;
73 const NvDsInferBatchDimsLayerInfo& layerInfo,
int id = 0);
80 bool setScaleOffsets(
float scale,
const std::vector<float>& offsets = {});
88 void* devBuf,
CudaStream& mainStream, CudaEvent* waitingEvent);
102 NvDsInferBatchDimsLayerInfo m_NetworkInputLayer;
103 float m_Scale = 1.0f;
104 std::vector<float> m_ChannelMeans;
105 std::string m_MeanFile;
107 std::unique_ptr<CudaStream> m_PreProcessStream;
109 std::shared_ptr<CudaEvent> m_PreProcessCompleteEvent;
110 std::unique_ptr<CudaDeviceBuffer> m_MeanDataBuffer;
146 const std::vector<std::vector<std::string>>&
getLabels()
const
169 const std::vector<NvDsInferLayerInfo>& outputLayers,
219 const std::vector<NvDsInferLayerInfo>& outputLayers,
222 bool parseBoundingBox(
223 std::vector<NvDsInferLayerInfo>
const& outputLayersInfo,
226 std::vector<NvDsInferObjectDetectionInfo>& objectList);
228 std::vector<int> nonMaximumSuppression
229 (std::vector<std::pair<float, int>>& scoreIndex,
230 std::vector<NvDsInferParseObjectInfo>& bbox,
231 const float nmsThreshold);
238 const std::vector<NvDsInferLayerInfo>& outputLayers,
241 std::vector<NvDsInferObjectDetectionInfo> &objectList);
242 void filterTopKOutputs(
const int topK,
243 std::vector<NvDsInferObjectDetectionInfo> &objectList);
247 bool m_UseDBScan = false;
248 std::shared_ptr<NvDsInferDBScan> m_DBScanHandle;
252 uint32_t m_NumDetectedClasses = 0;
259 std::vector<NvDsInferObjectDetectionInfo> m_ObjectList;
262 std::vector<std::vector<cv::Rect>> m_PerClassCvRectList;
265 std::vector<std::vector<NvDsInferObjectDetectionInfo>> m_PerClassObjectList;
283 const std::vector<NvDsInferLayerInfo>& outputLayers,
288 const std::vector<NvDsInferLayerInfo>& outputLayers,
291 std::vector<NvDsInferInstanceMaskInfo> &objectList);
292 void filterTopKOutputs(
const int topK,
293 std::vector<NvDsInferInstanceMaskInfo> &objectList);
299 uint32_t m_NumDetectedClasses = 0;
302 std::vector<NvDsInferDetectionParams> m_PerClassDetectionParams;
306 std::vector<NvDsInferInstanceMaskInfo> m_InstanceMaskList;
308 std::vector<std::vector<NvDsInferInstanceMaskInfo>> m_PerClassInstanceMaskList;
325 const std::vector<NvDsInferLayerInfo>& outputLayers,
329 const std::vector<NvDsInferLayerInfo>& outputLayers,
332 bool parseAttributesFromSoftmaxLayers(
333 std::vector<NvDsInferLayerInfo>
const& outputLayersInfo,
335 std::vector<NvDsInferAttribute>& attrList, std::string& attrString);
338 float m_ClassifierThreshold = 0.0f;
354 const std::vector<NvDsInferLayerInfo>& outputLayers,
358 const std::vector<NvDsInferLayerInfo>& outputLayers,
362 float m_SegmentationThreshold = 0.0f;
377 const std::vector<NvDsInferLayerInfo>& outputLayers,
383 class BackendContext;
414 void fillLayersInfo(std::vector<NvDsInferLayerInfo> &layersInfo)
override;
416 const std::vector<std::vector<std::string>>& getLabels()
override;
417 void destroy()
override;
427 std::unique_ptr<BackendContext> generateBackendContext(
429 std::unique_ptr<BackendContext> buildModel(
431 bool deserializeEngineAndBackend(
const std::string enginePath,
int dla,
432 std::shared_ptr<TrtEngine>& engine,
433 std::unique_ptr<BackendContext>& backend);
443 static const int INPUT_LAYER_INDEX = 0;
447 uint32_t m_UniqueID = 0;
448 uint32_t m_GpuID = 0;
452 std::unique_ptr<BackendContext> m_BackendContext;
453 std::shared_ptr<DlLibHandle> m_CustomLibHandle;
455 std::unique_ptr<InferPreprocessor> m_Preprocessor;
456 std::unique_ptr<InferPostprocessor> m_Postprocessor;
458 uint32_t m_MaxBatchSize = 0;
463 std::vector<NvDsInferBatchDimsLayerInfo> m_AllLayerInfo;
464 std::vector<NvDsInferBatchDimsLayerInfo> m_OutputLayerInfo;
465 NvDsInferBatchDimsLayerInfo m_InputImageLayerInfo;
467 std::vector<void *> m_BindingBuffers;
468 std::vector<std::unique_ptr<CudaDeviceBuffer>> m_InputDeviceBuffers;
471 std::vector<std::shared_ptr<NvDsInferBatch>> m_Batches;
472 std::mutex m_BatchesMutex;
480 std::unique_ptr<CudaStream> m_InferStream;
481 std::unique_ptr<CudaStream> m_PostprocessStream;
484 std::shared_ptr<CudaEvent> m_InputConsumedEvent;
487 std::shared_ptr<CudaEvent> m_InferCompleteEvent;
491 bool m_Initialized =
false;
492 uint32_t m_AutoIncMem = 1;
493 double m_MaxGPUMem = 99;
494 bool m_DumpIpTensor =
false;
495 std::string m_DumpIpTensorFilePath =
" ";
496 bool m_OverwriteIpTensor =
false;
497 std::string m_OverwriteIpTensorFilePath =
" ";
498 std::ifstream m_OverwriteIpTensorFile;
503 #define printMsg(level, tag_str, fmt, ...) \
505 char* baseName = strrchr((char*)__FILE__, '/'); \
506 baseName = (baseName) ? (baseName + 1) : (char*)__FILE__; \
507 char logMsgBuffer[5 * _MAX_STR_LENGTH + 1]; \
508 snprintf(logMsgBuffer, 5 * _MAX_STR_LENGTH, \
509 tag_str " NvDsInferContextImpl::%s() <%s:%d> [UID = %d]: " fmt, \
510 __func__, baseName, __LINE__, m_UniqueID, ##__VA_ARGS__); \
511 if (m_LoggingFunc) { \
512 m_LoggingFunc(level, logMsgBuffer); \
514 fprintf(stderr, "%s\n", logMsgBuffer); \
518 #define printError(fmt, ...) \
520 printMsg (NVDSINFER_LOG_ERROR, "Error in", fmt, ##__VA_ARGS__); \
523 #define printWarning(fmt, ...) \
525 printMsg (NVDSINFER_LOG_WARNING, "Warning from", fmt, ##__VA_ARGS__); \
528 #define printInfo(fmt, ...) \
530 printMsg (NVDSINFER_LOG_INFO, "Info from", fmt, ##__VA_ARGS__); \
533 #define printDebug(fmt, ...) \
535 printMsg (NVDSINFER_LOG_DEBUG, "DEBUG", fmt, ##__VA_ARGS__); \
void setAllLayerInfo(std::vector< NvDsInferBatchDimsLayerInfo > &info)
~DetectPostprocessor() override=default
void setLoggingFunc(const NvDsInferLoggingFunc &func)
std::function< void(NvDsInferLogLevel, const char *msg)> NvDsInferLoggingFunc
bool setMeanFile(const std::string &file)
NvDsInferTensorOrder
Defines UFF input layer orders.
@ NvDsInferNetworkType_Classifier
Specifies a classifier.
DetectPostprocessor(int id, int gpuId=0)
virtual NvDsInferStatus initResource(const NvDsInferContextInitParams &initParams)
NvDsInferFormat
Defines color formats.
void setLoggingFunc(const NvDsInferLoggingFunc &func)
Abstract interface for managing the actual inferencing implementation.
bool needOutputCopyB4Processing() const
virtual ~InferPostprocessor()
Helper class for managing Cuda Streams.
void releaseFrameOutput(NvDsInferFrameOutput &frameOutput)
std::shared_ptr< DlLibHandle > m_CustomLibHandle
const std::vector< std::vector< std::string > > & getLabels() const
Holds the information parsed from segmentation network output for one frame.
NvDsInferStatus allocDeviceResource()
void setDlHandle(const std::shared_ptr< DlLibHandle > &dlHandle)
bool needInputCopy() const
@ NVDSINFER_SUCCESS
NvDsInferContext operation succeeded.
virtual NvDsInferStatus postProcessHost(NvDsInferBatch &buffer, NvDsInferContextBatchOutput &output)
Implementation of post-processing class for instance segmentation networks.
void setOutputLayerInfo(std::vector< NvDsInferBatchDimsLayerInfo > &info)
void freeBatchOutput(NvDsInferContextBatchOutput &batchOutput)
bool m_disableOutputHostCopy
Base class for post-processing on inference output.
std::vector< std::pair< std::string, int > > m_OverwriteOpTensorFilePairs
NvDsInferLogLevel
Enum for the log levels of NvDsInferContext.
virtual NvDsInferStatus copyBuffersToHostMemory(NvDsInferBatch &buffer, CudaStream &mainStream)
ClassifyPostprocessor(int id, int gpuId=0)
Holds information on all attributes classifed by a classifier network for one frame.
@ NvDsInferNetworkType_Detector
Specifies a detector.
Copyright (c) 2019-2021, NVIDIA CORPORATION.
Holds the detection parameters required for parsing objects.
Holds information about one batch to be inferred.
NvDsInferStatus initResource(const NvDsInferContextInitParams &initParams) override
@ NvDsInferFormat_RGB
Specifies 24-bit interleaved R-G-B format.
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.
Helper class for managing Cuda Streams.
NvDsInferClusterMode
Enum for clustering mode for detectors.
std::vector< std::ifstream * > m_OverwriteOpTensorFiles
void setNetworkInfo(const NvDsInferNetworkInfo &info)
NvDsInferContextImpl()
Default constructor.
#define NVDSINFER_MIN_OUTPUT_BUFFERPOOL_SIZE
Defines the minimum number of sets of output buffers that must be allocated.
std::vector< std::unique_ptr< CudaDeviceBuffer > > m_OutputDeviceBuffers
SegmentPostprocessor(int id, int gpuId=0)
NvDsInferStatus transform(NvDsInferContextBatchInput &batchInput, void *devBuf, CudaStream &mainStream, CudaEvent *waitingEvent)
NvDsInferStatus initResource(const NvDsInferContextInitParams &initParams) override
Holds the information on all objects detected by a detector network in one frame.
std::vector< NvDsInferLayerInfo > m_OutputLayerInfo
std::vector< void * > m_DeviceBuffers
Holds information about the model network.
Provides pre-processing functionality like mean subtraction and normalization.
Implementation of the INvDsInferContext interface.
std::vector< std::unique_ptr< CudaHostBuffer > > m_HostBuffers
Copyright (c) 2018-2020, NVIDIA CORPORATION.
NvDsInferNetworkInfo m_NetworkInfo
NvDsInferStatus initResource(const NvDsInferContextInitParams &initParams) override
@ NvDsInferTensorOrder_kNCHW
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.
NvDsInferStatus parseLabelsFile(const std::string &path)
std::vector< std::vector< std::string > > m_Labels
bool setScaleOffsets(float scale, const std::vector< float > &offsets={})
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.
InstanceSegmentPostprocessor(int id, int gpuId=0)
@ NvDsInferNetworkType_InstanceSegmentation
Specifies a instance segmentation network.
Holds the initialization parameters required for the NvDsInferContext interface.
InferPostprocessor(NvDsInferNetworkType type, int id, int gpuId)
bool m_CopyInputToHostBuffers
NvDsInferStatus initResource(const NvDsInferContextInitParams &initParams) override
NvDsInferNetworkType m_NetworkType
std::vector< std::pair< std::string, std::string > > m_DumpOpTensorFiles
Implementation of post-processing class for classification networks.
void(* NvDsInferContextLoggingFunc)(NvDsInferContextHandle handle, unsigned int uniqueID, NvDsInferLogLevel logLevel, const char *logMessage, void *userCtx)
Type declaration for a logging callback.
#define _DS_DEPRECATED_(STR)
@ NvDsInferNetworkType_Segmentation
Specifies a segmentation network.
Holds detection and bounding box grouping parameters.
Holds the information inferred by the network on one frame.
virtual ~InferPreprocessor()=default
NvDsInferNetworkType
Defines network types.
Holds the output for all of the frames in a batch (an array of frame), and related buffer information...
NvDsInferStatus initResource(const NvDsInferContextInitParams &initParams) override
@ NvDsInferNetworkType_Other
Specifies other.
NvDsInferStatus initialize(NvDsInferContextInitParams &initParams, void *userCtx, NvDsInferContextLoggingFunc logFunc)
Initializes the Infer engine, allocates layer buffers and other required initialization steps.
InferPreprocessor(const NvDsInferNetworkInfo &info, NvDsInferFormat format, const NvDsInferBatchDimsLayerInfo &layerInfo, int id=0)
Implementation of post-processing class for object detection networks.
Holds information for one batch for processing.
~InstanceSegmentPostprocessor() override=default
OtherPostprocessor(int id, int gpuId=0)
bool setInputOrder(const NvDsInferTensorOrder order)
NvDsInferLoggingFunc m_LoggingFunc
Implementation of post-processing class for segmentation networks.
NvDsInferStatus allocateResource()
std::vector< NvDsInferLayerInfo > m_AllLayerInfo
NvDsInferStatus
Enum for the status codes returned by NvDsInferContext.
NvDsInferStatus syncStream()