I want to extract pbtxt file given an input of tensorflow frozen inference graph. In order to do this I am using the below script :
import tensorflow as tf
#from google.protobuf import text_format
from tensorflow.python.platform import gfile
def converter(filename):
with gfile.FastGFile(filename,'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def, name='')
tf.train.write_graph(graph_def, 'pbtxt/', 'protobuf.pbtxt', as_text=True)
print(graph_def)
return
#converter('ssd_mobilenet_v1_coco_2017_11_17/frozen_inference_graph.pb') # here you can write the name of the file to be converted
# and then a new file will be made in pbtxt directory.
converter('ssd_mobilenet_v1_coco_2017_11_17/frozen_inference_graph.pb')
As an example, I am using ssd mobilenet architecture. Using the above code I get the output as pbtxt but I cannot use it. For reference see the image below
RIGHT: Image of original pbtxt file of mobile-net architecture
LEFT: Image of pbtxt file obtained by using above script.
When I use The official pbtxt on the RIGHT I get correct results. But, I do not get any prediction when I use LEFT pbtxt which I generated using above script
I am using these predictions on open cv DNN module
tensorflowNet = cv2.dnn.readNetFromTensorflow('ssd_mobilenet_v1_coco_2017_11_17/frozen_inference_graph.pb', 'pbtxt/protobuf.pbtxt')
How do I convert mobilenet frozen inference graph into proper pbtxt format so that I can get inference ?
References: https://gist.github.com/Arafatk/c063bddb9b8d17a037695d748db4f592