def create_init_fn_to_restore(master_checkpoint, train_dir):
"""Creates an init operations to restore weights from various checkpoints.
master_checkpoint is path to a checkpoint which contains all weights for
the whole model.
"""
if master_checkpoint is None:
return None
# Warn the user if a checkpoint exists in the train_dir. Then we'll be
# ignoring the checkpoint path anyway.
if tf.train.latest_checkpoint(train_dir):
tf.logging.info(
'Ignoring --checkpoint_path because a checkpoint already exists in %s'
% train_dir)
return None
if tf.gfile.IsDirectory(master_checkpoint):
checkpoint_path = tf.train.latest_checkpoint(master_checkpoint)
else:
checkpoint_path = master_checkpoint
tf.logging.info('Fine-tuning from %s' % checkpoint_path)
return slim.assign_from_checkpoint_fn(checkpoint_path, slim.get_model_variables())
评论列表
文章目录