|
NVIDIA DeepStream SDK API Reference
|
7.1 Release
|
Go to the documentation of this file.
13 #ifndef __NVDSINFER_MODEL_BUILDER_H__
14 #define __NVDSINFER_MODEL_BUILDER_H__
18 #include <condition_variable>
24 #include <unordered_map>
27 #include <NvInferRuntime.h>
28 #include <NvOnnxParser.h>
55 const std::shared_ptr<DlLibHandle>& dllib)
58 virtual bool isValid()
const = 0;
76 const std::shared_ptr<DlLibHandle>& handle =
nullptr)
78 m_ModelName(initParams.onnxFilePath) {}
80 bool isValid()
const override {
return !m_ModelName.empty(); }
81 const char*
getModelName()
const override {
return m_ModelName.c_str(); }
86 std::string m_ModelName;
103 const std::shared_ptr<DlLibHandle>& handle);
109 return (
bool)m_CustomParser;
120 return m_CustomParser->hasFullDimsSupported();
124 std::unique_ptr<IModelParser> m_CustomParser;
128 class TrtModelBuilder;
137 std::tuple<nvinfer1::DataType, nvinfer1::TensorFormats>;
139 std::tuple<nvinfer1::DataType, nvinfer1::DeviceType>;
166 bool sanityCheck()
const override;
170 nvinfer1::EnumMax<nvinfer1::OptProfileSelector>()>;
188 bool sanityCheck()
const override;
198 : m_Engine(std::move(
engine)), m_DlaCore(dlaCore) {}
201 const std::shared_ptr<nvinfer1::IRuntime>& runtime,
int dlaCore = -1,
202 const std::shared_ptr<DlLibHandle>& dlHandle =
nullptr,
203 nvinfer1::IPluginFactory* pluginFactory =
nullptr);
207 bool hasDla()
const {
return m_DlaCore >= 0; }
211 std::vector<NvDsInferBatchDimsLayerInfo>& layersInfo);
213 int profileIdx, std::vector<NvDsInferBatchDimsLayerInfo>& layersInfo);
227 return m_Engine.get();
233 std::shared_ptr<nvinfer1::IRuntime> m_Runtime;
234 std::unique_ptr<nvinfer1::ICudaEngine> m_Engine;
235 std::shared_ptr<DlLibHandle> m_DlHandle;
236 nvinfer1::IPluginFactory* m_RuntimePluginFactory =
nullptr;
240 nvinfer1::IBuilderConfig *
const builderConfig,
243 nvinfer1::ICudaEngine *& cudaEngine);
258 const std::shared_ptr<DlLibHandle>& dlHandle =
nullptr,
bool isEngineFile =
false);
266 m_Int8Calibrator = std::move(calibrator);
278 std::string& suggestedPathName);
284 std::unique_ptr<TrtEngine> buildEngine(
285 nvinfer1::INetworkDefinition& network,
BuildParams& options);
290 const std::string& path, nvinfer1::ICudaEngine& engine);
295 const std::string& path,
int dla = -1);
306 std::unique_ptr<TrtEngine> buildEngine();
310 std::unique_ptr<TrtEngine> getCudaEngineFromCustomLib(
322 std::unique_ptr<BuildParams> createImplicitParams(
324 std::unique_ptr<BuildParams> createDynamicParams(
326 void initCommonParams(
332 nvinfer1::ILogger& m_Logger;
333 std::shared_ptr<DlLibHandle> m_DlLib;
334 std::shared_ptr<BaseModelParser> m_Parser;
335 std::unique_ptr<BuildParams> m_Options;
336 std::unique_ptr<nvinfer1::IBuilder> m_Builder;
337 std::unique_ptr<nvinfer1::IBuilderConfig> m_BuilderConfig;
338 std::unique_ptr<nvinfer1::INetworkDefinition> m_Network;
339 std::shared_ptr<nvinfer1::IInt8Calibrator> m_Int8Calibrator;
346 nvinfer1::IBuilderConfig *
const builderConfig,
349 nvinfer1::ICudaEngine *& cudaEngine);
~OnnxModelParser() override=default
bool hasFullDimsSupported() const override
std::unordered_map< std::string, TensorIOFormat > inputFormats
bool isValid() const override
NvDsInferStatus getLayerInfo(int idx, NvDsInferLayerInfo &layer)
NvDsInferStatus getImplicitLayersInfo(std::vector< NvDsInferBatchDimsLayerInfo > &layersInfo)
virtual bool sanityCheck() const
NvDsInferTensorOrder
Defines UFF input layer orders.
Holds build parameters required for implicit batch dimension network.
Implementation of ModelParser for custom models.
Helper class written on top of nvinfer1::ICudaEngine.
std::shared_ptr< DlLibHandle > m_LibHandle
NvDsInferStatus parseModel(nvinfer1::INetworkDefinition &network) override
std::vector< ProfileDims > inputProfileDims
Implementation of ModelParser for ONNX models derived from BaseModelParser.
bool NvDsInferCudaEngineGetFromTltModel(nvinfer1::IBuilder *const builder, nvinfer1::IBuilderConfig *const builderConfig, const NvDsInferContextInitParams *const initParams, nvinfer1::DataType dataType, nvinfer1::ICudaEngine *&cudaEngine)
Decodes and creates a CUDA engine file from a TLT encoded model.
Helper class to build models and generate the TensorRT ICudaEngine required for inference.
std::unordered_map< std::string, TensorIOFormat > outputFormats
BaseModelParser(const NvDsInferContextInitParams ¶ms, const std::shared_ptr< DlLibHandle > &dllib)
std::string int8CalibrationFilePath
NvDsInferStatus serializeEngine(const std::string &path, nvinfer1::ICudaEngine &engine)
NvDsInferNetworkMode networkMode
bool NvDsInferCudaEngineGet(nvinfer1::IBuilder *builder, NvDsInferContextInitParams *initParams, nvinfer1::DataType dataType, nvinfer1::ICudaEngine *&cudaEngine) __attribute__((deprecated("Use 'engine-create-func-name' config parameter instead")))
The NvDsInferCudaEngineGet interface has been deprecated and has been replaced by NvDsInferEngineCrea...
NvDsInferNetworkMode
Defines internal data formats used by the inference engine.
std::unique_ptr< nvonnxparser::IParser > m_OnnxParser
std::tuple< nvinfer1::DataType, nvinfer1::TensorFormats > TensorIOFormat
@ NvDsInferNetworkMode_FP32
nvinfer1::ICudaEngine & engine()
bool(* NvDsInferEngineCreateCustomFunc)(nvinfer1::IBuilder *const builder, nvinfer1::IBuilderConfig *const builderConfig, const NvDsInferContextInitParams *const initParams, nvinfer1::DataType dataType, nvinfer1::ICudaEngine *&cudaEngine)
Type definition for functions that build and return a CudaEngine for custom models.
virtual bool isValid() const =0
TrtModelBuilder(int gpuId, nvinfer1::ILogger &logger, const std::shared_ptr< DlLibHandle > &dlHandle=nullptr, bool isEngineFile=false)
Holds information about one layer in the model.
std::unique_ptr< TrtEngine > deserializeEngine(const std::string &path, int dla=-1)
std::array< nvinfer1::Dims, nvinfer1::EnumMax< nvinfer1::OptProfileSelector >()> ProfileDims
virtual ~BaseModelParser()
NvDsInferContextInitParams m_ModelParams
std::tuple< nvinfer1::DataType, nvinfer1::DeviceType > LayerDevicePrecision
bool isValid() const override
const char * getModelName() const override
@ NvDsInferTensorOrder_kNCHW
OnnxModelParser(const NvDsInferContextInitParams &initParams, const std::shared_ptr< DlLibHandle > &handle=nullptr)
std::unique_ptr< TrtEngine > buildModel(const NvDsInferContextInitParams &initParams, std::string &suggestedPathName)
Holds the initialization parameters required for the NvDsInferContext interface.
virtual NvDsInferStatus configBuilder(TrtModelBuilder &builder)=0
decltype(&NvDsInferCudaEngineGet) NvDsInferCudaEngineGetFcnDeprecated
NvDsInferStatus getFullDimsLayersInfo(int profileIdx, std::vector< NvDsInferBatchDimsLayerInfo > &layersInfo)
const char * getModelName() const override
nvinfer1::ICudaEngine * operator->()
const char * safeStr(const char *str)
std::vector< nvinfer1::Dims > inputDims
std::unordered_map< std::string, LayerDevicePrecision > layerDevicePrecisions
Holds build parameters required for full dimensions network.
Holds build parameters common to implicit batch dimension/full dimension networks.
NvDsInferTensorOrder inputOrder
static const size_t kWorkSpaceSize
CustomModelParser(const NvDsInferContextInitParams &initParams, const std::shared_ptr< DlLibHandle > &handle)
NvDsInferStatus parseModel(nvinfer1::INetworkDefinition &network) override
bool hasFullDimsSupported() const override
TrtEngine(std::unique_ptr< nvinfer1::ICudaEngine > &&engine, int dlaCore=-1)
void setInt8Calibrator(std::unique_ptr< nvinfer1::IInt8Calibrator > &&calibrator)
NvDsInferStatus
Enum for the status codes returned by NvDsInferContext.