Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use .pbtxt instead of .pb file in using Tensor flow model

I created a Tensorflow model which generated .pbtxt file. Can I use this file in building Android Application to use the generated model by renaming it to .pb file.

Thanks in Advance.

like image 200
Android_programmer_office Avatar asked Dec 07 '22 17:12

Android_programmer_office


1 Answers

If the .pbtxt file is really a textual representation of the TensorFlow graph, then no, the Android APIs currently do not accept that and instead require a binary representation of the graph.

That said, if you have the .pbtxt file, you can easily convert it to a binary protocol buffer with a few lines of Python:

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)

Alternatively, if you control the pipeline that generated the pbtxt file to begin with, perhaps you could change that to write out the file in binary format?

Hope that helps.

like image 110
ash Avatar answered Dec 10 '22 13:12

ash