MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ImportTensorFlowGraphDef

Function ImportTensorFlowGraphDef

tensorflow/lite/toco/import_tensorflow.cc:2642–2697  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2640} // namespace internal
2641
2642std::unique_ptr<Model> ImportTensorFlowGraphDef(
2643 const ModelFlags& model_flags, const TensorFlowImportFlags& tf_import_flags,
2644 const GraphDef& tf_graph) {
2645 LogDumpGraphDef(kLogLevelModelChanged, "AT IMPORT", tf_graph);
2646
2647 GraphDef inlined_graph(tf_graph);
2648 if (InlineAllFunctions(&inlined_graph)) {
2649 LogDumpGraphDef(kLogLevelModelChanged, "AFTER INLINING", inlined_graph);
2650 }
2651
2652 // Check input and output specification.
2653 for (const auto& specified_input_array : model_flags.input_arrays()) {
2654 CHECK(!absl::EndsWith(specified_input_array.name(), ":0"))
2655 << "Unsupported explicit zero output index: "
2656 << specified_input_array.name();
2657 }
2658 for (const string& specified_output_array : model_flags.output_arrays()) {
2659 CHECK(!absl::EndsWith(specified_output_array, ":0"))
2660 << "Unsupported explicit zero output index: " << specified_output_array;
2661 }
2662
2663 Model* model = new Model;
2664 internal::ConverterMapType converter_map;
2665
2666 // This is used for the TFLite "Full Flex Mode" conversion. All the ops are
2667 // imported as `TensorFlowUnsupportedOperator`, and later all these ops are
2668 // converted to TFLite Flex ops.
2669 if (!tf_import_flags.import_all_ops_as_unsupported) {
2670 converter_map = internal::GetTensorFlowNodeConverterMap();
2671 } else {
2672 converter_map = internal::GetTensorFlowNodeConverterMapForFlex();
2673 }
2674
2675 for (auto node : inlined_graph.node()) {
2676 StripZeroOutputIndexFromInputs(&node);
2677 auto status = internal::ImportTensorFlowNode(
2678 node, tf_import_flags, model_flags, model, converter_map);
2679 CHECK(status.ok()) << status.error_message();
2680 }
2681
2682 ResolveModelFlags(model_flags, model);
2683
2684 StripCaretFromArrayNames(model);
2685 AddExtraOutputs(model);
2686 FixNoMissingArray(model);
2687 FixNoOrphanedArray(model);
2688 FixOperatorOrdering(model);
2689 CheckInvariants(*model);
2690
2691 // if rnn state arrays are constant, make them transient
2692 for (const auto& rnn_state : model->flags.rnn_states()) {
2693 model->GetArray(rnn_state.state_array()).buffer = nullptr;
2694 }
2695
2696 return std::unique_ptr<Model>(model);
2697}
2698
2699std::unique_ptr<Model> ImportTensorFlowGraphDef(

Callers 1

ImportFunction · 0.85

Calls 15

LogDumpGraphDefFunction · 0.85
InlineAllFunctionsFunction · 0.85
EndsWithFunction · 0.85
ImportTensorFlowNodeFunction · 0.85
ResolveModelFlagsFunction · 0.85
StripCaretFromArrayNamesFunction · 0.85
AddExtraOutputsFunction · 0.85
FixNoMissingArrayFunction · 0.85
FixNoOrphanedArrayFunction · 0.85

Tested by

no test coverage detected