title: Invalid GraphDef in Tensorflow 2.2.0 saved model while using TF_GraphImportGraphDef in c_api
body: <p>I saved a keras model in tf 2.2.0 in Python via:</p>
  <pre><code>model.save('model', save_format='tf')
  </code></pre>
  <p>And it gives me a saved_model.pb in the &quot;model&quot; directory. I want to make inference via c_api, and the following code using the function: TF_LoadSessionFromSavedModel works fine.</p>
  <pre><code>int main() {
      TF_Graph *Graph = TF_NewGraph();
      TF_Status *Status = TF_NewStatus();
      TF_SessionOptions *SessionOpts = TF_NewSessionOptions();
      TF_Buffer *RunOpts = NULL;
  
      const char *saved_model_dir = &quot;model/&quot;;
      const char *tags = &quot;serve&quot;;
  
      int ntags = 1;
      TF_Session *Session = TF_LoadSessionFromSavedModel(SessionOpts, RunOpts, saved_model_dir, &amp;tags, ntags, Graph, NULL, Status);
  
      if (TF_GetCode(Status) == TF_OK)
      {
          printf(&quot;TF_LoadSessionFromSavedModel OK\n&quot;);
      }
      else
      {
          printf(&quot;%s&quot;, TF_Message(Status));
      }
      return 0;
  }
  </code></pre>
  <p>However, if I wanted to directly use the saved_model.pb in the &quot;model&quot; directory via TF_GraphImportGraphDef, it gives me the &quot;Invalid GraphDef&quot; errors:</p>
  <pre><code>int main(int argc, char const *argv[]){
      TF_Buffer *Graph_Def = read_file(&quot;model/saved_model.pb&quot;);
      TF_Graph *Graph = TF_NewGraph();
      TF_Status *Status = TF_NewStatus();
      TF_ImportGraphDefOptions *Opts = TF_NewImportGraphDefOptions();
      TF_GraphImportGraphDef(Graph, Graph_Def, Opts, Status);
      TF_DeleteImportGraphDefOptions(Opts);
      if (TF_GetCode(Status) != TF_OK)
      {
          fprintf(stderr, &quot;ERROR: Unable to import graph %s\n&quot;, TF_Message(Status));
          return 1;
      }
      fprintf(stdout, &quot;Successfully imported graph\n&quot;);
      return 0;
  }
  </code></pre>
  <p>I guess maybe the saved_model.pb is different from the freeze_graph version in v1. But I cannot find out why the failure happened.
  So, is there any way to save a tf2 keras model in a valid .pb file that can be used independently through<br />
  TF_GraphImportGraphDef?</p>
  <p>Many thanks in advance.</p>