tensorflow / models

Models and examples built with TensorFlow
Other
77.18k stars 45.75k forks source link

##Textsum - TF serving export error - 'No variables to save' #695

Closed xtr33me closed 7 years ago

xtr33me commented 7 years ago

I'm trying to go about setting up the decode functionality from the "textsum" model for TF serving. Upon running the below code I am getting an error stating "no variables to save" when the assignment of Saver(sharded=True) occurs. That aside, I also don't understand what I am supposed to assign to the "classification_signature" and the "named_graph_signature" variables for the exporting of the results via textsum decode.

Any help on what I'm missing here...sure it is a bit.

Code is at the bottom and the stack trace is directly below this:

Traceback (most recent call last): File "/home/daniel/Documents/git/serving/tf_models/textsum/export_textsum.py", line 25, in Export saver = tf.train.Saver(sharded=True) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 986, in init self.build() File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1006, in build raise ValueError("No variables to save") ValueError: No variables to save

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import sys
import tensorflow as tf
from tensorflow.contrib.session_bundle import exporter

tf.app.flags.DEFINE_string("export_dir", "exports/textsum",
                           "Directory where to export textsum model.")

tf.app.flags.DEFINE_string('checkpoint_dir', 'log_root',
                            "Directory where to read training checkpoints.")
tf.app.flags.DEFINE_integer('export_version', 1, 'version number of the model.')
tf.app.flags.DEFINE_bool("use_checkpoint_v2", False,
                     "If true, write v2 checkpoint files.")
FLAGS = tf.app.flags.FLAGS

def Export():
    try:
        saver = tf.train.Saver(sharded=True)
        with tf.Session() as sess:
            # Restore variables from training checkpoints.
            ckpt = tf.train.get_checkpoint_state(FLAGS.checkpoint_dir)
            if ckpt and ckpt.model_checkpoint_path:
                saver.restore(sess, ckpt.model_checkpoint_path)
                global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
                print('Successfully loaded model from %s at step=%s.' %
                    (ckpt.model_checkpoint_path, global_step))
            else:
                print('No checkpoint file found at %s' % FLAGS.checkpoint_dir)
                return

            # Export model
            print('Exporting trained model to %s' % FLAGS.export_dir)
            init_op = tf.group(tf.initialize_all_tables(), name='init_op')
            model_exporter = exporter.Exporter(saver)

            classification_signature = <-- Unsure what should be assigned here

            named_graph_signature = <-- Unsure what should be assigned here

            model_exporter.init(
                init_op=init_op,
                default_graph_signature=classification_signature,
                named_graph_signatures=named_graph_signature)

            model_exporter.export(FLAGS.export_dir, tf.constant(global_step), sess)
            print('Successfully exported model to %s' % FLAGS.export_dir)
    except:
        err = sys.exc_info()
        print ('Unexpected error:', err[0], ' - ', err[1])
        pass

def main(_):
    Export()

if __name__ == "__main__":
    tf.app.run()
poxvoculi commented 7 years ago

This sort of question is better asked on stackoverflow, as it is not a specific bug report or feature request. You will likely get a more helpful response if you include a stack trace of your error. Just guessing from the error message you cite, you might find one of these helpful:

http://stackoverflow.com/questions/36281129/no-variable-to-save-error-in-tensorflow

http://stackoverflow.com/questions/33759623/tensorflow-how-to-restore-a-previously-saved-model-python/

poxvoculi commented 7 years ago

Take a look at #5901 https://github.com/tensorflow/tensorflow/issues/5901

xtr33me commented 7 years ago

@poxvoculi thanks a bunch bud! Going to close this as I should be able to get my answer in one of these links.

GoingMyWay commented 7 years ago

Please create your network or initialize your network before initilizing the Saver.

xtr33me commented 7 years ago

Thanks @GoingMyWay for taking the time to respond. I unfortunately have still yet to successfully export and host the textsum model. I believe the export is correct now, but I can't be totally positive as I have not been able to get a client connecting to it. If you think you might be able to see where I have gone wrong, in either export_textsum.py or textsum_client.py I would love to hear what you have to say. IF you don't have the time then just disregard :) I appreciate the assist regardless!

PratsBhatt commented 7 years ago

@xtr33me were you able to serve the seq2seq model? I am working on this too but I am finding very hard to transfer the serving tutorial to seq2seq. Any help is appreciated. Thanks .

xtr33me commented 7 years ago

@PratsBhatt Unfortunately not. I am going to be jumping back on this attempt but have ran into wall after wall with this one. Will post here if I ever figure out a solution.