NVIDIA DeepStream SDK API Reference

6.4 Release
yolo.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef _YOLO_H_
24 #define _YOLO_H_
25 
26 #include <stdint.h>
27 #include <string>
28 #include <vector>
29 #include <memory>
30 
31 #include "NvInfer.h"
32 #include "trt_utils.h"
33 
34 #include "nvdsinfer_custom_impl.h"
35 
40 {
41  std::string networkType;
42  std::string configFilePath;
43  std::string wtsFilePath;
44  std::string deviceType;
45  std::string inputBlobName;
46 };
47 
51 struct TensorInfo
52 {
53  std::string blobName;
54  uint stride{0};
55  uint gridSize{0};
56  uint numClasses{0};
57  uint numBBoxes{0};
58  uint64_t volume{0};
59  std::vector<uint> masks;
60  std::vector<float> anchors;
61  int bindingIndex{-1};
62  float* hostBuffer{nullptr};
63 };
64 
65 class Yolo : public IModelParser {
66 public:
67  Yolo(const NetworkInfo& networkInfo);
68  ~Yolo() override;
69  bool hasFullDimsSupported() const override { return false; }
70  const char* getModelName() const override {
71  return m_ConfigFilePath.empty() ? m_NetworkType.c_str()
72  : m_ConfigFilePath.c_str();
73  }
74  NvDsInferStatus parseModel(nvinfer1::INetworkDefinition& network) override;
75 
76  nvinfer1::ICudaEngine *createEngine (
77  nvinfer1::IBuilder* builder, nvinfer1::IBuilderConfig* config);
78 
79 protected:
80  const std::string m_NetworkType;
81  const std::string m_ConfigFilePath;
82  const std::string m_WtsFilePath;
83  const std::string m_DeviceType;
84  const std::string m_InputBlobName;
85  std::vector<TensorInfo> m_OutputTensors;
86  std::vector<std::map<std::string, std::string>> m_ConfigBlocks;
87  uint m_InputH;
88  uint m_InputW;
89  uint m_InputC;
90  uint64_t m_InputSize;
91 
92  // TRT specific members
93  std::vector<nvinfer1::Weights> m_TrtWeights;
94 
95 private:
96  NvDsInferStatus buildYoloNetwork(
97  std::vector<float>& weights, nvinfer1::INetworkDefinition& network);
98  std::vector<std::map<std::string, std::string>> parseConfigFile(
99  const std::string cfgFilePath);
100  void parseConfigBlocks();
101  void destroyNetworkUtils();
102 };
103 
104 #endif // _YOLO_H_
Yolo::m_InputBlobName
const std::string m_InputBlobName
Definition: yolo.h:84
NetworkInfo::deviceType
std::string deviceType
Definition: yolo.h:44
NetworkInfo::configFilePath
std::string configFilePath
Definition: yolo.h:42
Yolo::parseModel
NvDsInferStatus parseModel(nvinfer1::INetworkDefinition &network) override
Yolo::Yolo
Yolo(const NetworkInfo &networkInfo)
Yolo::m_InputW
uint m_InputW
Definition: yolo.h:88
TensorInfo
Holds information about an output tensor of the yolo network.
Definition: yolo.h:51
TensorInfo::anchors
std::vector< float > anchors
Definition: yolo.h:60
TensorInfo::numClasses
uint numClasses
Definition: yolo.h:56
Yolo::m_TrtWeights
std::vector< nvinfer1::Weights > m_TrtWeights
Definition: yolo.h:93
Yolo::hasFullDimsSupported
bool hasFullDimsSupported() const override
Definition: yolo.h:69
TensorInfo::gridSize
uint gridSize
Definition: yolo.h:55
Yolo::m_ConfigFilePath
const std::string m_ConfigFilePath
Definition: yolo.h:81
TensorInfo::numBBoxes
uint numBBoxes
Definition: yolo.h:57
trt_utils.h
TensorInfo::hostBuffer
float * hostBuffer
Definition: yolo.h:62
Yolo::m_InputH
uint m_InputH
Definition: yolo.h:87
TensorInfo::bindingIndex
int bindingIndex
Definition: yolo.h:61
TensorInfo::masks
std::vector< uint > masks
Definition: yolo.h:59
Yolo
Definition: yolo.h:65
Yolo::~Yolo
~Yolo() override
Yolo::m_DeviceType
const std::string m_DeviceType
Definition: yolo.h:83
NetworkInfo::inputBlobName
std::string inputBlobName
Definition: yolo.h:45
TensorInfo::stride
uint stride
Definition: yolo.h:54
nvdsinfer_custom_impl.h
NetworkInfo::networkType
std::string networkType
Definition: yolo.h:41
Yolo::getModelName
const char * getModelName() const override
Definition: yolo.h:70
Yolo::createEngine
nvinfer1::ICudaEngine * createEngine(nvinfer1::IBuilder *builder, nvinfer1::IBuilderConfig *config)
Yolo::m_InputSize
uint64_t m_InputSize
Definition: yolo.h:90
NetworkInfo::wtsFilePath
std::string wtsFilePath
Definition: yolo.h:43
Yolo::m_OutputTensors
std::vector< TensorInfo > m_OutputTensors
Definition: yolo.h:85
Yolo::m_InputC
uint m_InputC
Definition: yolo.h:89
TensorInfo::blobName
std::string blobName
Definition: yolo.h:53
TensorInfo::volume
uint64_t volume
Definition: yolo.h:58
NetworkInfo
Holds all the file paths required to build a network.
Definition: yolo.h:39
Yolo::m_ConfigBlocks
std::vector< std::map< std::string, std::string > > m_ConfigBlocks
Definition: yolo.h:86
Yolo::m_NetworkType
const std::string m_NetworkType
Definition: yolo.h:80
Yolo::m_WtsFilePath
const std::string m_WtsFilePath
Definition: yolo.h:82
NvDsInferStatus
NvDsInferStatus
Enum for the status codes returned by NvDsInferContext.
Definition: nvdsinfer.h:218