本文整理汇总了Python中absl.logging.set_verbosity方法的典型用法代码示例。如果您正苦于以下问题:Python logging.set_verbosity方法的具体用法?Python logging.set_verbosity怎么用?Python logging.set_verbosity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类absl.logging
的用法示例。
在下文中一共展示了logging.set_verbosity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def main(_):
logging.set_verbosity(FLAGS.log_level)
if FLAGS.tf_eager:
tf.enable_eager_execution()
if FLAGS.tf_xla:
tf.config.optimizer.set_jit(True)
_setup_gin()
# Setup output directory
output_dir = FLAGS.output_dir or _default_output_dir()
trax.log("Using --output_dir %s" % output_dir)
output_dir = os.path.expanduser(output_dir)
# If on TPU, let JAX know.
if FLAGS.use_tpu:
jax.config.update("jax_platform_name", "tpu")
trax.train(output_dir=output_dir)
示例2: main
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def main(argv):
del argv
logging.set_verbosity(FLAGS.log_level)
if not FLAGS.logdir:
raise ValueError('logdir flag must be provided.')
if FLAGS.num_workers <= 0:
raise ValueError('num_workers flag must be greater than 0.')
if FLAGS.task_id < 0:
raise ValueError('task_id flag must be greater than or equal to 0.')
if FLAGS.task_id >= FLAGS.num_workers:
raise ValueError(
'task_id flag must be strictly less than num_workers flag.')
if FLAGS.num_tuners <= 0:
raise ValueError('num_tuners flag must be greater than 0.')
if FLAGS.tuner_id < 0:
raise ValueError('tuner_id flag must be greater than or equal to 0.')
if FLAGS.tuner_id >= FLAGS.num_tuners:
raise ValueError(
'tuner_id flag must be strictly less than num_tuners flag.')
ns, _ = run_lib.get_namespace(FLAGS.config)
run_tuner_loop(ns)
示例3: main
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def main(argv):
del argv # Unused.
logging.set_verbosity(FLAGS.log_level)
flags.mark_flag_as_required('logdir')
if FLAGS.num_workers <= 0:
raise ValueError('num_workers flag must be greater than 0.')
if FLAGS.task_id < 0:
raise ValueError('task_id flag must be greater than or equal to 0.')
if FLAGS.task_id >= FLAGS.num_workers:
raise ValueError(
'task_id flag must be strictly less than num_workers flag.')
ns, _ = get_namespace(FLAGS.config)
ns.run_training(is_chief=FLAGS.task_id == 0)
示例4: set_logging
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def set_logging(is_debug, config):
absl_logger = logging.get_absl_logger()
# create formatter and add it to the handlers
formatter = _logging.Formatter("[ %(asctime)-15s %(levelname)s %(filename)15s:%(lineno)-4d " \
" %(process)-5d ] %(message)s")
log_dir = config["solver"]["saver"]["model_path"]
if not os.path.exists(log_dir):
os.makedirs(log_dir)
logging.get_absl_handler().use_absl_log_file(
program_name='delta', log_dir=log_dir)
fh = _logging.StreamHandler()
fh.setLevel(_logging.NOTSET)
fh.setFormatter(formatter)
absl_logger.addHandler(fh)
if is_debug:
logging.set_verbosity(_logging.DEBUG)
else:
logging.set_verbosity(_logging.NOTSET)
logging.info("Also save log file to directory: {}".format(log_dir))
示例5: _update_logging_levels
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def _update_logging_levels(self):
"""Updates absl logging levels to the current verbosity."""
if not _absl_logger:
return
if self._value <= converter.ABSL_DEBUG:
standard_verbosity = converter.absl_to_standard(self._value)
else:
# --verbosity is set to higher than 1 for vlog.
standard_verbosity = logging.DEBUG - (self._value - 1)
# Also update root level when absl_handler is used.
if _absl_handler in logging.root.handlers:
# Make absl logger inherit from the root logger. absl logger might have
# a non-NOTSET value if logging.set_verbosity() is called at import time.
_absl_logger.setLevel(logging.NOTSET)
logging.root.setLevel(standard_verbosity)
else:
_absl_logger.setLevel(standard_verbosity)
示例6: set_verbosity
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def set_verbosity(v):
"""Sets the logging verbosity.
Causes all messages of level <= v to be logged,
and all messages of level > v to be silently discarded.
Args:
v: int|str, the verbosity level as an integer or string. Legal string values
are those that can be coerced to an integer as well as case-insensitive
'debug', 'info', 'warning', 'error', and 'fatal'.
"""
try:
new_level = int(v)
except ValueError:
new_level = converter.ABSL_NAMES[v.upper()]
FLAGS.verbosity = new_level
示例7: main
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def main(_):
tf.compat.v1.enable_resource_variables()
if tf.executing_eagerly():
# self.skipTest('b/123777119') # Secondary bug: ('b/123775375')
return
logging.set_verbosity(logging.INFO)
train_eval_clip_agent.train_eval(
FLAGS.root_dir,
tf_master=FLAGS.master,
env_name=FLAGS.env_name,
env_load_fn=env_load_fn,
replay_buffer_capacity=FLAGS.replay_buffer_capacity,
num_environment_steps=FLAGS.num_environment_steps,
num_parallel_environments=FLAGS.num_parallel_environments,
num_epochs=FLAGS.num_epochs,
collect_episodes_per_iteration=FLAGS.collect_episodes_per_iteration,
num_eval_episodes=FLAGS.num_eval_episodes,
use_rnns=FLAGS.use_rnns)
示例8: main
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def main(_):
tf.compat.v1.enable_resource_variables()
if tf.executing_eagerly():
# self.skipTest('b/123777119') # Secondary bug: ('b/123775375')
return
logging.set_verbosity(logging.INFO)
train_eval(
FLAGS.root_dir,
tf_master=FLAGS.master,
env_name=FLAGS.env_name,
replay_buffer_capacity=FLAGS.replay_buffer_capacity,
num_environment_steps=FLAGS.num_environment_steps,
num_parallel_environments=FLAGS.num_parallel_environments,
num_epochs=FLAGS.num_epochs,
collect_episodes_per_iteration=FLAGS.collect_episodes_per_iteration,
num_eval_episodes=FLAGS.num_eval_episodes,
use_rnns=FLAGS.use_rnns)
示例9: main
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def main(_):
# Users should always run this script under TF 2.x
assert tf.version.VERSION.startswith('2.')
logging.set_verbosity(logging.INFO)
with tf.io.gfile.GFile(FLAGS.input_meta_data_path, 'rb') as reader:
input_meta_data = json.loads(reader.read().decode('utf-8'))
strategy = None
if FLAGS.strategy_type == 'mirror':
strategy = tf.distribute.MirroredStrategy()
elif FLAGS.strategy_type == 'one':
strategy = tf.distribute.OneDeviceStrategy('GPU:0')
else:
raise ValueError('The distribution strategy type is not supported: %s' %
FLAGS.strategy_type)
if FLAGS.mode in ('train', 'train_and_predict'):
train_squad(strategy, input_meta_data)
if FLAGS.mode in ('predict', 'train_and_predict'):
predict_squad(strategy, input_meta_data)
示例10: StartTeeLogsToFile
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def StartTeeLogsToFile(
program_name: str = None,
log_dir: str = None,
file_log_level: int = logging.DEBUG,
) -> None:
"""Log messages to file as well as stderr.
Args:
program_name: The name of the program.
log_dir: The directory to log to.
file_log_level: The minimum verbosity level to log to file to.
Raises:
FileNotFoundError: If the requested log_dir does not exist.
"""
if not pathlib.Path(log_dir).is_dir():
raise FileNotFoundError(f"Log directory not found: '{log_dir}'")
old_verbosity = logging.get_verbosity()
logging.set_verbosity(file_log_level)
logging.set_stderrthreshold(old_verbosity)
logging.get_absl_handler().start_logging_to_file(program_name, log_dir)
# The Absl logging handler function start_logging_to_file() sets logtostderr
# to False. Re-enable whatever value it was before the call.
FLAGS.logtostderr = False
示例11: main
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def main(argv):
del argv # Unused.
if FLAGS.verbose:
logging.set_verbosity(logging.INFO)
if FLAGS.debug:
logging.set_verbosity(logging.DEBUG)
logging.debug('binary: %s\noptimize: %d\nbase_directory: %s\n'
'policy_file: %s\nrendered_acl_directory: %s',
str(sys.argv[0]),
int(FLAGS.optimize),
str(FLAGS.base_directory),
str(FLAGS.policy_file),
str(FLAGS.output_directory))
context = multiprocessing.get_context()
Run(FLAGS.base_directory, FLAGS.definitions_directory, FLAGS.policy_file,
FLAGS.output_directory, context)
示例12: main
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def main(_):
logging.set_verbosity(FLAGS.log_level)
_tf_setup_from_flags()
_gin_parse_configs()
_jax_and_tf_configure_for_devices()
output_dir = _output_dir_or_default()
if FLAGS.use_tpu and fastmath.backend_name() == 'tf':
_train_using_tf(output_dir)
else:
trainer_lib.train(output_dir=output_dir)
trainer_lib.log('Finished training.')
示例13: _test_debug_logging_with_async_function
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def _test_debug_logging_with_async_function(self, async_fn, test_regex, *args,
**kwargs):
loop = asyncio.get_event_loop()
try:
logging.set_verbosity(1)
retval = loop.run_until_complete(async_fn(*args, **kwargs))
finally:
logging.set_verbosity(0)
self.assertRegexMatch(''.join(self.log.getvalue()), [test_regex])
self.log.truncate(0)
loop.run_until_complete(async_fn(*args, **kwargs))
self.assertEmpty(''.join(self.log.getvalue()))
return retval
示例14: _test_debug_logging_with_sync_function
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def _test_debug_logging_with_sync_function(self, sync_fn, test_regex, *args,
**kwargs):
try:
logging.set_verbosity(1)
retval = sync_fn(*args, **kwargs)
finally:
logging.set_verbosity(0)
self.assertRegexMatch(''.join(self.log.getvalue()), [test_regex])
self.log.truncate(0)
self.assertEmpty(''.join(self.log.getvalue()))
return retval
示例15: main
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import set_verbosity [as 别名]
def main(unused_argv):
logging.set_verbosity(logging.INFO)
logging.info("tensorflow version: %s", tf.__version__)
evaluate()