| 14 | #include "tensorflowConverter.hpp" |
| 15 | |
| 16 | int tensorflow2MNNNet(const std::string inputModel, const std::string bizCode, |
| 17 | std::unique_ptr<MNN::NetT> &netT) { |
| 18 | // Load tensorflow model. |
| 19 | tensorflow::GraphDef tfGraph; |
| 20 | bool success = tf_read_proto_from_binary(inputModel.c_str(), &tfGraph); |
| 21 | DCHECK(success) << "read_proto_from_binary failed!"; |
| 22 | if (!success) { |
| 23 | MNN_ERROR("[ERROR] MNNConvert just support tensorflow frozen graph model. Model file is not tf frozen graph model.\n"); |
| 24 | return 1; |
| 25 | } |
| 26 | |
| 27 | TFGraphResolver resolver(tfGraph); |
| 28 | for (int i = 0; i < resolver.graph_size(); ++i) { |
| 29 | const TFGraph *graph = resolver.graph(i); |
| 30 | auto graph_proto = graph->ToProto(); |
| 31 | // The graph indexed by 0 is main graph. |
| 32 | if (i == 0) { |
| 33 | netT->oplists = std::move(graph_proto->nodes); |
| 34 | netT->tensorName = graph_proto->tensors; |
| 35 | } else { |
| 36 | netT->subgraphs.push_back(std::move(graph_proto)); |
| 37 | } |
| 38 | } |
| 39 | netT->sourceType = MNN::NetSource_TENSORFLOW; |
| 40 | netT->bizCode = bizCode; |
| 41 | return 0; |
| 42 | } |
no test coverage detected