nndeploy C++ API  0.2.0
nndeploy C++ API
interpret.h
Go to the documentation of this file.
1 
2 #ifndef _NNDEPLOY_IR_INTERPRET_H_
3 #define _NNDEPLOY_IR_INTERPRET_H_
4 
5 #include "nndeploy/ir/ir.h"
6 
7 namespace nndeploy {
8 namespace ir {
9 
11  public:
18  // Interpret();
19 
25  explicit Interpret(ModelDesc *model_desc = nullptr, bool is_external = false);
26 
32  virtual ~Interpret();
33 
56  const std::vector<std::string> &model_value,
57  const std::vector<ValueDesc> &input = std::vector<ValueDesc>()) = 0;
58 
63  // 打印模型结构
64  base::Status dump(std::ostream &oss = std::cout);
65 
85 #ifdef ENABLE_NNDEPLOY_SAFETENSORS_CPP
86  base::Status saveModel(std::string &structure_str,
87  std::shared_ptr<safetensors::safetensors_t> st_ptr);
88 #endif
108  base::Status saveModelToFile(const std::string &structure_file_path,
109  const std::string &weight_file_path);
110 
118 
119  public:
125  ModelDesc *model_desc_ = nullptr;
126 
130  bool is_external_ = false;
131 };
132 
138  public:
139  virtual ~InterpretCreator() {};
140  // virtual Interpret *createInterpret(base::ModelType type) = 0;
142  ir::ModelDesc *model_desc = nullptr,
143  bool is_external = false) = 0;
144  virtual std::shared_ptr<Interpret> createInterpretSharedPtr(
145  base::ModelType type, ir::ModelDesc *model_desc = nullptr,
146  bool is_external = false) = 0;
147 };
148 
154 template <typename T>
156  virtual Interpret *createInterpret(base::ModelType type,
157  ir::ModelDesc *model_desc = nullptr,
158  bool is_external = false) {
159  return new T(model_desc, is_external);
160  }
161  virtual std::shared_ptr<Interpret> createInterpretSharedPtr(
162  base::ModelType type, ir::ModelDesc *model_desc = nullptr,
163  bool is_external = false) {
164  return std::make_shared<T>(model_desc, is_external);
165  }
166 };
167 
173 extern NNDEPLOY_CC_API
174  std::map<base::ModelType, std::shared_ptr<InterpretCreator>> &
176 
182 template <typename T>
184  public:
186  getGlobalInterpretCreatorMap()[type] = std::shared_ptr<T>(new T());
187  }
188 };
189 
197  base::ModelType type, ir::ModelDesc *model_desc = nullptr,
198  bool is_external = false);
199 
200 extern NNDEPLOY_CC_API std::shared_ptr<Interpret> createInterpretSharedPtr(
201  base::ModelType type, ir::ModelDesc *model_desc = nullptr,
202  bool is_external = false);
203 
204 } // namespace ir
205 } // namespace nndeploy
206 
207 #endif /* _NNDEPLOY_IR_INTERPRET_H_ */
解释器的创建类
Definition: interpret.h:137
virtual Interpret * createInterpret(base::ModelType type, ir::ModelDesc *model_desc=nullptr, bool is_external=false)=0
virtual std::shared_ptr< Interpret > createInterpretSharedPtr(base::ModelType type, ir::ModelDesc *model_desc=nullptr, bool is_external=false)=0
base::Status saveModelToFile(const std::string &structure_file_path, const std::string &weight_file_path)
存储模型结构以及模型权重
ModelDesc * getModelDesc()
获取模型描述
virtual ~Interpret()
虚析构函数
virtual base::Status interpret(const std::vector< std::string > &model_value, const std::vector< ValueDesc > &input=std::vector< ValueDesc >())=0
解释模型
Interpret(ModelDesc *model_desc=nullptr, bool is_external=false)
解释器类的默认构造函数
base::Status dump(std::ostream &oss=std::cout)
参照onnx的格式,描述模型的结构
Definition: ir.h:109
解释器的创建类模板
Definition: interpret.h:155
解释器的创建类的注册类模板
Definition: interpret.h:183
TypeInterpretRegister(base::ModelType type)
Definition: interpret.h:185
#define NNDEPLOY_CC_API
api
Definition: macro.h:29
std::shared_ptr< Interpret > createInterpretSharedPtr(base::ModelType type, ir::ModelDesc *model_desc=nullptr, bool is_external=false)
std::map< base::ModelType, std::shared_ptr< InterpretCreator > > & getGlobalInterpretCreatorMap()
Get the Global Interpret Creator Map object.
Interpret * createInterpret(base::ModelType type, ir::ModelDesc *model_desc=nullptr, bool is_external=false)
Create a Interpret object.