NVIDIA DeepStream SDK API Reference

7.0 Release
infer_base_backend.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 
22 #ifndef __NVDSINFER_BASE_BACKEND_H__
23 #define __NVDSINFER_BASE_BACKEND_H__
24 
25 #include <stdarg.h>
26 #include <condition_variable>
27 #include <memory>
28 #include <mutex>
29 #include <queue>
30 
31 #include "infer_datatypes.h"
32 #include "infer_ibackend.h"
33 #include "infer_utils.h"
34 
35 namespace nvdsinferserver {
36 
40 class BaseBackend : public IBackend {
41 public:
45  ~BaseBackend() override = default;
49  InferTensorOrder getInputTensorOrder() const final { return m_InputOrder; }
50 
54  void setUniqueId(uint32_t id) { m_UniqueId = id; }
55 
59  int uniqueId() const { return m_UniqueId; }
60 
64  void setFirstDimBatch(bool flag) { m_IsFirstDimBatch = flag; }
65 
69  bool isFirstDimBatch() const final { return m_IsFirstDimBatch; }
70 
75  uint32_t getLayerSize() const final {
76  assert(!m_AllLayers.empty());
77  return (int)m_AllLayers.size();
78  }
79 
83  uint32_t getInputLayerSize() const final {
84  return m_InputSize;
85  }
86 
91  const std::string& bindingName) const final;
92 
96  LayersTuple getInputLayers() const final;
97 
101  LayersTuple getOutputLayers() const final;
102 
107  bool checkInputDims(const InputShapes& shapes) const;
108 
113  const LayerDescriptionList& allLayers() const { return m_AllLayers; }
114 
118  void setKeepInputs(bool enable) {
119  m_KeepInputs = enable;
120  }
121 
125  int32_t maxBatchSize() const final { return m_MaxBatchSize; }
126 
130  bool isNonBatching() const { return isNonBatch(maxBatchSize()); }
131 
132 protected:
136  using LayerIdxMap = std::unordered_map<std::string, int>;
137 
148  void resetLayers(LayerDescriptionList layers, int inputSize);
149 
153  LayerDescription* mutableLayerInfo(const std::string& bindingName)
154  {
155  const LayerDescription* info = getLayerInfo(bindingName);
156  return const_cast<LayerDescription*>(info);
157  }
158 
162  void setInputTensorOrder(InferTensorOrder order) { m_InputOrder = order; }
163 
167  bool needKeepInputs() const {
168  return m_KeepInputs;
169  }
170 
174  void setMaxBatchSize(uint32_t size) { m_MaxBatchSize = size; }
175 
176 private:
180  LayerDescriptionList m_AllLayers;
184  LayerIdxMap m_LayerNameToIdx;
188  uint32_t m_InputSize = 0;
192  int32_t m_MaxBatchSize = 0;
196  bool m_IsFirstDimBatch = false;
197 
205  uint32_t m_UniqueId = 0;
209  bool m_KeepInputs = false;
210 };
211 
212 using UniqBackend = std::unique_ptr<BaseBackend>;
213 
214 } // namespace nvdsinferserver
215 #endif
nvdsinferserver::BaseBackend::getOutputLayers
LayersTuple getOutputLayers() const final
Get the LayersTuple for output layers.
nvdsinferserver
This is a header file for pre-processing cuda kernels with normalization and mean subtraction require...
Definition: infer_custom_process.h:24
INFER_EXPORT_API::isNonBatch
bool isNonBatch(T b)
Checks if the input batch size is zero.
Definition: infer_utils.h:101
nvdsinferserver::BaseBackend::setMaxBatchSize
void setMaxBatchSize(uint32_t size)
Set the maximum batch size to be used for the backend.
Definition: infer_base_backend.h:174
nvdsinferserver::BaseBackend::~BaseBackend
~BaseBackend() override=default
Destructor, default.
nvdsinferserver::BaseBackend::uniqueId
int uniqueId() const
Get the unique ID of the object instance.
Definition: infer_base_backend.h:59
nvdsinferserver::BaseBackend::resetLayers
void resetLayers(LayerDescriptionList layers, int inputSize)
Set the layer description list of the backend.
nvdsinferserver::IBackend::InputShapes
std::vector< InputShapeTuple > InputShapes
Definition: infer_ibackend.h:84
infer_datatypes.h
Header file for the data types used in the inference processing.
nvdsinferserver::IBackend
Definition: infer_ibackend.h:60
nvdsinferserver::InferTensorOrder
InferTensorOrder
The type of tensor order.
Definition: infer_datatypes.h:41
nvdsinferserver::BaseBackend::mutableLayerInfo
LayerDescription * mutableLayerInfo(const std::string &bindingName)
Get the mutable layer description structure for the layer name.
Definition: infer_base_backend.h:153
nvdsinferserver::LayerDescription
Stores the information of a layer in the inference model.
Definition: infer_ibackend.h:34
nvdsinferserver::IBackend::LayersTuple
std::tuple< const LayerDescription *, int > LayersTuple
Tuple containing pointer to layer descriptions and the number of layers.
Definition: infer_ibackend.h:77
nvdsinferserver::BaseBackend::LayerIdxMap
std::unordered_map< std::string, int > LayerIdxMap
Map of layer name to layer index.
Definition: infer_base_backend.h:136
infer_ibackend.h
Inference processing backend interface header file.
nvdsinferserver::LayerDescriptionList
std::vector< LayerDescription > LayerDescriptionList
Definition: infer_ibackend.h:58
infer_utils.h
Header file containing utility functions and classes used by the nvinferserver low level library.
nvdsinferserver::BaseBackend::isFirstDimBatch
bool isFirstDimBatch() const final
Returns boolean indicating if batched input is expected.
Definition: infer_base_backend.h:69
nvdsinferserver::BaseBackend::getLayerInfo
const LayerDescription * getLayerInfo(const std::string &bindingName) const final
Retrieve the layer information from the layer name.
nvdsinferserver::UniqBackend
std::unique_ptr< BaseBackend > UniqBackend
Definition: infer_base_backend.h:212
nvdsinferserver::BaseBackend::getLayerSize
uint32_t getLayerSize() const final
Returns the total number of layers (input + output) for the model.
Definition: infer_base_backend.h:75
nvdsinferserver::BaseBackend::setUniqueId
void setUniqueId(uint32_t id)
Set the unique ID for the object instance.
Definition: infer_base_backend.h:54
nvdsinferserver::BaseBackend::isNonBatching
bool isNonBatching() const
Checks if the batch size indicates batched processing or no.
Definition: infer_base_backend.h:130
nvdsinferserver::BaseBackend::setFirstDimBatch
void setFirstDimBatch(bool flag)
Set the flag indicating that it is a batch input.
Definition: infer_base_backend.h:64
nvdsinferserver::BaseBackend::getInputLayers
LayersTuple getInputLayers() const final
Get the LayersTuple for input layers.
nvdsinferserver::BaseBackend::maxBatchSize
int32_t maxBatchSize() const final
Returns the maximum batch size set for the backend.
Definition: infer_base_backend.h:125
nvdsinferserver::InferTensorOrder::kNone
@ kNone
nvdsinferserver::BaseBackend::needKeepInputs
bool needKeepInputs() const
Check if the keep input flag is set.
Definition: infer_base_backend.h:167
nvdsinferserver::BaseBackend
Base class of inference backend processing.
Definition: infer_base_backend.h:40
nvdsinferserver::BaseBackend::allLayers
const LayerDescriptionList & allLayers() const
Returns the list of all descriptions of all layers, input and output.
Definition: infer_base_backend.h:113
nvdsinferserver::BaseBackend::checkInputDims
bool checkInputDims(const InputShapes &shapes) const
Check that the list of input shapes have fixed dimensions and corresponding layers are marked as inpu...
nvdsinferserver::BaseBackend::getInputTensorOrder
InferTensorOrder getInputTensorOrder() const final
Returns the input tensor order.
Definition: infer_base_backend.h:49
nvdsinferserver::BaseBackend::setInputTensorOrder
void setInputTensorOrder(InferTensorOrder order)
Set the tensor order for the input layers.
Definition: infer_base_backend.h:162
nvdsinferserver::BaseBackend::setKeepInputs
void setKeepInputs(bool enable)
Set the flag indicating whether to keep inputs buffers.
Definition: infer_base_backend.h:118
nvdsinferserver::BaseBackend::getInputLayerSize
uint32_t getInputLayerSize() const final
Returns the number of input layers for the model.
Definition: infer_base_backend.h:83