相关疑难解决方法(0)

TF保存/恢复图在tf.GraphDef.ParseFromString()失败

基于这个转换训练的张量流模型到protobuf我试图保存/恢复TF图没有成功.

这是救星:

with tf.Graph().as_default():
    variable_node = tf.Variable(1.0, name="variable_node")
    output_node = tf.mul(variable_node, 2.0, name="output_node")
    sess = tf.Session()
    init = tf.initialize_all_variables()
    sess.run(init)
    output = sess.run(output_node)
    tf.train.write_graph(sess.graph.as_graph_def(), summ_dir, 'model_00_g.pbtxt', as_text=True)
    #self.assertNear(2.0, output, 0.00001)
    saver = tf.train.Saver()
    saver.save(sess, saver_path)
Run Code Online (Sandbox Code Playgroud)

它产生model_00_g.pbtxt了文本图形描述.几乎从freeze_graph_test.py复制粘贴.

这是读者:

with tf.Session() as sess:

    with tf.Graph().as_default():
        graph_def = tf.GraphDef()
        graph_path = '/mnt/code/test_00/log/2016-02-11.22-37-46/model_00_g.pbtxt'
        with open(graph_path, "rb") as f:
            proto_b = f.read()
            #print proto_b   # -> I can see it
            graph_def.ParseFromString(proto_b) # no luck..
            _ = tf.import_graph_def(graph_def, name="")

    print …
Run Code Online (Sandbox Code Playgroud)

tensorflow

6
推荐指数
1
解决办法
1万
查看次数

google.protobuf.message.DecodeError:解析类型为“tensorflow.GraphDef”的消息时出错

我正在训练模型并保存它,现在我尝试加载但无法执行。我也在之前的帖子中看到过,但是一些参考链接不起作用,或者我尝试了一些方法,仍然无法解决问题。

代码片段:

#load model

with tf.io.gfile.GFile(args.model, "rb") as f:
    graph_def = tf.compat.v1.GraphDef()
    graph_def.ParseFromString(f.read())

# with tf.Graph().as_default() as graph:
generated_image_1, generated_image_2, generated_image_3, = tf.graph_util.import_graph_def(
        graph_def, 
        input_map={'input_image' : input_tensor, 'short_edge_1' : short_edge_1, 'short_edge_2' : short_edge_2, 'short_edge_3' : short_edge_3}, 
        return_elements=['style_subnet/conv-block/resize_conv_1/output:0', 'enhance_subnet/resize_conv_1/output:0', 'refine_subnet/resize_conv_1/output:0'],  
        producer_op_list=None
    )
Run Code Online (Sandbox Code Playgroud)

错误

Traceback (most recent call last):

  File "stylize.py", line 97, in <module>
    main()
  File "stylize.py", line 57, in main
    graph_def.ParseFromString(f.read())
google.protobuf.message.DecodeError: Error parsing message with type 'tensorflow.GraphDef'
Run Code Online (Sandbox Code Playgroud)

注意:如果需要更多相关信息,请务必在此处添加。让我知道

python image-processing deep-learning tensorflow tensorboard

6
推荐指数
1
解决办法
1万
查看次数

如何修复:创建张量流文本摘要时出现“google.protobuf.message.DecodeError:解析消息时出错”

我正在尝试运行一个脚本以从 tensorflow .pb 模型中获取文本摘要,如下所示:

    OPS counts:
    Squeeze : 1
    Softmax : 1
    BiasAdd : 1
    Placeholder : 1
    AvgPool : 1
    Reshape : 2
    ConcatV2 : 9
    MaxPool : 13
    Sub : 57
    Rsqrt : 57
    Relu : 57
    Conv2D : 58
    Add : 114
    Mul : 114
    Identity : 231
    Const : 298
Run Code Online (Sandbox Code Playgroud)

我总体上尝试将 .pb 模型转换为 .coremlmodel 并关注这篇文章:

https://hackernoon.com/integrating-tensorflow-model-in-an-ios-app-cecf30b9068d

从 .pb 模型中获取文本摘要是朝着这个目标迈出的一步。我尝试运行来创建文本摘要的代码如下:

import tensorflow as tf
from tensorflow.core.framework import graph_pb2
import time
import operator
import sys

def inspect(model_pb, output_txt_file): …
Run Code Online (Sandbox Code Playgroud)

python parsing tensorflow coreml firebase-mlkit

5
推荐指数
1
解决办法
3万
查看次数