本文整理汇总了Python中data_utils.name_to_batch方法的典型用法代码示例。如果您正苦于以下问题:Python data_utils.name_to_batch方法的具体用法?Python data_utils.name_to_batch怎么用?Python data_utils.name_to_batch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类data_utils
的用法示例。
在下文中一共展示了data_utils.name_to_batch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: namignize
# 需要导入模块: import data_utils [as 别名]
# 或者: from data_utils import name_to_batch [as 别名]
def namignize(names, checkpoint_path, config):
"""Recognizes names and prints the Perplexity of the model for each names
in the list
Args:
names: a list of names in the model format
checkpoint_path: the path to restore the trained model from, should not
include the model name, just the path to
config: one of the above configs that specify the model and how it
should be run and trained
Returns:
None
"""
with tf.Graph().as_default(), tf.Session() as session:
with tf.variable_scope("model"):
m = NamignizerModel(is_training=False, config=config)
m.saver.restore(session, checkpoint_path)
for name in names:
x, y = data_utils.name_to_batch(name, m.batch_size, m.num_steps)
cost, loss, _ = session.run([m.cost, m.loss, tf.no_op()],
{m.input_data: x,
m.targets: y,
m.weights: np.concatenate((
np.ones(len(name)), np.zeros(m.batch_size * m.num_steps - len(name))))})
print("Name {} gives us a perplexity of {}".format(
name, np.exp(cost)))
示例2: namignize
# 需要导入模块: import data_utils [as 别名]
# 或者: from data_utils import name_to_batch [as 别名]
def namignize(names, checkpoint_path, config):
"""Recognizes names and prints the Perplexity of the model for each names
in the list
Args:
names: a list of names in the model format
checkpoint_path: the path to restore the trained model from, should not
include the model name, just the path to
config: one of the above configs that specify the model and how it
should be run and trained
Returns:
None
"""
with tf.Graph().as_default(), tf.Session() as session:
with tf.variable_scope("model"):
m = NamignizerModel(is_training=False, config=config)
m.saver.restore(session, checkpoint_path)
for name in names:
x, y = data_utils.name_to_batch(name, m.batch_size, m.num_steps)
cost, loss, _ = session.run([m.cost, m.loss, tf.no_op()],
{m.input_data: x,
m.targets: y,
m.initial_state: m.initial_state.eval(),
m.weights: np.concatenate((
np.ones(len(name)), np.zeros(m.batch_size * m.num_steps - len(name))))})
print("Name {} gives us a perplexity of {}".format(
name, np.exp(cost)))