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

Function convert

tools/cpp/ConvertToFullQuant.hpp:171–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171void convert(std::string modelFile) {
172 std::unique_ptr<MNN::NetT> netT;
173 std::ifstream input(modelFile);
174 std::ostringstream outputOs;
175 outputOs << input.rdbuf();
176 netT = MNN::UnPackNet(outputOs.str().c_str());
177 auto net = netT.get();
178
179 std::vector<int> netNeedEraseIndices;
180 for (int i = 0; i < net->oplists.size(); i++) {
181 auto& op = net->oplists[i];
182 ConvertOp(op, i, net, nullptr, netNeedEraseIndices);
183 }
184 std::reverse(netNeedEraseIndices.begin(), netNeedEraseIndices.end());
185 for (int i = 0; i < netNeedEraseIndices.size(); i++) {
186 net->oplists.erase(net->oplists.begin() + netNeedEraseIndices[i]);
187 }
188
189 for (auto& subgraph : net->subgraphs) {
190 std::vector<int> subgraphNeedEraseIndices;
191 for (int i = 0; i < subgraph->nodes.size(); i++) {
192 auto& op = subgraph->nodes[i];
193 ConvertOp(op, i, net, subgraph.get(), subgraphNeedEraseIndices);
194 }
195 std::reverse(subgraphNeedEraseIndices.begin(), subgraphNeedEraseIndices.end());
196 for (int i = 0; i < subgraphNeedEraseIndices.size(); i++) {
197 subgraph->nodes.erase(subgraph->nodes.begin() + subgraphNeedEraseIndices[i]);
198 }
199 }
200
201 flatbuffers::FlatBufferBuilder builderOutput(1024);
202 builderOutput.ForceDefaults(true);
203 auto len = MNN::Net::Pack(builderOutput, net);
204 builderOutput.Finish(len);
205 std::ofstream output(modelFile);
206 output.write((const char*)builderOutput.GetBufferPointer(), builderOutput.GetSize());
207}
208
209} // namespace ConvertToFullQuant
210

Callers 15

_quantizeModelEMAMethod · 0.50
onExecuteMethod · 0.50
trainMethod · 0.50
convertMethod · 0.50
tensorConvertMethod · 0.50
onResizeMethod · 0.50
onCopyBufferMethod · 0.50
onExecuteMethod · 0.50
onExecuteMethod · 0.50
onExecuteMethod · 0.50
convertMethod · 0.50
onCopyBufferMethod · 0.50

Calls 13

UnPackNetFunction · 0.85
ConvertOpFunction · 0.85
reverseFunction · 0.50
c_strMethod · 0.45
strMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45
FinishMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected