save_path is not a valid checkpoint

男娘i 2022-09-04 06:48 138阅读 0赞

save_path is not a valid checkpoint

这句代码还是获取模型的字符串路径:

  1. aaa = tf.train.latest_checkpoint(model_path)

自己写对了,就不需要。

model_path结尾到文件名,.data前面的部分,加载预训练:

  1. tf.train.Saver(self.network.vars).restore(self.sess, model_path)

tensorflow版本1.4写的,

用1.13去读,识别不了了。

  1. ckpt = get_checkpoint_state(checkpoint_dir, latest_filename)
  2. if ckpt and ckpt.model_checkpoint_path:
  3. # Look for either a V2 path or a V1 path, with priority for V2.
  4. v2_path = _prefix_to_checkpoint_path(ckpt.model_checkpoint_path,
  5. saver_pb2.SaverDef.V2)
  6. v1_path = _prefix_to_checkpoint_path(ckpt.model_checkpoint_path,
  7. saver_pb2.SaverDef.V1)
  8. if file_io.get_matching_files(v2_path) or file_io.get_matching_files(
  9. v1_path):
  10. return ckpt.model_checkpoint_path

1 Tensorflow模型文件

我们在checkpoint_dir目录下保存的文件结构如下:

  1. --checkpoint_dir
  2. --checkpoint
  3. --MyModel.meta
  4. --MyModel.data-00000-of-00001
  5. --MyModel.index

1.1 meta文件

MyModel.meta文件保存的是图结构,meta文件是pb(protocol buffer)格式文件,包含变量、op、集合等。

1.2 ckpt文件

ckpt文件是二进制文件,保存了所有的weights、biases、gradients等变量。在tensorflow 0.11之前,保存在.ckpt文件中。0.11后,通过两个文件保存,如:

  1. MyModel.data-00000-of-00001
  2. MyModel.index

1.3 checkpoint文件

我们还可以看,checkpoint_dir目录下还有checkpoint文件,该文件是个文本文件,里面记录了保存的最新的checkpoint文件以及其它checkpoint文件列表。在inference时,可以通过修改这个文件,指定使用哪个model

发表评论

表情:
评论列表 (有 0 条评论,138人围观)

还没有评论,来说两句吧...

相关阅读