保存完整的模型
生成一下4个文件:
checkpoint
.meta
.data-00000-of-00001
.index
使用此方法保存时,会生成3个文件,其中后缀为.meta
保存图的结构和常量,.data
和.index
保存模型的权重,偏差,梯度其他的变量的所有的值等。
-
创建服务对象,如果
Saver()
有传入,表示只对传入的值有相应的后续效果saver = tf.train.Saver()
-
适应
saver
进行模型保存saver.save(sess,保存的文件名)
导出模型为一个文件
将图中所有的变量装换为常量tf.graph_util.convert_variables_to_constants()
写入到一个模型中tf.train.writer_graph()
import tensorflow as tf
w1 = tf.Variable(20.0, name="w1")
w2 = tf.Variable(30.0, name="w2")
b1= tf.Variable(2.0,name=