Python 从Tensorflow中的文件导入图形
我正试图从位于此处的DeepFovea项目导入Facebook发布的protobuf: 这是我的密码:Python 从Tensorflow中的文件导入图形,python,facebook,tensorflow,protocol-buffers,Python,Facebook,Tensorflow,Protocol Buffers,我正试图从位于此处的DeepFovea项目导入Facebook发布的protobuf: 这是我的密码: import tensorflow.compat.v1 as tf from tensorflow.python.platform import gfile tf.GraphDef.FromString(tf.gfile.Open("./input_graph.pb",'rb').read()) 我收到这个错误: google.protobuf.message.DecodeError: E
import tensorflow.compat.v1 as tf
from tensorflow.python.platform import gfile
tf.GraphDef.FromString(tf.gfile.Open("./input_graph.pb",'rb').read())
我收到这个错误:
google.protobuf.message.DecodeError: Error parsing message
我应该以不同的方式加载这个protobuf吗?在谷歌搜索了很多次之后,发现您需要像这样解析它:
from google.protobuf import text_format
with tf.gfile.GFile(graph_filename, "rb") as f:
graph_def = tf.GraphDef()
graph_str = f.read()
text_format.Merge(graph_str, graph_def)
从这里的代码示例:感谢您的回答-我刚刚尝试按照您的指示使用json_格式加载,并收到此新错误:google.protobuf.json_format.ParseError:加载json失败:无法解码json对象。更新了答案。此方法创建GraphDef时没有错误,但如果后续代码无法使用,请告诉我,我将进一步研究它