NVIDIA DeepStream SDK API Reference

7.0 Release
yolo.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2024, NVIDIA CORPORATION. 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 
13 #ifndef _YOLO_H_
14 #define _YOLO_H_
15 
16 #include <stdint.h>
17 #include <string>
18 #include <vector>
19 #include <memory>
20 
21 #include "NvInfer.h"
22 #include "trt_utils.h"
23 
24 #include "nvdsinfer_custom_impl.h"
25 
30 {
31  std::string networkType;
32  std::string configFilePath;
33  std::string wtsFilePath;
34  std::string deviceType;
35  std::string inputBlobName;
36 };
37 
41 struct TensorInfo
42 {
43  std::string blobName;
44  uint stride{0};
45  uint gridSize{0};
46  uint numClasses{0};
47  uint numBBoxes{0};
48  uint64_t volume{0};
49  std::vector<uint> masks;
50  std::vector<float> anchors;
51  int bindingIndex{-1};
52  float* hostBuffer{nullptr};
53 };
54 
55 class Yolo : public IModelParser {
56 public:
57  Yolo(const NetworkInfo& networkInfo);
58  ~Yolo() override;
59  bool hasFullDimsSupported() const override { return false; }
60  const char* getModelName() const override {
61  return m_ConfigFilePath.empty() ? m_NetworkType.c_str()
62  : m_ConfigFilePath.c_str();
63  }
64  NvDsInferStatus parseModel(nvinfer1::INetworkDefinition& network) override;
65 
66  nvinfer1::ICudaEngine *createEngine (
67  nvinfer1::IBuilder* builder, nvinfer1::IBuilderConfig* config);
68 
69 protected:
70  const std::string m_NetworkType;
71  const std::string m_ConfigFilePath;
72  const std::string m_WtsFilePath;
73  const std::string m_DeviceType;
74  const std::string m_InputBlobName;
75  std::vector<TensorInfo> m_OutputTensors;
76  std::vector<std::map<std::string, std::string>> m_ConfigBlocks;
77  uint m_InputH;
78  uint m_InputW;
79  uint m_InputC;
80  uint64_t m_InputSize;
81 
82  // TRT specific members
83  std::vector<nvinfer1::Weights> m_TrtWeights;
84 
85 private:
86  NvDsInferStatus buildYoloNetwork(
87  std::vector<float>& weights, nvinfer1::INetworkDefinition& network);
88  std::vector<std::map<std::string, std::string>> parseConfigFile(
89  const std::string cfgFilePath);
90  void parseConfigBlocks();
91  void destroyNetworkUtils();
92 };
93 
94 #endif // _YOLO_H_
Yolo::m_InputBlobName
const std::string m_InputBlobName
Definition: yolo.h:74
NetworkInfo::deviceType
std::string deviceType
Definition: yolo.h:34
NetworkInfo::configFilePath
std::string configFilePath
Definition: yolo.h:32
Yolo::parseModel
NvDsInferStatus parseModel(nvinfer1::INetworkDefinition &network) override
Yolo::Yolo
Yolo(const NetworkInfo &networkInfo)
Yolo::m_InputW
uint m_InputW
Definition: yolo.h:78
TensorInfo
Holds information about an output tensor of the yolo network.
Definition: yolo.h:41
TensorInfo::anchors
std::vector< float > anchors
Definition: yolo.h:50
TensorInfo::numClasses
uint numClasses
Definition: yolo.h:46
Yolo::m_TrtWeights
std::vector< nvinfer1::Weights > m_TrtWeights
Definition: yolo.h:83
Yolo::hasFullDimsSupported
bool hasFullDimsSupported() const override
Definition: yolo.h:59
TensorInfo::gridSize
uint gridSize
Definition: yolo.h:45
Yolo::m_ConfigFilePath
const std::string m_ConfigFilePath
Definition: yolo.h:71
TensorInfo::numBBoxes
uint numBBoxes
Definition: yolo.h:47
trt_utils.h
TensorInfo::hostBuffer
float * hostBuffer
Definition: yolo.h:52
Yolo::m_InputH
uint m_InputH
Definition: yolo.h:77
TensorInfo::bindingIndex
int bindingIndex
Definition: yolo.h:51
TensorInfo::masks
std::vector< uint > masks
Definition: yolo.h:49
Yolo
Definition: yolo.h:55
Yolo::~Yolo
~Yolo() override
Yolo::m_DeviceType
const std::string m_DeviceType
Definition: yolo.h:73
NetworkInfo::inputBlobName
std::string inputBlobName
Definition: yolo.h:35
TensorInfo::stride
uint stride
Definition: yolo.h:44
nvdsinfer_custom_impl.h
NetworkInfo::networkType
std::string networkType
Definition: yolo.h:31
Yolo::getModelName
const char * getModelName() const override
Definition: yolo.h:60
Yolo::createEngine
nvinfer1::ICudaEngine * createEngine(nvinfer1::IBuilder *builder, nvinfer1::IBuilderConfig *config)
Yolo::m_InputSize
uint64_t m_InputSize
Definition: yolo.h:80
NetworkInfo::wtsFilePath
std::string wtsFilePath
Definition: yolo.h:33
Yolo::m_OutputTensors
std::vector< TensorInfo > m_OutputTensors
Definition: yolo.h:75
Yolo::m_InputC
uint m_InputC
Definition: yolo.h:79
TensorInfo::blobName
std::string blobName
Definition: yolo.h:43
TensorInfo::volume
uint64_t volume
Definition: yolo.h:48
NetworkInfo
Holds all the file paths required to build a network.
Definition: yolo.h:29
Yolo::m_ConfigBlocks
std::vector< std::map< std::string, std::string > > m_ConfigBlocks
Definition: yolo.h:76
Yolo::m_NetworkType
const std::string m_NetworkType
Definition: yolo.h:70
Yolo::m_WtsFilePath
const std::string m_WtsFilePath
Definition: yolo.h:72
NvDsInferStatus
NvDsInferStatus
Enum for the status codes returned by NvDsInferContext.
Definition: nvdsinfer.h:218