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

Function LoadModelNaiveV0FromFile

lite/model_parser/model_parser.cc:784–836  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

782}
783#ifndef LITE_ON_TINY_PUBLISH
784void LoadModelNaiveV0FromFile(const std::string &filename,
785 Scope *scope,
786 cpp::ProgramDesc *cpp_prog) {
787 CHECK(cpp_prog);
788 CHECK(scope);
789 cpp_prog->ClearBlocks();
790 // ModelFile
791 const std::string prog_path = filename;
792
793 // Offset
794 model_parser::BinaryFileReader reader(filename, 0);
795
796 // (1)get meta version
797 uint16_t meta_version;
798 reader.Read(&meta_version, sizeof(uint16_t));
799 VLOG(4) << "Meta_version:" << meta_version;
800
801 // (2)get opt version
802 char opt_version[16];
803 const uint64_t opt_version_length = 16 * sizeof(char);
804 reader.Read(opt_version, opt_version_length);
805 VLOG(4) << "Opt_version:" << static_cast<const char *>(opt_version);
806
807 // check version, opt's version should be consistent with current Paddle-Lite
808 // version.
809 const std::string paddle_version = version();
810 const std::string opt_version_str = opt_version;
811 if (paddle_version != opt_version_str) {
812 LOG(FATAL) << "Error: the version of opt that transformed this model "
813 "is not consistent with current Paddle-Lite version."
814 "\n version of opt:"
815 << static_cast<const char *>(opt_version)
816 << "\n version of current Paddle-Lite:" << paddle_version;
817 }
818
819 // (3)get topo_size
820 uint64_t topo_size;
821 reader.Read(&topo_size, sizeof(uint64_t));
822
823 // (4)get topo data
824 naive_buffer::BinaryTable topo_table;
825 topo_table.LoadFromFile(prog_path, reader.current(), topo_size);
826 // transform topo_data into cpp::ProgramDesc
827 naive_buffer::proto::ProgramDesc nb_proto_prog(&topo_table);
828 nb_proto_prog.Load();
829 naive_buffer::ProgramDesc nb_prog(&nb_proto_prog);
830 TransformProgramDescAnyToCpp(nb_prog, cpp_prog);
831
832 // (5)Load Params
833 LoadCombinedParamsNaive(
834 prog_path, reader.current() + topo_size, scope, *cpp_prog, false);
835 VLOG(4) << "Load naive buffer model in '" << filename << "' successfully";
836}
837#endif // LITE_ON_TINY_PUBLISH
838void LoadModelFbsFromFile(model_parser::BinaryFileReader *reader,
839 Scope *scope,

Callers 1

LoadModelNaiveFromFileFunction · 0.85

Calls 7

LoadCombinedParamsNaiveFunction · 0.85
LoadFromFileMethod · 0.80
LoadMethod · 0.60
versionFunction · 0.50
ClearBlocksMethod · 0.45
ReadMethod · 0.45
currentMethod · 0.45

Tested by

no test coverage detected