Tensorflow 1.14,修复:“google.protobuf.message.DecodeError”:解析消息时出错

问题描述

Protobuf v3.15 错误:google.protobuf.message.DecodeError,当使用 tf.graph() 时,将 TensorFlow 模型加载到内存中。将上面的 tf.graph() 片段更改为 TensorFlow v2 后,出现了同样的错误

我尝试过 protobuf 3.12.4(在 colab 上相同),出现同样的错误

Traceback (most recent call last):
  File "object_detection/webcam.py",line 25,in <module>
    od_graph_def.ParseFromString(serialized_graph)
google.protobuf.message.DecodeError: Error parsing message
[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674) SourceReaderCB::~SourceReaderCB terminating async callback

我重新安装了不同的 protobuf 版本,但仍然出现相同的错误

我已经使用 TensorFlow 1.14 cpu 训练了一个“SSD MobileNet”模型,用于使用 OpenCV 进行网络摄像头对象检测。安装所需的 TensorFlow 库后,我运行 model_builder_tf1.py 并成功通过了所有 21 个测试。

代码片段:使用 tf.graph() 将 TensorFlow 模型加载到内存中

detection_graph = tf.Graph()
with detection_graph.as_default():
    od_graph_def = tf.compat.v1.GraphDef()
with tf.gfile.GFile(PATH_TO_FROZEN_GRAPH,'rb') as fid:
    serialized_graph = fid.read()
    od_graph_def.ParseFromString(serialized_graph)
    tf.import_graph_def(od_graph_def,name='')
    sess = tf.compat.v1.Session(graph=detection_graph) 

请注意,TensorFlow 1.14 安装在 conda 环境中。

使用protobuf==3.8,又出现了一个错误

AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key

有人能解决这个问题吗。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...