title: tensorflow: save model and load model
body: <p>Currently trying to make this <a href="https://github.com/SenticNet/conv-emotion/tree/master/ICON-end-to-end" rel="nofollow noreferrer">repo</a> works. </p>
  
  <p>I'm trying to save the trained model in the local machine so can be applied later. I read in tensorflow's <a href="https://www.tensorflow.org/api_docs/python/tf/saved_model/save" rel="nofollow noreferrer">doc</a>, seems pretty intuitive to save the model, by calling <code>tf.save_model.save(object)</code>. But I'm not sure how to apply.</p>
  
  <p>Original code is here: <a href="https://github.com/SenticNet/conv-emotion/blob/master/ICON-end-to-end/model.py" rel="nofollow noreferrer">model.py</a>
  Following is my changes:</p>
  
  <pre><code>import tensorflow as tf
  
  class ICON(tf.Module): # make it a tensorflow modul
  
      def __init__(self, config, embeddingMatrix, session=None):
  
      def _build_inputs(self):
  
      def _build_vars(self):
  
      def _convolution(self, input_to_conv):
  
      def _inference(self):
  
      def batch_fit(self, queries, ownHistory, otherHistory, labels):
  
          feed_dict = {self._input_queries: queries, self._own_histories: ownHistory, self._other_histories: otherHistory,
                       self._labels: labels}
          loss, _ = self._sess.run([self.loss_op, self.train_op], feed_dict=feed_dict)
          return loss
  
      def predict(self, queries, ownHistory, otherHistory, ):
  
          feed_dict = {self._input_queries: queries, self._own_histories: ownHistory, self._other_histories: otherHistory}
          return self._sess.run(self.predict_op, feed_dict=feed_dict)
  
      def save(self): # attempt to save the model
          tf.saved_model.save(
              self, './output/model')
  </code></pre>
  
  <p>The code above produces ValueError as following:
  <code>ValueError: Tensor("ICON/CNN/embedding_matrix:0", shape=(16832, 300), dtype=float32_ref) must be from the same graph as Tensor("saver_filename:0", shape=(), dtype=string).</code></p>