Saving Checkpoints in SavedModel format

Viewed 761

I am using tensorflow 1.15, I have checkpoints saved from training the model. What I want to do is save the model in SavedModel format.

The method I am using is restoring the checkpoints and then trying to save the model in the SavedModel format.

trained_checkpoint_prefix = 'checkpoint_size/checkpoint_size'
export_dir = os.path.join('SavedModel', '0') 
loaded_graph = tf.Graph()
with tf.Session(graph=loaded_graph) as sess:
   # Restore from checkpoint
   loader = tf.train.import_meta_graph(trained_checkpoint_prefix + '.meta')
   loader.restore(sess, trained_checkpoint_prefix)

   # Export checkpoint to SavedModel
   builder = tf.saved_model.builder.SavedModelBuilder(export_dir)
   builder.add_meta_graph_and_variables(sess,[tf.saved_model.tag_constants.TRAINING, tf.saved_model.tag_constants.SERVING],strip_default_attrs=True)
   builder.save()

It gives me a ValueError: At least 2 variables have the same name

I just want to convert the checkpoints to SavedModel format.

0 Answers
Related