ckpt转化为pb并进行测试运行
利用tf.graph_util.convert_variables_to_constants进行模型固化
1.导出pb文件:export.py
2.利用pb文件进行预测
from __future__ import absolute_import, unicode_literals
import tensorflow as tf
import os
from PIL import Image
import numpy as np
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
readImage = Image.open("./test/517.jpg")
#readImage = Image.open("cat.9.jpg")
# readImage.show()
# matrix = np.asarray(readImage).astype("float32")
readImage = readImage.resize([100, 100])
npmatrix = np.array(readImage)
with tf.Graph().as_default():
output_graph_def = tf.GraphDef()
output_graph_path = '/data/lyk/lyk/FaceFeature/output_model/pb_model/SecModel.pb'
# sess.graph.add_to_collection("input", mnist.test.images)
with open(output_graph_path, "rb") as f:
output_graph_def.ParseFromString(f.read())
tf.import_graph_def(output_graph_def, name="")
with tf.Session() as sess:
tf.initialize_all_variables().run()
input_x = sess.graph.get_tensor_by_name("inputdata:0")
output = sess.graph.get_tensor_by_name("outputdata:0")
y_conv_2 = sess.run(output, {input_x: image})
print("y_conv_2", y_conv_2)
测试结果:
参考资料:链接