NVIDIA DeepStream SDK API Reference

9.1 Release
9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2018-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 
18 #ifndef __NVDSINFERSERVER_POST_PROCESS_BUF_H__
19 #define __NVDSINFERSERVER_POST_PROCESS_BUF_H__
20 
21 #include <condition_variable>
22 #include <functional>
23 #include <list>
24 #include <memory>
25 #include <mutex>
26 #include <queue>
27 
28 #include "infer_batch_buffer.h"
29 #include "infer_cuda_utils.h"
30 #include "infer_datatypes.h"
31 #include "infer_iprocess.h"
32 #include "infer_post_datatypes.h"
33 #include "nvdsinfer.h"
34 #include "nvdsinfer_custom_impl.h"
35 #include "nvdsinferserver_config.pb.h"
36 
37 namespace ic = nvdsinferserver::config;
38 
39 struct NvDsInferDBScan;
40 
41 namespace nvdsinferserver {
42 
43 class DetectionOutput : public BaseBatchBuffer {
44 public:
46  {
48  memType : InferMemType::kCpu,
49  devId : 0,
50  dataType : InferDataType::kNone,
51  dims : {1, {1}, 1},
52  elementSize : sizeof(NvDsInferDetectionOutput),
54  isInput : false,
55  };
56  setBufDesc(desc);
57  }
59  {
60  for (auto& batch : m_Objects)
61  for (auto& object : batch)
62  if (object.label) {
63  free(object.label);
64  }
65  }
66  void swapObjects(std::vector<std::vector<NvDsInferObject>>& objs)
67  {
68  setBatchSize(objs.size());
69  m_Objects.swap(objs);
70  m_BufPtrs.resize(m_Objects.size());
71  for (size_t i = 0; i < m_BufPtrs.size(); ++i) {
72  NvDsInferDetectionOutput& bufPtr = m_BufPtrs[i];
73  bufPtr.numObjects = m_Objects.at(i).size();
74  bufPtr.objects = m_Objects.at(i).data();
75  }
76  }
78  void* getBufPtr(uint32_t batchIdx) const override
79  {
80  assert(batchIdx < (uint32_t)m_BufPtrs.size());
81  return (void*)&m_BufPtrs.at(batchIdx);
82  }
83 
84 private:
85  std::vector<std::vector<NvDsInferObject>> m_Objects;
86  std::vector<NvDsInferDetectionOutput> m_BufPtrs;
87 };
88 
89 class ClassificationOutput : public BaseBatchBuffer {
90 public:
91  ClassificationOutput(int batchSize) : BaseBatchBuffer(batchSize)
92  {
94  memType : InferMemType::kCpu,
95  devId : 0,
96  dataType : InferDataType::kNone,
97  dims : {1, {1}, 1},
98  elementSize : sizeof(InferClassificationOutput),
100  isInput : false,
101  };
102  setBufDesc(desc);
103  m_BufPtrs.resize(batchSize);
104  }
106  InferClassificationOutput& mutableOutput(uint32_t idx)
107  {
108  assert(idx < m_BufPtrs.size());
109  return m_BufPtrs[idx];
110  }
112  void* getBufPtr(uint32_t batchIdx) const override
113  {
114  assert(batchIdx < (uint32_t)m_BufPtrs.size());
115  return (void*)&m_BufPtrs.at(batchIdx);
116  }
117 
119  void finalize()
120  {
121  for (uint32_t i = 0; i < m_BufPtrs.size(); ++i) {
122  InferClassificationOutput& data = mutableOutput(i);
123  for (size_t k = 0; k < data.attributes.size(); ++k) {
124  auto& attrib = data.attributes[k];
125  if (attrib.safeAttributeLabel.empty()) {
126  attrib.safeAttributeLabel = safeStr(attrib.attributeLabel);
127  }
128  attrib.attributeLabel = (char *) attrib.safeAttributeLabel.c_str();
129  }
130  }
131  }
132 
133 private:
134  std::vector<InferClassificationOutput> m_BufPtrs;
135 };
136 
137 using SharedClassOutput = std::shared_ptr<ClassificationOutput>;
138 
139 class SegmentationOutput : public BaseBatchBuffer {
140 public:
141  SegmentationOutput(int batchSize) : BaseBatchBuffer(batchSize)
142  {
144  memType : InferMemType::kCpu,
145  devId : 0,
146  dataType : InferDataType::kNone,
147  dims : {1, {1}, 1},
148  elementSize : sizeof(NvDsInferSegmentationOutput),
150  isInput : false,
151  };
152  setBufDesc(desc);
153  m_BufPtrs.resize(batchSize, NvDsInferSegmentationOutput{0});
154  }
156  {
157  for (NvDsInferSegmentationOutput& out : m_BufPtrs) {
158  if (out.class_map) {
159  delete[] out.class_map;
160  }
161  }
162  }
164  {
165  assert(idx < m_BufPtrs.size());
166  return m_BufPtrs[idx];
167  }
169  void* getBufPtr(uint32_t batchIdx) const override
170  {
171  assert(batchIdx < (uint32_t)m_BufPtrs.size());
172  return (void*)&m_BufPtrs.at(batchIdx);
173  }
174 
175 private:
176  std::vector<NvDsInferSegmentationOutput> m_BufPtrs;
177 };
178 
179 } // namespace nvdsinferserver
180 
181 #endif // __NVDSINFERSERVER_POST_PROCESS_BUF_H__
infer_batch_buffer.h
Header file of batch buffer related class declarations.
nvdsinferserver
This is a header file for pre-processing cuda kernels with normalization and mean subtraction require...
Definition: sources/gst-plugins/gst-nvinferserver/gstnvinferserver_impl.h:69
INFER_SERVER_CLASSIFICATION_BUF_NAME
#define INFER_SERVER_CLASSIFICATION_BUF_NAME
Definition: sources/includes/nvdsinferserver/infer_post_datatypes.h:105
nvdsinferserver::DetectionOutput::getBufPtr
void * getBufPtr(uint32_t batchIdx) const override
return NvDsInferDetectionOutput* pointer
Definition: 9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h:78
nvdsinferserver::ClassificationOutput::~ClassificationOutput
~ClassificationOutput()
Definition: 9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h:105
INFER_SERVER_SEGMENTATION_BUF_NAME
#define INFER_SERVER_SEGMENTATION_BUF_NAME
Definition: sources/includes/nvdsinferserver/infer_post_datatypes.h:107
nvdsinferserver::SegmentationOutput::~SegmentationOutput
~SegmentationOutput()
Definition: 9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h:155
NvDsInferDetectionOutput::numObjects
unsigned int numObjects
Holds the number of objects in objects.
Definition: sources/includes/nvdsinfer_context.h:576
NvDsInferSegmentationOutput
Holds information parsed from segmentation network output for one frame.
Definition: sources/includes/nvdsinfer_context.h:599
nvdsinferserver::DetectionOutput::swapObjects
void swapObjects(std::vector< std::vector< NvDsInferObject >> &objs)
Definition: 9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h:66
nvdsinferserver::ClassificationOutput::getBufPtr
void * getBufPtr(uint32_t batchIdx) const override
return InferClassificationOutput* pointer
Definition: 9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h:112
INFER_SERVER_DETECTION_BUF_NAME
#define INFER_SERVER_DETECTION_BUF_NAME
Definition: sources/includes/nvdsinferserver/infer_post_datatypes.h:104
infer_cuda_utils.h
Header file declaring utility classes for CUDA memory management, CIDA streams and events.
nvdsinferserver::BaseBatchBuffer::setBatchSize
virtual void setBatchSize(uint32_t size)
Definition: sources/libs/nvdsinferserver/infer_batch_buffer.h:56
nvdsinferserver::SegmentationOutput::SegmentationOutput
SegmentationOutput(int batchSize)
Definition: 9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h:141
NvDsInferDetectionOutput
Holds information on all objects detected by a detector network in one frame.
Definition: sources/includes/nvdsinfer_context.h:571
nvdsinferserver::DetectionOutput::~DetectionOutput
~DetectionOutput()
Definition: 9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h:58
nvdsinferserver::ClassificationOutput::mutableOutput
InferClassificationOutput & mutableOutput(uint32_t idx)
Definition: 9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h:106
nvdsinferserver::ClassificationOutput::ClassificationOutput
ClassificationOutput(int batchSize)
Definition: 9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h:91
nvdsinferserver::SegmentationOutput::mutableOutput
NvDsInferSegmentationOutput & mutableOutput(uint32_t idx)
Definition: 9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h:163
nvdsinferserver::DetectionOutput::DetectionOutput
DetectionOutput()
Definition: 9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h:45
nvdsinferserver::SegmentationOutput::getBufPtr
void * getBufPtr(uint32_t batchIdx) const override
return NvDsInferSegmentationOutput* pointer
Definition: 9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h:169
nvdsinferserver::BaseBatchBuffer::setBufDesc
void setBufDesc(const InferBufferDescription &desc)
Definition: sources/libs/nvdsinferserver/infer_batch_buffer.h:54
nvdsinferserver::InferDataType::kNone
@ kNone
nvdsinferserver::ClassificationOutput::finalize
void finalize()
copy all lables to safe place
Definition: 9.1/sources/libs/nvdsinferserver/infer_postproc_buf.h:119
nvdsinferserver::SharedClassOutput
std::shared_ptr< ClassificationOutput > SharedClassOutput
Definition: sources/libs/nvdsinferserver/infer_postproc_buf.h:137
safeStr
#define safeStr(str)
Definition: sources/includes/nvdsinferserver/infer_options.h:39
infer_iprocess.h
Preprocessing and postprocessing interface header file.
nvdsinferserver::BaseBatchBuffer
The base class for batch buffers.
Definition: sources/libs/nvdsinferserver/infer_batch_buffer.h:39
nvdsinferserver::InferMemType::kCpu
@ kCpu
Host (CPU) memory.
NvDsInferDetectionOutput::objects
NvDsInferObject * objects
Holds a pointer to an array of objects.
Definition: sources/includes/nvdsinfer_context.h:574
nvdsinferserver::InferBufferDescription
Holds the information about a inference buffer.
Definition: sources/includes/nvdsinferserver/infer_datatypes.h:173