title: Serializing and deserializing Tensorflow model in memory and continue training
body: <p>I have seen variations of this question asked, but I haven't quite found a satisfactory answer yet. Basically, I would like to do the equivalent from keras <code>model.to_json()</code>, <code>model.get_weights()</code>, <code>model.from_json()</code>, <code>model.set_weights()</code> to tensorflow. I think I am getting close to there, but I am at a point where I am stuck. I'd prefer if I could get the weights and graph in the same string, but I understand if that isn't possible.</p>
  
  <p>Currently, what I have is: </p>
  
  <pre><code>g = optimizer.minimize(loss_op,
                         global_step=tf.train.get_global_step())
  de = g.graph.as_graph_def()
  json_string = json_format.MessageToJson(de)
  
  gd = tf.GraphDef()
  gd = json_format.Parse(json_string, gd)
  </code></pre>
  
  <p>That seems to create the graph fine, but obviously the meta graph is not included for variable, weights, etc. There is also the meta graph, but the only thing I see is export_meta_graph, which doesn't seem to serialize in the same manner. I saw that MetaGraph has a proto function, but I don't know how to serialize those variables.</p>
  
  <p>So in short, how would you take a tensorflow model (model as in weights, graph, etc), serialize it to a string (preferably json), then deserialize it and continue training or serve predictions.</p>
  
  <p>Here are things that get me close to there and I have tried, but mostly has limitations in needing to write to disk, which I can't do in this case:</p>
  
  <p><a href="https://gist.github.com/tokestermw/795cc1fd6d0c9069b20204cbd133e36b" rel="nofollow noreferrer">Gist on GitHub</a></p>
  
  <p><a href="https://stackoverflow.com/questions/41575442/tensorflow-export-compute-graph-to-xml-json-etc">This is the closest one I found, but the link to serializing a metagraph doesn't exist.</a></p>