tensorflow1.0-解决加载图模型时报错google.protobuf.message.DecodeError: Error parsing message

本文介绍了一种常见的图模型加载失败的问题及解决方案。通过调整保存图模型的方式,从文本格式改为二进制格式,成功解决了在TensorFlow中加载图模型时报错的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用以下代码,加载图模型的时候会报错

#保存图模型
    tf.train.write_graph(sess.graph_def, graph_dir, 'graph.pbtxt',as_text=True)
    #加载图模型
    with tf.gfile.FastGFile("modle_graph/graph.pbtxt","rb") as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())

graph_def.ParseFromString(f.read())
google.protobuf.message.DecodeError: Error parsing message

解决:

tf.train.write_graph(sess.graph_def, graph_dir, 'graph.pbtxt',as_text=False)
While parsing a protocol message, the input ended unexpectedly in the middle of a field. This could mean either that the input has been truncated or that an embedded message misreported its own length. 2025-06-12 21:47:02,722 [12] ERROR PitayaClient.Zmq.ZeroMqClient - at Google.Protobuf.CodedInputStream.RefillBuffer(Boolean mustSucceed) in T:\src\github\protobuf\csharp\src\Google.Protobuf\CodedInputStream.cs:line 1426 at Google.Protobuf.CodedInputStream.ReadRawByte() in T:\src\github\protobuf\csharp\src\Google.Protobuf\CodedInputStream.cs:line 1476 at Google.Protobuf.CodedInputStream.ReadRawVarint64() in T:\src\github\protobuf\csharp\src\Google.Protobuf\CodedInputStream.cs:line 1205 at Google.Protobuf.UnknownFieldSet.MergeFieldFrom(CodedInputStream input) in T:\src\github\protobuf\csharp\src\Google.Protobuf\UnknownFieldSet.cs:line 190 at Google.Protobuf.UnknownFieldSet.MergeFieldFrom(UnknownFieldSet unknownFields, CodedInputStream input) in T:\src\github\protobuf\csharp\src\Google.Protobuf\UnknownFieldSet.cs:line 269 at FCoreProto4GDR.PosiItem.MergeFrom(CodedInputStream input) in E:\GUI\ArdaClient\protobufLib\ProtoGenerated\Fcore4GDR.cs:line 4431 at Google.Protobuf.CodedInputStream.ReadMessage(IMessage builder) in T:\src\github\protobuf\csharp\src\Google.Protobuf\CodedInputStream.cs:line 621 at FCoreProto4GDR.PubDetails.MergeFrom(CodedInputStream input) in E:\GUI\ArdaClient\protobufLib\ProtoGenerated\Fcore4GDR.cs:line 9135 at Google.Protobuf.MessageExtensions.MergeFrom(IMessage message, Byte[] data, Boolean discardUnknownFields, ExtensionRegistry registry) in T:\src\github\protobuf\csharp\src\Google.Protobuf\MessageExtensions.cs:line 214 at Google.Protobuf.MessageParser`1.ParseFrom(Byte[] data) in T:\src\github\protobuf\csharp\src\Google.Protobuf\MessageParser.cs:line 247 at PitayaClient.Zmq.ZeroMqClient.SubscribeOrdRelated() in D:\project\GUI\ardaclient\PitayaClient\Zmq\ZeroMqClient.cs:line 37
06-14
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值