本文整理汇总了Python中util.load_ckpt方法的典型用法代码示例。如果您正苦于以下问题:Python util.load_ckpt方法的具体用法?Python util.load_ckpt怎么用?Python util.load_ckpt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util
的用法示例。
在下文中一共展示了util.load_ckpt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: restore_best_model
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def restore_best_model(self):
"""Load bestmodel file from eval directory, add variables for adagrad, and save to train directory"""
tf.logging.info("Restoring bestmodel for training...")
# Initialize all vars in the model
sess = tf.Session(config=util.get_config())
print("Initializing all variables...")
sess.run(tf.initialize_all_variables())
# Restore the best model from eval dir
saver = tf.train.Saver([v for v in tf.all_variables() if "Adagrad" not in v.name])
print("Restoring all non-adagrad variables from best model in eval dir...")
curr_ckpt = util.load_ckpt(saver, sess, "eval")
print("Restored %s." % curr_ckpt)
# Save this model to train dir and quit
new_model_name = curr_ckpt.split("/")[-1].replace("bestmodel", "model")
new_fname = os.path.join(FLAGS.log_root, "train", new_model_name)
print("Saving model to %s..." % (new_fname))
new_saver = tf.train.Saver() # this saver saves all variables that now exist, including Adagrad variables
new_saver.save(sess, new_fname)
print("Saved.")
exit()
示例2: convert_to_coverage_model
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def convert_to_coverage_model(self):
"""Load non-coverage checkpoint, add initialized extra variables for coverage, and save as new checkpoint"""
tf.logging.info("converting non-coverage model to coverage model..")
# initialize an entire coverage model from scratch
sess = tf.Session(config=util.get_config())
print("initializing everything...")
sess.run(tf.global_variables_initializer())
# load all non-coverage weights from checkpoint
saver = tf.train.Saver([v for v in tf.global_variables() if "coverage" not in v.name and "Adagrad" not in v.name])
print("restoring non-coverage variables...")
curr_ckpt = util.load_ckpt(saver, sess)
print("restored.")
# save this model and quit
new_fname = curr_ckpt + '_cov_init'
print("saving model to %s..." % (new_fname))
new_saver = tf.train.Saver() # this one will save all variables that now exist
new_saver.save(sess, new_fname)
print("saved.")
exit()
示例3: convert_to_reinforce_model
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def convert_to_reinforce_model(self):
"""Load non-reinforce checkpoint, add initialized extra variables for reinforce, and save as new checkpoint"""
tf.logging.info("converting non-reinforce model to reinforce model..")
# initialize an entire reinforce model from scratch
sess = tf.Session(config=util.get_config())
print("initializing everything...")
sess.run(tf.global_variables_initializer())
# load all non-reinforce weights from checkpoint
saver = tf.train.Saver([v for v in tf.global_variables() if "reinforce" not in v.name and "Adagrad" not in v.name])
print("restoring non-reinforce variables...")
curr_ckpt = util.load_ckpt(saver, sess)
print("restored.")
# save this model and quit
new_fname = curr_ckpt + '_rl_init'
print("saving model to %s..." % (new_fname))
new_saver = tf.train.Saver() # this one will save all variables that now exist
new_saver.save(sess, new_fname)
print("saved.")
exit()
示例4: restore_best_model
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def restore_best_model():
"""Load bestmodel file from eval directory, add variables for adagrad, and save to train directory"""
tf.logging.info("Restoring best model for training...")
# Initialize all vars in the model
sess = tf.Session(config=util.get_config())
print("Initializing all variables...")
sess.run(tf.initialize_all_variables())
# Restore the best model from eval dir
saver = tf.train.Saver([v for v in tf.all_variables() if "Adagrad" not in v.name])
print("Restoring all non-adagrad variables from best model in eval dir...")
curr_ckpt = util.load_ckpt(saver, sess, "eval")
print("Restored %s." % curr_ckpt)
# Save this model to train dir and quit
new_model_name = curr_ckpt.split("/")[-1].replace("bestmodel", "model")
new_fname = os.path.join(FLAGS.log_root, "train", new_model_name)
print("Saving model to %s..." % new_fname)
new_saver = tf.train.Saver() # this saver saves all variables that now exist, including Adagrad variables
new_saver.save(sess, new_fname)
print("Saved.")
exit()
示例5: convert_to_coverage_model
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def convert_to_coverage_model():
"""Load non-coverage checkpoint, add initialized extra variables for coverage, and save as new checkpoint"""
tf.logging.info("converting non-coverage model to coverage model..")
# initialize an entire coverage model from scratch
sess = tf.Session(config=util.get_config())
print("initializing everything...")
sess.run(tf.global_variables_initializer())
# load all non-coverage weights from checkpoint
saver = tf.train.Saver([v for v in tf.global_variables() if "coverage" not in v.name and "Adagrad" not in v.name])
print("restoring non-coverage variables...")
curr_ckpt = util.load_ckpt(saver, sess, FLAGS.ckpt_dir)
print("restored.")
# save this model and quit
new_fname = curr_ckpt + '_cov_init'
print("saving model to %s..." % new_fname)
new_saver = tf.train.Saver() # this one will save all variables that now exist
new_saver.save(sess, new_fname)
print("saved.")
exit()
示例6: convert_to_coverage_model
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def convert_to_coverage_model():
"""Load non-coverage checkpoint, add initialized extra variables for coverage, and save as new checkpoint"""
tf.logging.info("converting non-coverage model to coverage model..")
# initialize an entire coverage model from scratch
sess = tf.Session(config=util.get_config())
print("initializing everything...")
sess.run(tf.global_variables_initializer())
# load all non-coverage weights from checkpoint
saver = tf.train.Saver([v for v in tf.global_variables(
) if "coverage" not in v.name and "Adagrad" not in v.name])
print("restoring non-coverage variables...")
curr_ckpt = util.load_ckpt(saver, sess)
print("restored.")
# save this model and quit
new_fname = curr_ckpt + '_cov_init'
print("saving model to %s..." % (new_fname))
new_saver = tf.train.Saver() # this one will save all variables that now exist
new_saver.save(sess, new_fname)
print("saved.")
exit()
示例7: restore_best_model
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def restore_best_model():
"""Load bestmodel file from eval directory, add variables for adagrad, and save to train directory"""
tf.logging.info("Restoring bestmodel for training...")
# Initialize all vars in the model
sess = tf.Session(config=util.get_config())
print("Initializing all variables...")
sess.run(tf.initialize_all_variables())
# Restore the best model from eval dir
saver = tf.train.Saver([v for v in tf.all_variables() if "Adagrad" not in v.name])
print("Restoring all non-adagrad variables from best model in eval dir...")
curr_ckpt = util.load_ckpt(saver, sess, "eval")
print("Restored %s." % curr_ckpt)
# Save this model to train dir and quit
new_model_name = curr_ckpt.split("/")[-1].replace("bestmodel", "model")
new_fname = os.path.join(FLAGS.log_root, "train", new_model_name)
print("Saving model to %s..." % (new_fname))
new_saver = tf.train.Saver() # this saver saves all variables that now exist, including Adagrad variables
new_saver.save(sess, new_fname)
print("Saved.")
exit()
示例8: convert_linear_attn_to_hier_model
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def convert_linear_attn_to_hier_model():
"""Load non-coverage checkpoint, add initialized extra variables for coverage, and save as new checkpoint"""
tf.logging.info("converting linear model to hier model..")
# initialize an entire coverage model from scratch
sess = tf.Session(config=util.get_config())
print("initializing everything...")
sess.run(tf.global_variables_initializer())
# load all non-coverage weights from checkpoint
saver = tf.train.Saver([v for v in tf.global_variables(
) if "Linear--Section-Features" not in v.name and "v_sec" not in v.name and "Adagrad" not in v.name])
print("restoring variables...")
curr_ckpt = util.load_ckpt(saver, sess)
print("restored.")
# save this model and quit
new_fname = curr_ckpt
print(("saving model to %s..." % (new_fname)))
new_saver = tf.train.Saver() # this one will save all variables that now exist
new_saver.save(sess, new_fname)
print("saved.")
exit()
示例9: setup_training_generator
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def setup_training_generator(model):
"""Does setup before starting training (run_training)"""
train_dir = os.path.join(FLAGS.log_root, "train-generator")
if not os.path.exists(train_dir): os.makedirs(train_dir)
model.build_graph() # build the graph
saver = tf.train.Saver(max_to_keep=20) # we use this to load checkpoints for decoding
sess = tf.Session(config=util.get_config())
#sess.run(tf.train.Saver(max_to_keep=20))
#init = tf.global_variables_initializer()
#sess.run(init)
# Load an initial checkpoint to use for decoding
util.load_ckpt(saver, sess, ckpt_dir="train-generator")
return sess, saver,train_dir
示例10: setup_training_discriminator
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def setup_training_discriminator(model):
"""Does setup before starting training (run_training)"""
train_dir = os.path.join(FLAGS.log_root, "train-discriminator")
if not os.path.exists(train_dir): os.makedirs(train_dir)
model.build_graph() # build the graph
saver = tf.train.Saver(max_to_keep=20) # we use this to load checkpoints for decoding
sess = tf.Session(config=util.get_config())
#init = tf.global_variables_initializer()
#sess.run(init)
util.load_ckpt(saver, sess, ckpt_dir="train-discriminator")
return sess, saver,train_dir
示例11: restore_best_model
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def restore_best_model():
"""Load bestmodel file from eval directory, add variables for adagrad, and save to train directory"""
tf.logging.info("Restoring bestmodel for training...")
# Initialize all vars in the model
sess = tf.Session(config=util.get_config())
print "Initializing all variables..."
sess.run(tf.initialize_all_variables())
# Restore the best model from eval dir
saver = tf.train.Saver([v for v in tf.all_variables() if "Adagrad" not in v.name])
print "Restoring all non-adagrad variables from best model in eval dir..."
curr_ckpt = util.load_ckpt(saver, sess, "eval")
print "Restored %s." % curr_ckpt
# Save this model to train dir and quit
new_model_name = curr_ckpt.split("/")[-1].replace("bestmodel", "model")
new_fname = os.path.join(FLAGS.log_root, "train", new_model_name)
print "Saving model to %s..." % (new_fname)
new_saver = tf.train.Saver() # this saver saves all variables that now exist, including Adagrad variables
new_saver.save(sess, new_fname)
print "Saved."
exit()
示例12: convert_to_coverage_model
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def convert_to_coverage_model():
"""Load non-coverage checkpoint, add initialized extra variables for coverage, and save as new checkpoint"""
tf.logging.info("converting non-coverage model to coverage model..")
# initialize an entire coverage model from scratch
sess = tf.Session(config=util.get_config())
print "initializing everything..."
sess.run(tf.global_variables_initializer())
# load all non-coverage weights from checkpoint
saver = tf.train.Saver([v for v in tf.global_variables() if "coverage" not in v.name and "Adagrad" not in v.name])
print "restoring non-coverage variables..."
curr_ckpt = util.load_ckpt(saver, sess)
print "restored."
# save this model and quit
new_fname = curr_ckpt + '_cov_init'
print "saving model to %s..." % (new_fname)
new_saver = tf.train.Saver() # this one will save all variables that now exist
new_saver.save(sess, new_fname)
print "saved."
exit()
示例13: __init__
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def __init__(self, model, batcher, vocab):
"""Initialize decoder.
Args:
model: a Seq2SeqAttentionModel object.
batcher: a Batcher object.
vocab: Vocabulary object
"""
self._model = model
self._model.build_graph()
self._batcher = batcher
self._vocab = vocab
self._saver = tf.train.Saver() # we use this to load checkpoints for decoding
self._sess = tf.Session(config=util.get_config())
# Load an initial checkpoint to use for decoding
ckpt_path = util.load_ckpt(self._saver, self._sess)
# if FLAGS.single_pass:
# # Make a descriptive decode directory name
# ckpt_name = "ckpt-" + ckpt_path.split('-')[-1] # this is something of the form "ckpt-123456"
# self._decode_dir = os.path.join(FLAGS.log_root, get_decode_dir_name(ckpt_name))
# if os.path.exists(self._decode_dir):
# raise Exception("single_pass decode directory %s should not already exist" % self._decode_dir)
#
# else: # Generic decode dir name
self._decode_dir = os.path.join(FLAGS.log_root, "decode")
# Make the decode dir if necessary
if not os.path.exists(self._decode_dir): os.mkdir(self._decode_dir)
# if FLAGS.single_pass:
# # Make the dirs to contain output written in the correct format for pyrouge
# self._rouge_ref_dir = os.path.join(self._decode_dir, "reference")
# if not os.path.exists(self._rouge_ref_dir): os.mkdir(self._rouge_ref_dir)
# self._rouge_dec_dir = os.path.join(self._decode_dir, "decoded")
# if not os.path.exists(self._rouge_dec_dir): os.mkdir(self._rouge_dec_dir)
示例14: restore_best_model
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def restore_best_model():
"""Load bestmodel file from eval directory, add variables for adagrad, and save to train directory"""
tf.logging.info("Restoring bestmodel for training...")
# Initialize all vars in the model
sess = tf.Session(config=util.get_config())
print("Initializing all variables...")
sess.run(tf.initialize_all_variables())
# Restore the best model from eval dir
saver = tf.train.Saver(
[v for v in tf.all_variables() if "Adagrad" not in v.name])
print("Restoring all non-adagrad variables from best model in eval dir...")
curr_ckpt = util.load_ckpt(saver, sess, "eval")
print("Restored %s." % curr_ckpt)
# Save this model to train dir and quit
new_model_name = curr_ckpt.split("/")[-1].replace("bestmodel", "model")
new_fname = os.path.join(FLAGS.log_root, "train", new_model_name)
print("Saving model to %s..." % (new_fname))
# this saver saves all variables that now exist, including Adagrad
# variables
new_saver = tf.train.Saver()
new_saver.save(sess, new_fname)
print("Saved.")
exit()
示例15: convert_to_coverage_model
# 需要导入模块: import util [as 别名]
# 或者: from util import load_ckpt [as 别名]
def convert_to_coverage_model():
"""Load non-coverage checkpoint, add initialized extra variables for coverage, and save as new checkpoint"""
tf.logging.info("converting non-coverage model to coverage model..")
# initialize an entire coverage model from scratch
sess = tf.Session(config=util.get_config())
if FLAGS.debug:
print('entering debug mode')
sess = tf_debug.LocalCLIDebugWrapperSession(sess, ui_type=FLAGS.ui_type)
sess.add_tensor_filter("has_inf_or_nan", tf_debug.has_inf_or_nan)
print("initializing everything...")
sess.run(tf.global_variables_initializer())
# load all non-coverage weights from checkpoint
saver = tf.train.Saver([v for v in tf.global_variables(
) if "coverage" not in v.name and "Adagrad" not in v.name])
print("restoring non-coverage variables...")
curr_ckpt = util.load_ckpt(saver, sess)
print("restored.")
# save this model and quit
new_fname = curr_ckpt + '_cov_init'
print(("saving model to %s..." % (new_fname)))
new_saver = tf.train.Saver() # this one will save all variables that now exist
new_saver.save(sess, new_fname)
print("saved.")
exit()