Saving, Freezing, Optimizing for inference, Restoring of tensorflow models
在训练完tensorflow模型后,会有三个文件:model-epoch_99.data-00000-of-00001,model-epoch_99.index,model-epoch_99.meta
1.tensorflowModel.ckpt.meta:Tenosrflow将图结构与变量值分开存储。 文件.ckpt.meta包含完整的图结构。 它包括GraphDef,SaverDef等。
2.tensorflowModel.ckpt.data-00000-of-00001:它包含的变量(重量,偏差,占位符,梯度,超参数等)的值。
3.tensorflowModel.ckpt.index:这是一个表,其中每个键是张量tensor的名称,其值是序列化的BundleEntryProto。
- 第一步先生成tensorflowModel.pbtxt文件。可以在测试程序中,执行完saver.restore之后,将graph保存为.pbtxt。
import resnet_multitask
def classify_model(images, class_num):
# images: 输入三通道彩色图
# class_num: 分类类别数目,用于定义网络最后的全连接层
with slim.arg_scope(resnet_multitask.resnet_arg_scope(is_training=False)):
logits, pre_heatmap, end_points = resnet_multitask.resnet_v2(images, class_num)
return logits, pre_heatmap, end_points
restore_path = './checkpoint/model-epoch_99'
with tf.Session() as sess:
input_x = tf.placeholder(tf.float32, shape=[None, w, h, c], name='input_x')
logits,pre_heatmap,end_points = classify_model(input_x,class_num)
saver = tf.train.Saver()
saver.restor