MCPcopy Create free account
hub / github.com/alibaba/MNN / json2mnn

Method json2mnn

tools/converter/source/common/cli.cpp:1090–1112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1088}
1089
1090bool Cli::json2mnn(const char* jsonFile, const char* modelFile) {
1091 rapidjson::Document document;
1092 {
1093 std::ifstream fileNames(jsonFile);
1094 std::ostringstream output;
1095 output << fileNames.rdbuf();
1096 auto outputStr = output.str();
1097 document.Parse(outputStr.c_str());
1098 if (document.HasParseError()) {
1099 MNN_ERROR("Invalid json\n");
1100 return 0;
1101 }
1102 }
1103 auto object = document.GetObject();
1104 flatbuffers::FlatBufferBuilder builder;
1105 builder.ForceDefaults(true);
1106 auto table = MNN::NetTypeTable();
1107 auto offset = Json2Flatbuffer::writeJsonToFlatbuffer(table, builder, object);
1108 builder.Finish(offset);
1109 std::ofstream outputOs(modelFile, std::ios::binary);
1110 outputOs.write((char*)builder.GetBufferPointer(), builder.GetSize());
1111 return true;
1112}
1113
1114};

Callers

nothing calls this directly

Calls 8

NetTypeTableFunction · 0.85
strMethod · 0.45
ParseMethod · 0.45
c_strMethod · 0.45
HasParseErrorMethod · 0.45
FinishMethod · 0.45
writeMethod · 0.45
GetSizeMethod · 0.45

Tested by

no test coverage detected