本文整理汇总了Python中tensorflow.logging方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.logging方法的具体用法?Python tensorflow.logging怎么用?Python tensorflow.logging使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.logging方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: printable_text
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import logging [as 别名]
def printable_text(text):
"""Returns text encoded in a way suitable for print or `tf.logging`."""
# These functions want `str` for both Python2 and Python3, but in one case
# it's a Unicode string and in the other it's a byte string.
if six.PY3:
if isinstance(text, str):
return text
elif isinstance(text, bytes):
return text.decode("utf-8", "ignore")
else:
raise ValueError("Unsupported string type: %s" % (type(text)))
elif six.PY2:
if isinstance(text, str):
return text
elif isinstance(text, unicode):
return text.encode("utf-8")
else:
raise ValueError("Unsupported string type: %s" % (type(text)))
else:
raise ValueError("Not running on Python2 or Python 3?")
示例2: printable_text
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import logging [as 别名]
def printable_text(text):
"""Returns text encoded in a way suitable for print or `tf.logging`."""
# These functions want `str` for both Python2 and Python3, but in one case
# it's a Unicode string and in the other it's a byte string.
if six.PY3:
if isinstance(text, str):
return text
elif isinstance(text, bytes):
return text.decode("utf-8", "ignore")
else:
raise ValueError("Unsupported string type: %s" % (type(text)))
elif six.PY2:
if isinstance(text, str):
return text
elif isinstance(text, unicode):
return text.encode("utf-8")
else:
raise ValueError("Unsupported string type: %s" % (type(text)))
else:
raise ValueError("Not running on Python2 or Python 3?")
示例3: printable_text
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import logging [as 别名]
def printable_text(text):
"""Returns text encoded in a way suitable for print or `tf.logging`."""
# These functions want `str` for both Python2 and Python3, but in one case
# it's a Unicode string and in the other it's a byte string.
if six.PY3:
if isinstance(text, str):
return text
elif isinstance(text, bytes):
return text.decode("utf-8", "ignore")
else:
raise ValueError("Unsupported string type: %s" % (type(text)))
elif six.PY2:
if isinstance(text, str):
return text
elif isinstance(text, unicode):
return text.encode("utf-8")
else:
raise ValueError("Unsupported string type: %s" % (type(text)))
else:
raise ValueError("Not running on Python2 or Python 3?")
示例4: _run_one_phase
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import logging [as 别名]
def _run_one_phase(self, min_steps, statistics, run_mode_str):
# Mostly copy of parent method.
step_count = 0
num_episodes = 0
sum_returns = 0.
while step_count < min_steps:
num_steps, episode_returns = self._run_one_episode()
for episode_return in episode_returns:
statistics.append({
"{}_episode_lengths".format(run_mode_str):
num_steps / self.batch_size,
"{}_episode_returns".format(run_mode_str): episode_return
})
step_count += num_steps
sum_returns += sum(episode_returns)
num_episodes += self.batch_size
# We use sys.stdout.write instead of tf.logging so as to flush frequently
# without generating a line break.
sys.stdout.write("Steps executed: {} ".format(step_count) +
"Batch episodes steps: {} ".format(num_steps) +
"Returns: {}\r".format(episode_returns))
sys.stdout.flush()
return step_count, sum_returns, num_episodes
示例5: initialize_from_ckpt
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import logging [as 别名]
def initialize_from_ckpt(ckpt_dir, hparams):
"""Initialize variables from given directory."""
model_dir = hparams.get("model_dir", None)
already_has_ckpt = (
model_dir and tf.train.latest_checkpoint(model_dir) is not None)
if already_has_ckpt:
return
tf.logging.info("Checkpoint dir: %s", ckpt_dir)
reader = tf.contrib.framework.load_checkpoint(ckpt_dir)
variable_map = {}
for var in tf.contrib.framework.get_trainable_variables():
var_name = var.name.split(":")[0]
if reader.has_tensor(var_name):
tf.logging.info("Loading variable from checkpoint: %s", var_name)
variable_map[var_name] = var
else:
tf.logging.info("Cannot find variable in checkpoint, skipping: %s",
var_name)
tf.train.init_from_checkpoint(ckpt_dir, variable_map)