MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle-Lite / LoadModelPb

Function LoadModelPb

lite/model_parser/model_parser.cc:226–273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

224}
225
226void LoadModelPb(const std::string &model_dir,
227 const std::string &model_file,
228 const std::string &param_file,
229 Scope *scope,
230 cpp::ProgramDesc *cpp_prog,
231 bool combined,
232 const lite_api::CxxModelBuffer &model_buffer) {
233 CHECK(cpp_prog) << "The input cpp program pointer var is nullptr.";
234 CHECK(scope) << "The input scope var is nullptr.";
235 cpp_prog->ClearBlocks();
236
237 // Load model topology data from file.
238 std::string prog_path =
239 model_buffer.is_empty()
240 ? FindModelFileName(model_dir, model_file, combined)
241 : "";
242 if (model_buffer.is_empty()) {
243 OPT_LOG << "Loading topology data from " << prog_path;
244 }
245 framework::proto::ProgramDesc pb_proto_prog =
246 *LoadProgram(prog_path, model_buffer);
247 pb::ProgramDesc pb_prog(&pb_proto_prog);
248 // Transform to cpp::ProgramDesc
249 TransformProgramDescAnyToCpp(pb_prog, cpp_prog);
250
251 // Load params data from file.
252 // NOTE: Only main block be used now.
253 CHECK(combined || model_buffer.is_empty())
254 << "If you want use the model_from_memory,"
255 << " you should load the combined model using cfg.set_model_buffer "
256 "interface.";
257 if (!combined) {
258 LoadNonCombinedParamsPb(model_dir, cpp_prog, model_buffer, scope);
259 } else {
260 if (model_buffer.is_empty()) {
261 OPT_LOG << "Loading params data from " << param_file;
262 CHECK(IsFileExists(param_file))
263 << "Error, the param file '" << param_file
264 << "' is not existed. Please confirm that you have inputed "
265 "correct param file path.";
266 }
267
268 LoadCombinedParamsPb(param_file, scope, *cpp_prog, model_buffer);
269 }
270 if (model_buffer.is_empty()) {
271 OPT_LOG << "1. Model is successfully loaded!";
272 }
273}
274
275void SaveModelPb(const std::string &model_dir,
276 const Scope &exec_scope,

Callers 4

TESTFunction · 0.85
BuildMethod · 0.85
BuildMethod · 0.85
TESTFunction · 0.85

Calls 7

FindModelFileNameFunction · 0.85
LoadProgramFunction · 0.85
LoadNonCombinedParamsPbFunction · 0.85
IsFileExistsFunction · 0.85
LoadCombinedParamsPbFunction · 0.85
is_emptyMethod · 0.80
ClearBlocksMethod · 0.45

Tested by 2

TESTFunction · 0.68
TESTFunction · 0.68