load noncombined params from directory.
| 178 | |
| 179 | // load noncombined params from directory. |
| 180 | void LoadNonCombinedParamsPb(const std::string &model_dir, |
| 181 | cpp::ProgramDesc *cpp_prog, |
| 182 | const lite_api::CxxModelBuffer &model_buffer, |
| 183 | Scope *scope) { |
| 184 | auto *main_block = cpp_prog->GetBlock<cpp::BlockDesc>(0); |
| 185 | std::string log_info = "Loading non-combined params data from " + model_dir; |
| 186 | // Check param files format |
| 187 | // default format: non-combined params |
| 188 | for (auto &var : main_block->GetVars()) { |
| 189 | if (IsParamVarDesc(*var)) { |
| 190 | if (IsFileExists(model_dir + "/" + var->Name())) { |
| 191 | VLOG(4) << "reading weight " << var->Name(); |
| 192 | model_parser::BinaryFileReader reader(model_dir + "/" + var->Name()); |
| 193 | model_parser::pb::LoDTensorDeserializer loader; |
| 194 | switch (var->GetType()) { |
| 195 | case VarDescAPI::Type::LOD_TENSOR: |
| 196 | LoadLoDTensor(&loader, &reader, scope->Var(var->Name())); |
| 197 | break; |
| 198 | default: |
| 199 | CHECK(false) << "unknown weight type"; |
| 200 | } |
| 201 | } else { |
| 202 | std::string params_path{""}; |
| 203 | // format 1. model_dir/params |
| 204 | // format 2. model_dir/weights |
| 205 | // format 3. model_dir/pdiparams |
| 206 | if (IsFileExists(model_dir + "/params")) { |
| 207 | params_path = model_dir + "/params"; |
| 208 | } else if (IsFileExists(model_dir + "/weights")) { |
| 209 | params_path = model_dir + "/weights"; |
| 210 | } else if (IsFileExists(model_dir + "/model.pdiparams")) { |
| 211 | params_path = model_dir + "/model.pdiparams"; |
| 212 | } else if (IsFileExists(model_dir + "/inference.pdiparams")) { |
| 213 | params_path = model_dir + "/inference.pdiparams"; |
| 214 | } else { |
| 215 | PrintPbModelErrorMessage(); |
| 216 | } |
| 217 | log_info = "Loading params data from " + params_path; |
| 218 | LoadCombinedParamsPb(params_path, scope, *cpp_prog, model_buffer); |
| 219 | break; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | OPT_LOG << log_info; |
| 224 | } |
| 225 | |
| 226 | void LoadModelPb(const std::string &model_dir, |
| 227 | const std::string &model_file, |
no test coverage detected