tensorflow / tensor2tensor

Library of deep learning models and datasets designed to make deep learning more accessible and accelerate ML research.
Apache License 2.0
15.5k stars 3.49k forks source link

Export/Server tensor2tensor as a .pb file instead of .pbtxt #853

Closed NehaPathapati closed 6 years ago

NehaPathapati commented 6 years ago

Description

I would like to know how to export the tensor2tensor serving as a .pb file, rather than a .pbtxt file.

Alternately, how can I get the output node names from the checkpoints/.pbtxt file? ...

tensor2tensor==1.6.3 tensorflow==1.8.0

OS: CentOS

Python 2.7.5

For bugs: reproduction and error logs

# Steps to reproduce:
...
# Error logs:
...
Littlenova commented 6 years ago

The tensor2tensor trainer doesn't appear to package this feature as an argument or flag, nonetheless, it is possible using ash's answer from stack overflow:

`import tensorflow as tf from google.protobuf import text_format

with open('/tmp/myfile.pbtxt') as f: txt = f.read() gdef = text_format.Parse(txt, tf.GraphDef())

tf.train.write_graph(gdef, '/tmp', 'myfile.pb', as_text=False)`

rsepassi commented 6 years ago

Thanks @Littlenova

ndvbd commented 6 years ago

@Littlenova, I tried it and it says:

google.protobuf.text_format.ParseError: 1:1 : Message type "tensorflow.GraphDef" has no field named "saved_model_schema_version".

I tried it on the .pbtxt which was created using tensor2tensor.serving.export

summerfan2018 commented 6 years ago

Yes, I am facing the same issue too.

xu-song commented 6 years ago

+1

google.protobuf.text_format.ParseError: 1:1 : 
Message type "tensorflow.GraphDef" has no field named "saved_model_schema_version".
marcbelmont commented 6 years ago

Actually the format is closer to MetaGraphDef (but not exactly). Export file should be used with tensorflow-model-server as described in https://github.com/tensorflow/tensor2tensor/tree/v1.9.0/tensor2tensor/serving

hhxxttxsh commented 6 years ago

@marcbelmont Is it possible to freeze the savedmodel files (.pbtxt and variables) into .pb for mobile or embedded applications? I have got the same error in the process of doing that: google.protobuf.text_format.ParseError: 1:1 : Message type "tensorflow.GraphDef" has no field named "saved_model_schema_version".

kudou1994 commented 5 years ago

@marcbelmont Is it possible to freeze the savedmodel files (.pbtxt and variables) into .pb for mobile or embedded applications? I have got the same error in the process of doing that: google.protobuf.text_format.ParseError: 1:1 : Message type "tensorflow.GraphDef" has no field named "saved_model_schema_version". I also encountered this problem. Have you solved it? ask for help. please my wechat rensheng_1994 mail:5625060@qq.com