相关疑难解决方法(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万
查看次数

无法使用训练好的Tensorflow模型

我是深度学习和Tensorflow的新手。我重新训练了一个预训练过的tensorflow inceptionv3模型为save_model.pb,以识别不同类型的图像,但是当我尝试将fie与以下代码一起使用时。

with tf.Session() as sess:
    with tf.gfile.FastGFile("tensorflow/trained/saved_model.pb",'rb') as  f:
        graph_def = tf.GraphDef()
        tf.Graph.as_graph_def()
        graph_def.ParseFromString(f.read())
        g_in=tf.import_graph_def(graph_def)
        LOGDIR='/log'
        train_writer=tf.summary.FileWriter(LOGDIR)
        train_writer.add_graph(sess.graph)
Run Code Online (Sandbox Code Playgroud)

它给了我这个错误-

 File "testing.py", line 7, in <module>
graph_def.ParseFromString(f.read())
google.protobuf.message.DecodeError: Error parsing message
Run Code Online (Sandbox Code Playgroud)

我尝试了很多可以找到这个问题的解决方案,并且使用graph_def.ParseFromString(f.read())函数的tensorflow / python / tools中的模块给了我同样的错误。请告诉我如何解决此问题或告诉我可以避免ParseFromString(f.read())函数的方式。任何帮助,将不胜感激。谢谢!

image-processing python-3.x deep-learning tensorflow tensorboard

6
推荐指数
3
解决办法
4308
查看次数

如何修复:创建张量流文本摘要时出现“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万
查看次数