Tensorflow : What is the relationship between .ckpt file and .ckpt.meta and .ckpt.index , and .pb file

后端 未结 1 1304
有刺的猬
有刺的猬 2020-12-12 22:49

I used saver=tf.train.Saver() to save the model that I trained, and I get three kinds of files named:

  • .ckpt.meta
  • .ckpt.index
  • .c
相关标签:
1条回答
  • 2020-12-12 23:23
    • the .ckpt file is the old version output of saver.save(sess), which is the equivalent of your .ckpt-data (see below)

    • the "checkpoint" file is only here to tell some TF functions which is the latest checkpoint file.

    • .ckpt-meta contains the metagraph, i.e. the structure of your computation graph, without the values of the variables (basically what you can see in tensorboard/graph).

    • .ckpt-data contains the values for all the variables, without the structure. To restore a model in python, you'll usually use the meta and data files with (but you can also use the .pb file):

      saver = tf.train.import_meta_graph(path_to_ckpt_meta)
      saver.restore(sess, path_to_ckpt_data)
      
    • I don't know exactly for .ckpt-index, I guess it's some kind of index needed internally to map the two previous files correctly. Anyway it's not really necessary usually, you can restore a model with only .ckpt-meta and .ckpt-data.

    • the .pb file can save your whole graph (meta + data). To load and use (but not train) a graph in c++ you'll usually use it, created with freeze_graph, which creates the .pb file from the meta and data. Be careful, (at least in previous TF versions and for some people) the py function provided by freeze_graph did not work properly, so you'd have to use the script version. Tensorflow also provides a tf.train.Saver.to_proto() method, but I don't know what it does exactly.

    There are a lot of questions here about how to save and restore a graph. See the answer here for instance, but be careful that the two cited tutorials, though really helpful, are far from perfect, and a lot of people still seem to struggle to import a model in c++.

    EDIT: it looks like you can also use the .ckpt files in c++ now, so I guess you don't necessarily need the .pb file any more.

    0 讨论(0)
提交回复
热议问题