| 2640 | } // namespace internal |
| 2641 | |
| 2642 | std::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 | |
| 2699 | std::unique_ptr<Model> ImportTensorFlowGraphDef( |
no test coverage detected