运行import_pb_to_tensorboard.py时出现_DecodeError('意外的端组标记。')

问题描述 投票:0回答:1

我正在尝试在android / iOS设备上部署tensorflow模型的方法。所以我做了:1)使用tf.saved_model.builder.SavedModelBuilder来获取.pb文件中的模型2)使用tf.saved_model.loader.load()来验证我是否可以恢复模型

但是,当我想使用import_pb_to_tensorboard.py进一步检查模型时,请遵循以下建议:1)https://medium.com/@daj/how-to-inspect-a-pre-trained-tensorflow-model-5fd2ee79ced0 2)https://hackernoon.com/running-a-tensorflow-model-on-ios-and-android-ce89446c8143

我收到了这个错误:

    File "/Users/rjtang/_hack/env.tensorflow_src/lib/python3.4/site-packages/google/protobuf/internal/python_message.py", line 1083, in MergeFromString
if self._InternalParse(serialized, 0, length) != length:
    .....
    File "/Users/rjtang/_hack/env.tensorflow_src/lib/python3.4/site-packages/google/protobuf/internal/decoder.py", line 612, in DecodeRepeatedField
if value.add()._InternalParse(buffer, pos, new_pos) != new_pos:
    ....
    File "/Users/rjtang/_hack/env.tensorflow_src/lib/python3.4/site-packages/google/protobuf/internal/decoder.py", line 746, in DecodeMap
raise _DecodeError('Unexpected end-group tag.')

代码和生成的.pb文件在这里:

我使用的tensorflow版本是从源代码“HEAD在v1.4.1分离”构建的

tensorflow tensorflow-serving
1个回答
0
投票

好吧,我明白现在发生了什么。 Tensorflow至少有3种方法来保存和加载模型。该图将被序列化为以下3个protobuf对象之一:

  1. GraphDef
  2. MetaGrapiDef
  3. SavedModel

您只需要正确地反序列化它,例如https://github.com/rjt10/hear_it/blob/master/urban_sound/model_check.py

对于Android,TensorFlowInferenceInterface()需要GraphDef,https://github.com/tensorflow/tensorflow/blob/e2be6d4c4fc9f1b7f6040b51b23190c14202e797/tensorflow/contrib/android/java/org/tensorflow/contrib/android/TensorFlowInferenceInterface.java#L541

这解释了原因。

© www.soinside.com 2019 - 2024. All rights reserved.