| 23 | |
| 24 | namespace paddle2onnx { |
| 25 | bool PaddleParser::LoadProgram(const std::string& model) { |
| 26 | prog = std::make_shared<paddle2onnx::framework::proto::ProgramDesc>(); |
| 27 | std::ifstream fin(model, std::ios::in | std::ios::binary); |
| 28 | if (!fin.is_open()) { |
| 29 | P2OLogger() << "Failed to read model file: " << model |
| 30 | << ", please make sure your model file or file path is valid." |
| 31 | << std::endl; |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | std::string contents; |
| 36 | fin.seekg(0, std::ios::end); |
| 37 | contents.clear(); |
| 38 | contents.resize(fin.tellg()); |
| 39 | fin.seekg(0, std::ios::beg); |
| 40 | fin.read(&(contents.at(0)), contents.size()); |
| 41 | fin.close(); |
| 42 | |
| 43 | if (!prog->ParseFromString(contents)) { |
| 44 | P2OLogger() << "Failed to parse paddlepaddle model from read content." |
| 45 | << std::endl; |
| 46 | return false; |
| 47 | } |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | bool PaddleParser::LoadProgram(const void* model_buffer, int64_t model_size) { |
| 52 | prog = std::make_shared<paddle2onnx::framework::proto::ProgramDesc>(); |