Eshaka
Eshaka

Reputation: 994

How to load a model using .ckpt.data and .ckpt.index

In the code, I have been using it uses a .ckpt like incption_v4.ckpt to load a model. am trying to use the pretrained pnesnet model and it comes as two separate file .ckpt.data and .ckpt.index. can someone please show me how to load from these two files.

In the code to evaluate the model it used the path of dir as the checkpoint_path to load the model. So, I tried giving the path like that but it doesn't work.

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)

Above is the code to load from a .ckpt file.

Upvotes: 0

Views: 2191

Answers (1)

Eshaka
Eshaka

Reputation: 994

Just using the name of the model as model.ckpt works. Don't have to care about the .data and .index part

Upvotes: 1

Related Questions