After several file [model] to save TensorFlow

TensorFlow with good training model, through saverafter saving, there are often several files corresponding to the path, we combine a look at the following piece of code

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)

This code is very short answer, initializes two variables v1, v2, and then were made plus one and minus one operation, and then defines a Saver, the model is saved.
After the general model will save the file as follows:

  • checkpoint: All Information checkpoint, the checkpoint information is saved, that is, through it I know a few of the most recently saved version of the model
  • xxx.meta: contains all the graph information. This is a sequence of MetaGraphDef protocol buffer, containing a data stream annotations, variables, input pipelines, and other relevant information
  • 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: it contains the values of all variables (weights, biases, placeholders, gradients , hyper-parameters etc), which is a good model training parameters and other values

References:
1, https://www.tensorflow.org/guide/saved_model?hl=zh-cn

Published 114 original articles · won praise 55 · views 80000 +

Guess you like

Origin blog.csdn.net/zuolixiangfisher/article/details/98755280