1. 模型图和参数全保存在一个pb文件里(即freeze出来的模型),查看模型图代码如下:
import tensorflow as tf
with tf.Session() as sess:
model_filename ='model/freezon.pb'
with tf.gfile.GFile(model_filename, 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
g_in = tf.import_graph_def(graph_def)
train_writer = tf.summary.FileWriter("./log")
train_writer.add_graph(sess.graph)
train_writer.flush()
train_writer.close()
2. 使用estimator的export_saved_model或tf.saved_model保存的模型,包含saved_model.pb和varibles目录,导出模型图代码如下:
import tensorflow as tf
from tensorflow.core.protobuf import saved_model_pb2
from tensorflow.python.util import compat
from tensorflow.python.framework import ops
model_path = "./1578003200/saved_model.pb"
with tf.Session(graph=ops.Graph()) as sess:
with tf.gfile.GFile(model_path, &#