|
|
NVIDIA DeepStream SDK API Reference
|
9.1 Release
|
Go to the documentation of this file.
18 #ifndef __NVDSINFER_MODEL_BUILDER_H__
19 #define __NVDSINFER_MODEL_BUILDER_H__
23 #include <condition_variable>
29 #include <unordered_map>
32 #include <NvInferRuntime.h>
33 #include <NvOnnxParser.h>
35 #include <nvdsinfer_custom_impl.h>
37 #include "nvdsinfer_tlt.h"
60 const std::shared_ptr<DlLibHandle>& dllib)
63 virtual bool isValid()
const = 0;
81 const std::shared_ptr<DlLibHandle>& handle =
nullptr)
83 m_ModelName(initParams.onnxFilePath) {}
85 bool isValid()
const override {
return !m_ModelName.empty(); }
86 const char*
getModelName()
const override {
return m_ModelName.c_str(); }
91 std::string m_ModelName;
108 const std::shared_ptr<DlLibHandle>& handle);
114 return (
bool)m_CustomParser;
125 return m_CustomParser->hasFullDimsSupported();
129 std::unique_ptr<IModelParser> m_CustomParser;
133 class TrtModelBuilder;
142 std::tuple<nvinfer1::DataType, nvinfer1::TensorFormats>;
144 std::tuple<nvinfer1::DataType, nvinfer1::DeviceType>;
171 bool sanityCheck()
const override;
175 nvinfer1::EnumMax<nvinfer1::OptProfileSelector>()>;
193 bool sanityCheck()
const override;
203 : m_Engine(std::move(
engine)), m_DlaCore(dlaCore) {}
206 const std::shared_ptr<nvinfer1::IRuntime>& runtime,
int dlaCore = -1,
207 const std::shared_ptr<DlLibHandle>& dlHandle =
nullptr,
208 nvinfer1::IPluginFactory* pluginFactory =
nullptr);
212 bool hasDla()
const {
return m_DlaCore >= 0; }
216 std::vector<NvDsInferBatchDimsLayerInfo>& layersInfo);
218 int profileIdx, std::vector<NvDsInferBatchDimsLayerInfo>& layersInfo);
232 return m_Engine.get();
238 std::shared_ptr<nvinfer1::IRuntime> m_Runtime;
239 std::unique_ptr<nvinfer1::ICudaEngine> m_Engine;
240 std::shared_ptr<DlLibHandle> m_DlHandle;
241 nvinfer1::IPluginFactory* m_RuntimePluginFactory =
nullptr;
245 nvinfer1::IBuilderConfig *
const builderConfig,
248 nvinfer1::ICudaEngine *& cudaEngine);
263 const std::shared_ptr<DlLibHandle>& dlHandle =
nullptr,
bool isEngineFile =
false);
271 m_Int8Calibrator = std::move(calibrator);
283 std::string& suggestedPathName);
289 std::unique_ptr<TrtEngine> buildEngine(
290 nvinfer1::INetworkDefinition& network,
BuildParams& options);
295 const std::string& path, nvinfer1::ICudaEngine& engine);
300 const std::string& path,
int dla = -1);
311 std::unique_ptr<TrtEngine> buildEngine();
315 std::unique_ptr<TrtEngine> getCudaEngineFromCustomLib(
327 std::unique_ptr<BuildParams> createImplicitParams(
329 std::unique_ptr<BuildParams> createDynamicParams(
331 void initCommonParams(
337 nvinfer1::ILogger& m_Logger;
338 std::shared_ptr<DlLibHandle> m_DlLib;
339 std::shared_ptr<BaseModelParser> m_Parser;
340 std::unique_ptr<BuildParams> m_Options;
341 std::unique_ptr<nvinfer1::IBuilder> m_Builder;
342 std::unique_ptr<nvinfer1::IBuilderConfig> m_BuilderConfig;
343 std::unique_ptr<nvinfer1::INetworkDefinition> m_Network;
344 std::shared_ptr<nvinfer1::IInt8Calibrator> m_Int8Calibrator;
351 nvinfer1::IBuilderConfig *
const builderConfig,
354 nvinfer1::ICudaEngine *& cudaEngine);
~OnnxModelParser() override=default
bool hasFullDimsSupported() const override
bool isValid() const override
std::array< nvinfer1::Dims, nvinfer1::EnumMax< nvinfer1::OptProfileSelector >()> ProfileDims
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.
const char * safeStr(const char *str)
NvDsInferStatus parseModel(nvinfer1::INetworkDefinition &network) override
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.
BaseModelParser(const NvDsInferContextInitParams ¶ms, const std::shared_ptr< DlLibHandle > &dllib)
std::string int8CalibrationFilePath
NvDsInferStatus serializeEngine(const std::string &path, nvinfer1::ICudaEngine &engine)
NvDsInferNetworkMode networkMode
NvDsInferNetworkMode
Defines internal data formats used by the inference engine.
std::tuple< nvinfer1::DataType, nvinfer1::TensorFormats > TensorIOFormat
@ NvDsInferNetworkMode_FP32
std::unordered_map< std::string, LayerDevicePrecision > layerDevicePrecisions
decltype(&NvDsInferCudaEngineGet) NvDsInferCudaEngineGetFcnDeprecated
nvinfer1::ICudaEngine & engine()
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)
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 ~BaseModelParser()
NvDsInferContextInitParams m_ModelParams
std::tuple< nvinfer1::DataType, nvinfer1::DeviceType > LayerDevicePrecision
std::vector< TensorIOFormat > inputFormats
bool isValid() const override
const char * getModelName() const override
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...
@ 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.
std::unordered_map< std::string, TensorIOFormat > outputFormats
virtual NvDsInferStatus configBuilder(TrtModelBuilder &builder)=0
NvDsInferStatus getFullDimsLayersInfo(int profileIdx, std::vector< NvDsInferBatchDimsLayerInfo > &layersInfo)
const char * getModelName() const override
nvinfer1::ICudaEngine * operator->()
std::vector< ProfileDims > inputProfileDims
Holds build parameters required for full dimensions network.
std::shared_ptr< DlLibHandle > m_LibHandle
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
std::unique_ptr< nvonnxparser::IParser > m_OnnxParser
std::vector< nvinfer1::Dims > inputDims
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.