seq2seq icon indicating copy to clipboard operation
seq2seq copied to clipboard

export SavedModel error

Open dream-catcher opened this issue 7 years ago • 7 comments

I try to export seq2seq model to SavedModel protobuf for later inferencing with java language.
According to guides from tensorflow(https://www.tensorflow.org/api_docs/python/tf/saved_model/builder/SavedModelBuilder), we need to create a SavedModelBuilder, and then add meta graph to a session. But I find that, the framework in tensorflow use MonitoredTrainingSession as the session , and it will finalize the graph, so we I call builder.add_meta_graph_and_variables in after_create_session(self, session, coord) function in hooks.py , it reports errors: "graph is finalized and cannot be modified" And I try to add SavedModelBuilder in somewhere else, it does't have a session, the API can't be called. But when the session is created, the graph is already been finalized, and can't be changed anymore!

So can anyone help me how to export SavedModel for this framework?

dream-catcher avatar Sep 04 '17 08:09 dream-catcher

Same problem here, I was not able to successfully export a tensorflow servable. Can anyone help?

brucechou1983 avatar Jan 06 '18 03:01 brucechou1983

Hi guys, I come across the same problem and try to solve this in another way. When training within MonitoredTrainingSession, I use a tf.train.SessionRunHook to save the model with name 'last_model.ckpt' at end(session). After training, I use 'with tf.Session() as sess:' to open another session, and restore 'last_model.ckpt' in this new session. So now I can use builder.add_meta_graph_and_variables and builder.saver() to save model as pb. If there's any other good solutions, pls let me know. Thanks.

Orion-Chen avatar Mar 14 '18 03:03 Orion-Chen

@Orpin Hi, have can I use tf.train.SessionRunHook. Is there any example, I saw your code, but still confused..

CangHaiQingYue avatar May 30 '18 12:05 CangHaiQingYue

@CangHaiQingYue Hi, I found another solution and forgot to update the comment. You can use this piece of code before creating tf.saved_model.builder to unfinalize the graph sess.graph._unsafe_unfinalize() And then it is ok to do builder.save().

Orion-Chen avatar May 31 '18 04:05 Orion-Chen

is that possible to use this method defined in tensorflow with seq2seq? Or is there built-in support to export model by seq2seq?

There is also something like _maybe_export in official repo any usage with this possible?

Need to use the exported model in tf serving.

sathyarr avatar Feb 12 '19 12:02 sathyarr

Hi guys, I come across the same problem and try to solve this in another way. When training within MonitoredTrainingSession, I use a tf.train.SessionRunHook to save the model with name 'last_model.ckpt' at end(session). After training, I use 'with tf.Session() as sess:' to open another session, and restore 'last_model.ckpt' in this new session. So now I can use builder.add_meta_graph_and_variables and builder.saver() to save model as pb. If there's any other good solutions, pls let me know. Thanks.

Could you share the code snippet?

sathyarr avatar Feb 12 '19 12:02 sathyarr

Hi guys, I come across the same problem and try to solve this in another way. When training within MonitoredTrainingSession, I use a tf.train.SessionRunHook to save the model with name 'last_model.ckpt' at end(session). After training, I use 'with tf.Session() as sess:' to open another session, and restore 'last_model.ckpt' in this new session. So now I can use builder.add_meta_graph_and_variables and builder.saver() to save model as pb. If there's any other good solutions, pls let me know. Thanks.

Could you share the code snippet?

You can read these two pages:https://github.com/Microsoft/samples-for-ai/blob/master/projects/StyleTransfer/StyleTransferTraining/src/train.py#L218 and https://github.com/Microsoft/vs-tools-for-ai/issues/16

ghtwht avatar Mar 08 '19 04:03 ghtwht