Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

export SavedModel error #296

Open
dream-catcher opened this issue Sep 4, 2017 · 7 comments
Open

export SavedModel error #296

dream-catcher opened this issue Sep 4, 2017 · 7 comments

Comments

@dream-catcher
Copy link

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?

@brucechou1983
Copy link

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

@Orion-Chen
Copy link

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.

@CangHaiQingYue
Copy link

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

@Orion-Chen
Copy link

@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().

@sathyarr
Copy link

sathyarr commented Feb 12, 2019

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
Copy link

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?

@ghtwht
Copy link

ghtwht commented Mar 8, 2019

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 microsoft/vs-tools-for-ai#16

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants