首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用.ckpt.data和.ckpt.index加载模型

如何使用.ckpt.data和.ckpt.index加载模型
EN

Stack Overflow用户
提问于 2019-01-28 13:11:14
回答 1查看 952关注 0票数 0

在代码中,我一直使用它使用像incption_v4.ckpt这样的.ckpt来加载模型。我尝试使用预先训练好的pnesnet模型,它是由两个独立的文件.ckpt.data和.ckpt.index组成的。谁能告诉我如何从这两个文件加载。

在评估模型的代码中,它使用目录的路径作为加载模型的checkpoint_path。所以,我试着给出这样的路径,但它不起作用。

代码语言:javascript
复制
def _get_init_fn():
  """Returns a function run by the chief worker to warm-start the training.

  Note that the init_fn is only run when initializing the model during the very
  first global step.

  Returns:
    An init function run by the supervisor.
  """
  if FLAGS.checkpoint_path is None:
    return None

  # Warn the user if a checkpoint exists in the train_dir. Then we'll be
  # ignoring the checkpoint anyway.
  if tf.train.latest_checkpoint(FLAGS.train_dir):
    tf.logging.info(
        'Ignoring --checkpoint_path because a checkpoint already exists in %s'
        % FLAGS.train_dir)
    return None

  exclusions = []
  if FLAGS.checkpoint_exclude_scopes:
    exclusions = [scope.strip()
                  for scope in FLAGS.checkpoint_exclude_scopes.split(',')]

  # TODO(sguada) variables.filter_variables()
  variables_to_restore = []
  for var in slim.get_model_variables():
    excluded = False
    for exclusion in exclusions:
      if var.op.name.startswith(exclusion):
        excluded = True
        break
    if not excluded:
      variables_to_restore.append(var)

  if tf.gfile.IsDirectory(FLAGS.checkpoint_path):
    checkpoint_path = tf.train.latest_checkpoint(FLAGS.checkpoint_path)
  else:
    checkpoint_path = FLAGS.checkpoint_path

  tf.logging.info('Fine-tuning from %s' % checkpoint_path)

  return slim.assign_from_checkpoint_fn(
      checkpoint_path,
      variables_to_restore,
      ignore_missing_vars=FLAGS.ignore_missing_vars)

上面是从.ckpt文件加载的代码。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-28 16:36:28

只要在model.ckpt工作时使用模型的名称即可。不必关心.data.index部分

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54395858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档