【发布时间】:2017-02-11 13:41:13
【问题描述】:
我一直在尝试使用freeze_graph 函数来获取模型+权重/偏差,但在此过程中,我发现我的初始网络似乎没有任何变量,尽管能够正确分类图像.我的代码如下:
#!/usr/bin/python
import tensorflow as tf
import numpy as np
def outputCheckpoint(sess):
with sess.as_default():
print("Saving to checkpoint")
saver = tf.train.Saver()
# Fails on this line: 'ValueError: No variables to save'
saver.save(sess, '/path/to/tensorflow/graph_saver/save_checkpoint')
def main():
with tf.device('/cpu:0'):
with open("tensorflow_inception_graph.pb", mode='rb') as f:
fileContent = f.read()
graph_def = tf.GraphDef()
graph_def.ParseFromString(fileContent)
images = tf.placeholder("float", [ None, 299, 299, 3])
tf.import_graph_def(graph_def, input_map={ "Mul": images })
print "graph loaded from disk"
graph = tf.get_default_graph()
with tf.Session() as sess:
init = tf.global_variables_initializer()
sess.run(init)
outputCheckpoint(sess)
main()
错误是:
graph loaded from disk
Saving to checkpoint
Traceback (most recent call last):
File "./inception_benchmark.py", line 28, in <module>
main()
File "./inception_benchmark.py", line 24, in main
saver = tf.train.Saver()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1067, in __init__
self.build()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1088, in build
raise ValueError("No variables to save")
ValueError: No variables to save
如果您还没有下载初始网络,这将为您获取 .pb 文件:
$ wget https://storage.googleapis.com/download.tensorflow.org/models/inception_dec_2015.zip -O tensorflow/examples/label_image/data/inception_dec_2015.zip
另外,如果有人好奇,这里是我完整代码的要点:gist
有人知道这里发生了什么吗?
谢谢!
【问题讨论】:
标签: python tensorflow