NVIDIA DeepStream SDK API Reference

6.4 Release
post_processor.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef __POST_PROCESSOR_HPP__
25 #define __POST_PROCESSOR_HPP__
26 
27 #include <iostream>
28 #include <fstream>
29 #include <thread>
30 #include <cstring>
31 #include <queue>
32 #include <mutex>
33 #include <memory>
34 #include <stdexcept>
35 #include <unordered_map>
36 #include <condition_variable>
37 #include <yaml-cpp/yaml.h>
38 #include <limits.h>
39 #include <cassert>
40 #include <algorithm>
41 #include "nvbufsurface.h"
42 #include "nvbufsurftransform.h"
43 #include "gst-nvquery.h"
44 #include "gstnvdsmeta.h"
45 #include "gst-nvevent.h"
46 #include "nvdsinfer_dbscan.h"
47 #include "post_processor_struct.h"
48 
49 
50 #ifndef PP_DISABLE_CLASS_COPY
51 #define PP_DISABLE_CLASS_COPY(NoCopyClass) \
52  NoCopyClass(const NoCopyClass&) = delete; \
53  void operator=(const NoCopyClass&) = delete
54 #endif
55 
56 
58 {
59 
60 protected:
62  : m_NetworkType(type), m_UniqueID(id), m_GpuID(gpuId){}
63 
64 public:
65  virtual ~ModelPostProcessor() = default;
66 
67  virtual NvDsPostProcessStatus
69  const std::vector<std::vector<std::string>>& getLabels() const
70  {
71  return m_Labels;
72  }
75  m_NetworkInfo = networkInfo;
76  }
77 
79  const std::vector <NvDsInferLayerInfo> &outputLayers,
80  NvDsPostProcessFrameOutput& result) = 0;
81 
82 
83  virtual void
84  attachMetadata (NvBufSurface *surf, gint batch_idx,
85  NvDsBatchMeta *batch_meta,
86  NvDsFrameMeta *frame_meta,
87  NvDsObjectMeta *object_meta,
88  NvDsObjectMeta *parent_obj_meta,
89  NvDsPostProcessFrameOutput & detection_output,
91  std::set <gint> & filterOutClassIds,
92  int32_t unique_id,
93  gboolean output_instance_mask,
94  gboolean process_full_frame,
95  float segmentationThreshold,
96  gboolean maintain_aspect_ratio) = 0;
97 
98 
99  virtual void releaseFrameOutput(NvDsPostProcessFrameOutput& frameOutput) = 0;
100 
101 protected:
102  NvDsPostProcessStatus parseLabelsFile(const std::string &path);
103 
104 private:
105  PP_DISABLE_CLASS_COPY(ModelPostProcessor);
106 
107 protected:
108  /* Processor type */
110 
111  int m_UniqueID = 0;
112  uint32_t m_GpuID = 0;
113 
114  /* Network input information. */
116  std::vector<NvDsInferLayerInfo> m_AllLayerInfo;
117  std::vector<NvDsInferLayerInfo> m_OutputLayerInfo;
118 
119  /* Holds the string labels for classes. */
120  std::vector<std::vector<std::string>> m_Labels;
121 
122 };
123 
124 #endif
ModelPostProcessor::parseEachFrame
virtual NvDsPostProcessStatus parseEachFrame(const std::vector< NvDsInferLayerInfo > &outputLayers, NvDsPostProcessFrameOutput &result)=0
ModelPostProcessor::getLabels
const std::vector< std::vector< std::string > > & getLabels() const
Definition: post_processor.h:69
ModelPostProcessor::setNetworkInfo
void setNetworkInfo(NvDsInferNetworkInfo networkInfo)
Definition: post_processor.h:74
NvDsPostProcessDetectionParams
Holds detection and bounding box grouping parameters.
Definition: post_processor_struct.h:216
ModelPostProcessor
Definition: post_processor.h:57
NvDsPostProcessNetworkType
NvDsPostProcessNetworkType
Defines network types.
Definition: post_processor_struct.h:191
ModelPostProcessor::attachMetadata
virtual void attachMetadata(NvBufSurface *surf, gint batch_idx, NvDsBatchMeta *batch_meta, NvDsFrameMeta *frame_meta, NvDsObjectMeta *object_meta, NvDsObjectMeta *parent_obj_meta, NvDsPostProcessFrameOutput &detection_output, NvDsPostProcessDetectionParams *all_params, std::set< gint > &filterOutClassIds, int32_t unique_id, gboolean output_instance_mask, gboolean process_full_frame, float segmentationThreshold, gboolean maintain_aspect_ratio)=0
ModelPostProcessor::initResource
virtual NvDsPostProcessStatus initResource(NvDsPostProcessContextInitParams &initParams)
NvBufSurface
Holds information about batched buffers.
Definition: nvbufsurface.h:503
gst-nvevent.h
gst-nvquery.h
ModelPostProcessor::ModelPostProcessor
ModelPostProcessor(NvDsPostProcessNetworkType type, int id, int gpuId)
Definition: post_processor.h:61
NvDsPostProcessStatus
NvDsPostProcessStatus
Enum for the status codes returned by NvDsPostProcessAlgorithm.
Definition: post_processor_struct.h:84
ModelPostProcessor::m_Labels
std::vector< std::vector< std::string > > m_Labels
Definition: post_processor.h:120
ModelPostProcessor::m_GpuID
uint32_t m_GpuID
Definition: post_processor.h:112
ModelPostProcessor::m_NetworkInfo
NvDsInferNetworkInfo m_NetworkInfo
Definition: post_processor.h:115
nvdsinfer_dbscan.h
ModelPostProcessor::m_OutputLayerInfo
std::vector< NvDsInferLayerInfo > m_OutputLayerInfo
Definition: post_processor.h:117
NvDsInferNetworkInfo
Holds information about the model network.
Definition: nvdsinfer.h:110
ModelPostProcessor::m_UniqueID
int m_UniqueID
Definition: post_processor.h:111
_NvDsBatchMeta
Holds information about a formed batch containing frames from different sources.
Definition: nvdsmeta.h:240
gstnvdsmeta.h
_NvDsPostProcessContextInitParams
Holds the initialization parameters required for the NvDsPostProcessContext interface.
Definition: post_processor_struct.h:260
ModelPostProcessor::m_AllLayerInfo
std::vector< NvDsInferLayerInfo > m_AllLayerInfo
Definition: post_processor.h:116
NvDsPostProcessFrameOutput
Holds the information inferred by the network on one frame.
Definition: post_processor_struct.h:483
ModelPostProcessor::parseLabelsFile
NvDsPostProcessStatus parseLabelsFile(const std::string &path)
NvDsPostProcessBatchOutput
Holds the output for all of the frames in a batch (an array of frame), and related buffer information...
Definition: post_processor_struct.h:509
post_processor_struct.h
ModelPostProcessor::m_NetworkType
NvDsPostProcessNetworkType m_NetworkType
Definition: post_processor.h:109
ModelPostProcessor::releaseFrameOutput
virtual void releaseFrameOutput(NvDsPostProcessFrameOutput &frameOutput)=0
ModelPostProcessor::~ModelPostProcessor
virtual ~ModelPostProcessor()=default
_NvDsFrameMeta
Holds metadata for a frame in a batch.
Definition: nvdsmeta.h:284
nvbufsurftransform.h
NvDsPostProcessNetworkType_Other
@ NvDsPostProcessNetworkType_Other
Specifies other.
Definition: post_processor_struct.h:210
nvbufsurface.h
ModelPostProcessor::freeBatchOutput
void freeBatchOutput(NvDsPostProcessBatchOutput &batchOutput)
_NvDsObjectMeta
Holds metadata for an object in the frame.
Definition: nvdsmeta.h:342