2 #ifndef _NNDEPLOY_INFERENCE_INFERENCE_H_
3 #define _NNDEPLOY_INFERENCE_INFERENCE_H_
348 bool is_share_context_ =
true;
354 bool is_external_stream_ =
false;
396 template <
typename T>
402 return std::make_shared<T>(type);
411 extern NNDEPLOY_CC_API std::map<base::InferenceType, std::shared_ptr<InferenceCreator>> &
419 template <
typename T>
virtual ~InferenceCreator()
virtual std::shared_ptr< Inference > createInference(base::InferenceType type)=0
virtual std::vector< device::Tensor * > getAllOutputTensorVector()
Get the All Output Tensor Vector object.
virtual std::string getInputName(int i)
Get the Input Name object.
virtual base::Status run()=0
推理
virtual base::Status deinit()=0
反初始化推理
virtual int getNumOfOutputTensor()
Get the Num Of Output Tensor object.
virtual int getNumOfInputTensor()
Get the Num Of Input Tensor object.
virtual base::Status setMemory(device::Buffer *buffer)
设置推理所需的内存(推理内存由外部分配)
virtual bool canOpInput()
是否可以操作推理框架内部分配的输入tensor
base::Param * getParam()
Get the Inference Param(这里使用基类指针)
virtual device::TensorDesc getInputTensorDesc(const std::string &name)
Get the Input Tensor Desc object.
Inference(base::InferenceType type)
device::Stream * getStream()
base::InferenceType type_
推理框架的类型
virtual bool isOutputDynamic()
是否为动态输出
virtual base::IntVector getInputShape(const std::string &name)
Get the Input Shape object.
virtual std::string getOutputName(int i)
Get the Output Name object.
base::Status setParam(base::Param *param)
Set the Inference Param(这里使用基类指针)
base::InferenceType getInferenceType()
virtual std::map< std::string, device::Tensor * > getAllOutputTensorMap()
Get the All Output Tensor Map object.
virtual bool isShareStream()
该推理实例是否与nndeploy共享一个stream
virtual device::Tensor * getInputTensor(const std::string &name)
Get the Input Tensor object.
virtual base::Status init()=0
初始化推理
virtual base::Status setInputTensor(const std::string &name, device::Tensor *input_tensor)
Set the Input Tensor object.
virtual bool isShareContext()
该推理实例是否与nndeploy共享一个context
virtual device::TensorDesc getOutputTensorAlignDesc(const std::string &name)
Get the Output Tensor Align Desc object.
virtual base::Status reshape(base::ShapeMap &shape_map)=0
针对动态输入的推理,设置输入tensor的shape
virtual device::Tensor * getOutputTensor(const std::string &name)
Get the Output Tensor object.
std::map< std::string, device::Tensor * > input_tensors_
输入tensor的map
virtual bool isInputDynamic()
是否为动态输入
virtual std::vector< device::Tensor * > getAllInputTensorVector()
Get the All Input Tensor Vector object.
virtual device::Tensor * getOutputTensorAfterRun(const std::string &name, base::DeviceType device_type, bool is_copy, base::DataFormat data_format=base::kDataFormatAuto)=0
Get the Output Tensor object.
virtual bool isBatch()
是否为多batch推理
virtual std::vector< std::string > getAllInputTensorName()
Get the All Input Tensor Name object.
virtual device::TensorDesc getInputTensorAlignDesc(const std::string &name)
Get the Input Tensor Align Desc object.
base::Status setParamSharedPtr(std::shared_ptr< base::Param > param)
virtual base::ShapeMap getAllInputShape()
Get the Output Shape object.
virtual float getGFLOPs()
获得推理计算量
base::DeviceType getDeviceType()
std::shared_ptr< base::Param > getParamSharedPtr()
base::ShapeMap getOptShape()
针对动态输入的推理,获取输入tensor的opt_shape
base::ShapeMap getMaxShape()
针对动态输入的推理,获取输入tensor的max_shape
void setStream(device::Stream *stream)
virtual std::map< std::string, device::Tensor * > getAllInputTensorMap()
Get the All Input Tensor Map object.
std::map< std::string, device::Tensor * > output_tensors_
输出tensor的map
virtual bool canOpOutput()
是否可以操作推理框架内部分配的输出tensor
std::shared_ptr< InferenceParam > inference_param_
推理框架的配置
base::ShapeMap getMinShape()
针对动态输入的推理,获取输入tensor的min_shape
std::map< std::string, device::Tensor * > external_input_tensors_
外部输入tensor的map
virtual int64_t getMemorySize()
获取推理所需的内存大小
virtual std::vector< std::string > getAllOutputTensorName()
Get the All Output Tensor Name object.
virtual device::TensorDesc getOutputTensorDesc(const std::string &name)
Get the Output Tensor Desc object.
TypeInferenceRegister(base::InferenceType type)
#define NNDEPLOY_CC_API
api
std::vector< int > IntVector
std::map< std::string, std::vector< int > > ShapeMap
std::shared_ptr< Inference > createInference(base::InferenceType type)
Create a Inference object.
std::map< base::InferenceType, std::shared_ptr< InferenceCreator > > & getGlobalInferenceCreatorMap()
Get the Global Inference Creator Map object.