NVIDIA DeepStream SDK API Reference

7.0 Release
trt_utils.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 
14 #ifndef __TRT_UTILS_H__
15 #define __TRT_UTILS_H__
16 
17 #include <set>
18 #include <map>
19 #include <string>
20 #include <vector>
21 #include <cassert>
22 #include <iostream>
23 #include <fstream>
24 
25 #include "NvInfer.h"
26 
27 #define UNUSED(expr) (void)(expr)
28 #define DIVUP(n, d) ((n) + (d)-1) / (d)
29 
30 std::string trim(std::string s);
31 float clamp(const float val, const float minVal, const float maxVal);
32 bool fileExists(const std::string fileName, bool verbose = true);
33 std::vector<float> loadWeights(const std::string weightsFilePath, const std::string& networkType);
34 std::string dimsToString(const nvinfer1::Dims d);
35 int getNumChannels(nvinfer1::ITensor* t);
36 uint64_t get3DTensorVolume(nvinfer1::Dims inputDims);
37 
38 // Helper functions to create yolo engine
39 nvinfer1::ILayer* netAddMaxpool(int layerIdx, std::map<std::string, std::string>& block,
40  nvinfer1::ITensor* input, nvinfer1::INetworkDefinition* network);
41 nvinfer1::ILayer* netAddConvLinear(int layerIdx, std::map<std::string, std::string>& block,
42  std::vector<float>& weights,
43  std::vector<nvinfer1::Weights>& trtWeights, int& weightPtr,
44  int& inputChannels, nvinfer1::ITensor* input,
45  nvinfer1::INetworkDefinition* network);
46 nvinfer1::ILayer* netAddConvBNLeaky(int layerIdx, std::map<std::string, std::string>& block,
47  std::vector<float>& weights,
48  std::vector<nvinfer1::Weights>& trtWeights, int& weightPtr,
49  int& inputChannels, nvinfer1::ITensor* input,
50  nvinfer1::INetworkDefinition* network);
51 nvinfer1::ILayer* netAddUpsample(int layerIdx, std::map<std::string, std::string>& block,
52  std::vector<float>& weights,
53  std::vector<nvinfer1::Weights>& trtWeights, int& inputChannels,
54  nvinfer1::ITensor* input, nvinfer1::INetworkDefinition* network);
55 void printLayerInfo(std::string layerIndex, std::string layerName, std::string layerInput,
56  std::string layerOutput, std::string weightPtr);
57 
58 #endif
clamp
float clamp(const float val, const float minVal, const float maxVal)
trim
std::string trim(std::string s)
inputDims
NvDsInferDimsCHW inputDims
Holds the input dimensions for the model.
Definition: nvdsinfer_context.h:270
netAddConvLinear
nvinfer1::ILayer * netAddConvLinear(int layerIdx, std::map< std::string, std::string > &block, std::vector< float > &weights, std::vector< nvinfer1::Weights > &trtWeights, int &weightPtr, int &inputChannels, nvinfer1::ITensor *input, nvinfer1::INetworkDefinition *network)
fileExists
bool fileExists(const std::string fileName, bool verbose=true)
netAddUpsample
nvinfer1::ILayer * netAddUpsample(int layerIdx, std::map< std::string, std::string > &block, std::vector< float > &weights, std::vector< nvinfer1::Weights > &trtWeights, int &inputChannels, nvinfer1::ITensor *input, nvinfer1::INetworkDefinition *network)
loadWeights
std::vector< float > loadWeights(const std::string weightsFilePath, const std::string &networkType)
dimsToString
std::string dimsToString(const nvinfer1::Dims d)
netAddMaxpool
nvinfer1::ILayer * netAddMaxpool(int layerIdx, std::map< std::string, std::string > &block, nvinfer1::ITensor *input, nvinfer1::INetworkDefinition *network)
netAddConvBNLeaky
nvinfer1::ILayer * netAddConvBNLeaky(int layerIdx, std::map< std::string, std::string > &block, std::vector< float > &weights, std::vector< nvinfer1::Weights > &trtWeights, int &weightPtr, int &inputChannels, nvinfer1::ITensor *input, nvinfer1::INetworkDefinition *network)
get3DTensorVolume
uint64_t get3DTensorVolume(nvinfer1::Dims inputDims)
printLayerInfo
void printLayerInfo(std::string layerIndex, std::string layerName, std::string layerInput, std::string layerOutput, std::string weightPtr)
getNumChannels
int getNumChannels(nvinfer1::ITensor *t)