Steps to reproduce freeze_graph

  1. Copy the IPython Notebook from here
  2. Change sample_prediction = tf.nn.softmax(tf.nn.xw_plus_b(sample_output, w, b)) tosample_prediction = tf.nn.softmax(tf.nn.xw_plus_b(sample_output, w, b), name="sample_prediction")
  3. Modify the code like so:
with tf.Session(graph=graph) as session:
  tf.initialize_all_variables().run()
  print('Initialized')
  mean_loss = 0
  # code omitted (no changes)
  # new code below:
  saver = tf.train.Saver(tf.all_variables())
  saver.save(session, '/home/me/Documents/checkpoint.ckpt', write_meta_graph=False)
  tf.train.write_graph(graph.as_graph_def(), '/home/me/Documents', 'graph.pb')
  1. Run, and verify that checkpoint.ckpt and graph.pb have been created
  2. Run bazel build tensorflow/python/tools:freeze_graph && bazel-bin/tensorflow/python/tools/freeze_graph --input_graph=/home/me/Documents/graph.pb --input_checkpoint=/home/me/Documents/checkpoint.ckpt --output_graph=/home/me/Documents/frozen_graph.pb --output_node_names=sample_prediction                            bazel build tensorflow/python/tools:freeze_graph && \bazel-bin/tensorflow/python/tools/freeze_graph \--input_graph=some_graph_def.pb \--input_checkpoint=model.ckpt-8361242 \--output_graph=/tmp/frozen_graph.pb --output_node_names=softmax
  3. Verify that frozen_graph.pb has been created
  4. Create a new IPython Notebook with the following code:
from __future__ import print_function
import os
import numpy as np
import random
import string
import tensorflow as tf
from tensorflow.python.platform import gfile
import zipfile
from six.moves import range
from six.moves.urllib.request import urlretrieve

graph = tf.Graph()
with graph.as_default():
    graph_def = tf.GraphDef()
    with open('/home/me/Documents/frozen_graph.pb', "rb") as f:
        graph_def.ParseFromString(f.read())
        sample_prediction = tf.import_graph_def(graph_def, name="", return_elements=['sample_prediction:0'])
  1. Run

What have you tried?

  1. Originally, the graph also contained a node named saved_sample_output, and when I tried importing that frozen graph, the error complained about saved_sample_output:0. I tried removing the name, re-writing the checkpoint and graph files, re-freezing, and re-running the code. It then complained aboutVariable_17:0, which, after checking graph.pb, was what had originally been namedsaved_sample_output. Other than that, I haven't been able to find anything else out.
  2. Checked out #616 and looked at the solutions suggested for similar errors, but my import_graph_defnever had an input map to begin with.
  3. Removing the name parameter, or the return_elements parameter, or both, hasn't made a difference.
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值