【TensorFlow】模型保存后的几个文件

用TensorFlow训练好模型,通过saver保存之后,对应路径下通常会有几个文件,我们结合下面的一段代码看一下

import tensorflow as tf

# Create some variables.
v1 = tf.get_variable("v1", shape=[3], initializer = tf.zeros_initializer)
v2 = tf.get_variable("v2", shape=[5], initializer = tf.zeros_initializer)

inc_v1 = v1.assign(v1+1)
dec_v2 = v2.assign(v2-1)

# Add an op to initialize the variables.
init_op = tf.global_variables_initializer()

# Add ops to save and restore all the variables.
saver = tf.train.Saver()

# Later, launch the model, initialize the variables, do some work, and save the
# variables to disk.
with tf.Session() as sess:
  sess.run(init_op)
  # Do some work with the model.
  inc_v1.op.run()
  dec_v2.op.run()
  # Save the variables to disk.
  save_path = saver.save(sess, "/tmp/model.ckpt")
  print("Model saved in path: %s" % save_path)

这段代码很简答,初始化了两个变量 v1, v2,然后分别做了加一和减一操作,然后定义了一个saver,用于保存模型。
一般模型保存后会有如下文件:

  • checkpoint: All checkpoint information,保存的是checkpoint的信息,也就是通过它我知道最近保存的几个模型版本
  • xxx.meta: 包含全部graph信息。这是一个序列化的MetaGraphDef protocol buffer,包含数据流、变量的annotations、input pipelines,以及其他相关信息
  • xxx.index: metadata,元数据 [ It’s an immutable table(tensoflow::table::Table). Each key is a name of a Tensor and it’s value is a serialized BundleEntryProto. Each BundleEntryProto describes the metadata of a Tensor]
  • xxx.data-00000-of-00001: 包含所有变量的值(weights, biases, placeholders,gradients, hyper-parameters etc),也就是模型训练好参数和其他值

参考资料:
1、https://www.tensorflow.org/guide/saved_model?hl=zh-cn

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值