[TF] checkpoint version

According to the official instructions, checkpoint has two versions: 1 and 2

in version 0.12 tensorflow updated the checkpoint version, by default the checkpoints written and read are new In the V2 version, the new version can significantly reduce memory spikes during the restore process. The

two versions of the model are saved as follows:

v1 v2
model.ckpt-66000 model.ckpt-66000.index
model.ckpt-66000.meta model.ckpt-66000.meta


版1 When saving ckpt, there are two files model.ckpt-xxx (containing parameter names and parameter values) and model.ckpt- Xxx.meta (graph structure)

When reading the ckpt, the path is written in the usual way:


版2 When saving the model, there are three files model.ckpt-xxx.data( Parameter value), model.ckpt-xxx.index (parameter name), model.ckpt-xxx.meta (graph structure)

When reading the ckpt, the path is written to the public part of only three files

@@Save version selection

TF is saved as v2 format by default. The saved checkpoint version can be specified when creating saver

import tensorflow as tf
From tensorflow.core.protobuf import saver_pb2
# Save as v1 version
Saver = tf.train.Saver(write_version=saver_pb2.SaverDef.V1)
# Save as v2 version
Saver = tf.train.Saver(write_version=saver_pb2.SaverDef.V2)

Recovering variables from ckpt

Although there are differences when saving, when recovering, both versions can be used (but different versions are required) The path of ckpt is written differently)

v1Directly write the path of the complete ckpt file

v2Write the model.ckpt-xxx in the path of the complete ckpt file directly