本文整理汇总了Python中absl.logging.warning方法的典型用法代码示例。如果您正苦于以下问题:Python logging.warning方法的具体用法?Python logging.warning怎么用?Python logging.warning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类absl.logging
的用法示例。
在下文中一共展示了logging.warning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_constants_from_storage
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def load_constants_from_storage(self):
"""Attempts to load constants from Google Cloud Storage."""
try:
constants = self._storage_api.get_blob(
self._config.constants_storage_path,
self._config.bucket,
)
except storage.NotFoundError as err:
logging.error('Constants were not found in storage: %s', err)
else:
for name in self._constants.keys():
try:
self._constants[name].value = constants[name]
except ValueError:
logging.warning(
'The value %r for %r stored in Google Cloud Storage does not meet'
' the requirements. Using the default value...',
constants[name], name)
except KeyError:
logging.info(
'The key %r was not found in the stored constants, this may be '
'because a new constant was added since your most recent '
'configuration. To resolve run `configure` in the main menu.',
name)
示例2: from_config
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def from_config(cls, config, custom_objects=None):
model = super(CalibratedLinear, cls).from_config(
config, custom_objects=custom_objects)
try:
model_config = tf.keras.utils.deserialize_keras_object(
config.get('model_config'), custom_objects=custom_objects)
premade_lib.verify_config(model_config)
model.model_config = model_config
except ValueError:
logging.warning(
'Could not load model_config. Constructing model without it: %s',
str(config.get('model_config')))
return model
# TODO: add support for tf.map_fn and inputs of shape (B, ?, input_dim)
# as well as non-ragged inputs using padding/mask.
示例3: main
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def main(unused_argv):
"""Prints Q&As from modules according to FLAGS.filter."""
init_modules()
text_wrapper = textwrap.TextWrapper(
width=80, initial_indent=' ', subsequent_indent=' ')
for regime, flat_modules in six.iteritems(filtered_modules):
per_module = counts[regime]
for module_name, module in six.iteritems(flat_modules):
# These magic print constants make the header bold.
print('\033[1m{}/{}\033[0m'.format(regime, module_name))
num_dropped = 0
for _ in range(per_module):
problem, extra_dropped = sample_from_module(module)
num_dropped += extra_dropped
text = text_wrapper.fill(
'{} \033[92m{}\033[0m'.format(problem.question, problem.answer))
print(text)
if num_dropped > 0:
logging.warning('Dropped %d examples', num_dropped)
示例4: __init__
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def __init__(self, space, vocab_size, precision=2, max_range=(-100.0, 100.0)):
self._precision = precision
# Some gym envs (e.g. CartPole) have unreasonably high bounds for
# observations. We clip so we can represent them.
bounded_space = copy.copy(space)
(min_low, max_high) = max_range
bounded_space.low = np.maximum(space.low, min_low)
bounded_space.high = np.minimum(space.high, max_high)
if (not np.allclose(bounded_space.low, space.low) or
not np.allclose(bounded_space.high, space.high)):
logging.warning(
'Space limits %s, %s out of bounds %s. Clipping to %s, %s.',
str(space.low), str(space.high), str(max_range),
str(bounded_space.low), str(bounded_space.high)
)
super(BoxSpaceSerializer, self).__init__(bounded_space, vocab_size)
示例5: _build_metric
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def _build_metric(metric,
num_categories,
ignored_label,
max_instances_per_category,
intersection_offset=None,
normalize_by_image_size=True):
"""Creates a metric aggregator objet of the given name."""
if metric == 'pq':
logging.warning('One should check Panoptic Quality results against the '
'official COCO API code. Small numerical differences '
'(< 0.1%) can be magnified by rounding.')
return panoptic_quality.PanopticQuality(num_categories, ignored_label,
max_instances_per_category,
intersection_offset)
elif metric == 'pc':
return parsing_covering.ParsingCovering(
num_categories, ignored_label, max_instances_per_category,
intersection_offset, normalize_by_image_size)
else:
raise ValueError('No implementation for metric "%s"' % metric)
示例6: _is_thing_array
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def _is_thing_array(categories_json, ignored_label):
"""is_thing[category_id] is a bool on if category is "thing" or "stuff"."""
is_thing_dict = {}
for category_json in categories_json:
is_thing_dict[category_json['id']] = bool(category_json['isthing'])
# Check our assumption that the category ids are consecutive.
# Usually metrics should be able to handle this case, but adding a warning
# here.
max_category_id = max(six.iterkeys(is_thing_dict))
if len(is_thing_dict) != max_category_id + 1:
seen_ids = six.viewkeys(is_thing_dict)
all_ids = set(six.moves.range(max_category_id + 1))
unseen_ids = all_ids.difference(seen_ids)
if unseen_ids != {ignored_label}:
logging.warning(
'Nonconsecutive category ids or no category JSON specified for ids: '
'%s', unseen_ids)
is_thing_array = np.zeros(max_category_id + 1)
for category_id, is_thing in six.iteritems(is_thing_dict):
is_thing_array[category_id] = is_thing
return is_thing_array
示例7: _parse_tsv
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def _parse_tsv(path, language_pair=None):
"""Generates examples from TSV file."""
if language_pair is None:
lang_match = re.match(r".*\.([a-z][a-z])-([a-z][a-z])\.tsv", path)
assert lang_match is not None, "Invalid TSV filename: %s" % path
l1, l2 = lang_match.groups()
else:
l1, l2 = language_pair
with tf.io.gfile.GFile(path) as f:
for j, line in enumerate(f):
cols = line.split("\t")
if len(cols) != 2:
logging.warning(
"Skipping line %d in TSV (%s) with %d != 2 columns.",
j, path, len(cols))
continue
s1, s2 = cols
yield j, {
l1: s1.strip(),
l2: s2.strip()
}
示例8: _generate_examples
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def _generate_examples(self, archive):
"""Generate Cats vs Dogs images and labels given a directory path."""
num_skipped = 0
for fname, fobj in archive:
res = _NAME_RE.match(fname)
if not res: # README file, ...
continue
label = res.group(1).lower()
if tf.compat.as_bytes("JFIF") not in fobj.peek(10):
num_skipped += 1
continue
record = {
"image": fobj,
"image/filename": fname,
"label": label,
}
yield fname, record
if num_skipped != _NUM_CORRUPT_IMAGES:
raise ValueError("Expected %d corrupt images, but found %d" % (
_NUM_CORRUPT_IMAGES, num_skipped))
logging.warning("%d images were corrupted and were skipped", num_skipped)
示例9: after_download
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def after_download(self) -> bool:
try:
train_file_path = os.path.join(self.data_dir, self.train_file)
dev_file_path = os.path.join(self.data_dir, self.dev_file)
test_file_path = os.path.join(self.data_dir, self.test_file)
text_vocab_file = os.path.join(self.data_dir, self.text_vocab)
label_vocab_file = os.path.join(self.data_dir, self.label_vocab)
mock_data(self.samples, train_file_path, dev_file_path, test_file_path,
text_vocab_file, self.text_vocab_list, label_vocab_file, self.label_vocab_list)
except Exception as e:
logging.warning(traceback.format_exc())
return False
return True
示例10: after_download
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def after_download(self) -> bool:
try:
for data_type in self.samples_dict:
samples = self.samples_dict[data_type]
text_vocab_list = self.text_vocab_dict[data_type]
train_file_path = os.path.join(self.data_dir,
self.train_file.replace("txt", "") + data_type + ".txt")
dev_file_path = os.path.join(self.data_dir,
self.dev_file.replace("txt", "") + data_type + ".txt")
test_file_path = os.path.join(self.data_dir,
self.test_file.replace("txt", "") + data_type + ".txt")
text_vocab_file = os.path.join(self.data_dir,
self.text_vocab.replace("txt", "") + data_type + ".txt")
mock_data(samples, train_file_path, dev_file_path, test_file_path, text_vocab_file, text_vocab_list)
except Exception as e:
logging.warning(traceback.format_exc())
return False
return True
示例11: validate
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def validate(self):
''' Sanity check. Make sure everything is (probably) OK. '''
# TODO: more efficient and robust. Also check speakers.
for utt_key in self.utts.keys():
first_utt_key = utt_key
break
num_props = len(self.utts[first_utt_key])
for utt_key, utt in self.utts.items():
if len(utt) != num_props:
logging.warning('Utt %s has unequal number of props with %s.' % \
(utt_key, first_utt_key))
return False
if 'spkid' not in utt:
utt['spkid'] = self.spks[utt.spk].id
logging.warning(
'All utts have same number of props, data dir appears to be OK.')
return True
示例12: config_join_project_path
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def config_join_project_path(project_dir: str, config: dict,
key_path: List[Union[str, int]]):
"""join project dir on a path"""
d = config
try:
for k in key_path[:-1]:
d = d[k]
original_path = d[key_path[-1]]
except KeyError as e:
logging.warning(f"key_path: {key_path} not found!")
raise KeyError(repr(e))
if isinstance(original_path, list):
d[key_path[-1]] = [os.path.join(project_dir, p) for p in original_path]
elif isinstance(original_path, str):
d[key_path[-1]] = os.path.join(project_dir, original_path)
else:
logging.warning(f"key_path: {key_path} error.")
raise TypeError("path is not str or list!")
示例13: unbundle
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def unbundle(self, checkpoint_dir, iteration_number, bundle_dict):
"""Restores the agent from a checkpoint.
Args:
checkpoint_dir: A string that represents the path to the checkpoint and is
used when we save TensorFlow objects by tf.Save.
iteration_number: An integer that represents the checkpoint version and is
used when restoring replay buffer.
bundle_dict: A dict containing additional Python objects owned by the
agent. Each key is an object name and the value is the actual object.
Returns:
bool, True if unbundling was successful.
"""
del checkpoint_dir # Unused.
del iteration_number # Unused.
if 'episode_num' not in bundle_dict:
logging.warning(
'Could not unbundle from checkpoint files with exception.')
return False
self._episode_num = bundle_dict['episode_num']
return True
示例14: sample_from_module
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def sample_from_module(module):
"""Samples a problem, ignoring samples with overly long questions / answers.
Args:
module: Callable returning a `Problem`.
Returns:
Pair `(problem, num_dropped)`, where `problem` is an instance of `Problem`
and `num_dropped` is an integer >= 0 indicating the number of samples that
were dropped.
"""
num_dropped = 0
while True:
problem = module()
question = str(problem.question)
if len(question) > generate_settings.MAX_QUESTION_LENGTH:
num_dropped += 1
if FLAGS.show_dropped:
logging.warning('Dropping question: %s', question)
continue
answer = str(problem.answer)
if len(answer) > generate_settings.MAX_ANSWER_LENGTH:
num_dropped += 1
if FLAGS.show_dropped:
logging.warning('Dropping question with answer: %s', answer)
continue
return problem, num_dropped
示例15: reverse_action
# 需要导入模块: from absl import logging [as 别名]
# 或者: from absl.logging import warning [as 别名]
def reverse_action(self, action):
"""
Transform a Dota2-style action into an agent-style action.
"""
def func_call(func_id, args):
return actions.FunctionCall(func_id, [[int(v) for v in a] for a in args])
def func_call_ability(ability_id, cmd_type, args):
"""Get the function id for a specific ability id and action type."""
if ability_id not in actions.ABILITY_IDS:
logging.warning("Unknown ability_id: %s. Treating as a no-op.", ability_id)
return func_call_name("no_op", [])
if self._hide_specific_actions:
general_id = next(iter(actions.ABILITY_IDS[ability_id])).general_id
if general_id:
ability_id = general_id
for func in actions.ABILITY_IDS[ability_id]:
if func.function_type is cmd_type:
return func_call(func.id, args)
raise ValueError("Unknown ability_id: %s, type: %s. Likely a bug." % (
ability_id, cmd_type.__name__))
def func_call_name(name, args):
return func_call(actions.FUNCTIONS[name].id, args)
return func_call_name("no_op", [])