【发布时间】:2019-11-22 06:21:54
【问题描述】:
在给定 tensorflow 冻结推理图的输入的情况下,我想提取 pbtxt 文件。为了做到这一点,我使用以下脚本:
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')
例如,我使用的是 ssd mobilenet 架构。使用上面的代码,我得到了 pbtxt 的输出,但我不能使用它。参考下图
右图:移动网络架构的原始 pbtxt 文件图片
左:使用上述脚本获得的 pbtxt 文件的图像。
当我使用右边的官方 pbtxt 时,我得到了正确的结果。但是,当我使用使用上述脚本生成的 LEFT pbtxt 时,我没有得到任何预测
我在 open cv DNN 模块上使用这些预测
tensorflowNet = cv2.dnn.readNetFromTensorflow('ssd_mobilenet_v1_coco_2017_11_17/frozen_inference_graph.pb', 'pbtxt/protobuf.pbtxt')
如何将 mobilenet 冻结推理图转换为正确的 pbtxt 格式以便进行推理?
参考资料: https://gist.github.com/Arafatk/c063bddb9b8d17a037695d748db4f592
【问题讨论】:
标签: python opencv tensorflow deep-learning computer-vision