title: Tensorflow serving in Go
body: <p>I am trying to run a keras model in Go. First I train the model in python:</p>
  
  <pre><code>import keras as krs
  from keras import backend as K
  import tensorflow as tf
  
  sess = tf.Session()
  K.set_session(sess)
  K._LEARNING_PHASE = tf.constant(0)
  K.set_learning_phase(0)
  
  m1 = krs.models.Sequential()
  m1.Add(krs.layers.Dense(..., name="inputNode"))
  ...
  m1.Add(krs.layers.Dense(..., activation="softmax", name="outputNode"))
  m1.compile(...)
  m1.fit(...)
  </code></pre>
  
  <p>Then I understand that it is advised that the model is frozen - to convert  placeholder to constants.</p>
  
  <pre><code>saver = tf.train.Saver()
  tf.train.write_graph(sess.graph_def, '.', 'my_model.pbtxt')
  saver.save(sess, save_path="my_model.ckpt")
  
  from tensorflow.python.tools import freeze_graph
  from tensorflow.python.tools import optimize_for_inference_lib
  
  freeze_graph.freeze_graph(input_graph = 'my_model.pbtxt',  input_saver = "",
                   input_binary = False, input_checkpoint = "my_model.ckpt", output_node_names = "outputNode/Softmax",
                   restore_op_name = "save/restore_all", filename_tensor_name = "save/Const:0",
                   output_graph = "frozen_my_model.pb", clear_devices = True, initializer_nodes = "")
  </code></pre>
  
  <p>When trying to use the frozen model in Golang:</p>
  
  <pre><code>model, err := tf.LoadSavedModel("frozen_my_model.pb", []string{"serve"}, nil)
  </code></pre>
  
  <p>It returns an error that the tag serve is not found <code>SavedModel load for tags { serve }; Status: fail.</code></p>
  
  <p>My questions are therefore:</p>
  
  <ol>
  <li>How do you freeze a model in python, then load it in Go</li>
  <li>I do this to speed up inference in Go - is it correct that freezing
  models will improve inference speed?</li>
  <li>I have noted that another function exists <code>optimize_for_inference</code>, how would this implemented in the above setting?</li>
  </ol>