Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从Tensorflow中的文件导入图形_Python_Facebook_Tensorflow_Protocol Buffers - Fatal编程技术网

Python 从Tensorflow中的文件导入图形

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

我正试图从位于此处的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: 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时没有错误,但如果后续代码无法使用,请告诉我,我将进一步研究它