本文整理汇总了Python中tensorflow.keras.metrics方法的典型用法代码示例。如果您正苦于以下问题:Python keras.metrics方法的具体用法?Python keras.metrics怎么用?Python keras.metrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.keras
的用法示例。
在下文中一共展示了keras.metrics方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _init
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def _init(string_list, tf_funcs, custom_funcs, logger=None, **kwargs):
"""
Helper for 'init_losses' or 'init_metrics'.
Please refer to their docstrings.
Args:
string_list: (list) List of strings, each giving a name of a metric
or loss to use for training. The name should
refer to a function or class in either tf_funcs
or custom_funcs modules.
tf_funcs: (module) A Tensorflow.keras module of losses or metrics,
or a list of various modules to look through.
custom_funcs: (module) A custom module or losses or metrics
logger: (Logger) A Logger object
**kwargs: (dict) Parameters passed to all losses or metrics which
are represented by a class (i.e. not a function)
Returns:
A list of len(string_list) of initialized classes of losses or metrics
or references to loss or metric functions.
"""
initialized = []
tf_funcs = ensure_list_or_tuple(tf_funcs)
for func_or_class in ensure_list_or_tuple(string_list):
modules_found = list(filter(None, [getattr(m, func_or_class, None)
for m in tf_funcs]))
if modules_found:
initialized.append(modules_found[0]) # return the first found
else:
# Fall back to look in custom module
initialized.append(getattr(custom_funcs, func_or_class))
return initialized
示例2: init_metrics
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def init_metrics(metric_string_list, logger=None, **kwargs):
"""
Same as 'init_losses', but for metrics.
Please refer to the 'init_losses' docstring.
"""
return _init(
metric_string_list, metrics, custom_metrics, logger, **kwargs
)
示例3: __init__
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def __init__(self, metrics=None):
# str -> MetricHistory
self.metrics = {}
self.register_metrics(metrics)
示例4: register_metrics
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def register_metrics(self, metrics=None):
metrics = metrics or []
for metric in metrics:
self.register(metric.name)
示例5: register
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def register(self, name, direction=None):
if self.exists(name):
raise ValueError('Metric already exists: %s' % (name,))
if direction is None:
direction = infer_metric_direction(name)
if direction is None:
# Objective direction is handled separately, but
# non-objective direction defaults to min.
direction = 'min'
self.metrics[name] = MetricHistory(direction)
示例6: update
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def update(self, name, value, step=0):
value = float(value)
if not self.exists(name):
self.register(name)
prev_best = self.metrics[name].get_best_value()
self.metrics[name].update(value, step=step)
new_best = self.metrics[name].get_best_value()
improved = new_best != prev_best
return improved
示例7: get_history
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def get_history(self, name):
self._assert_exists(name)
return self.metrics[name].get_history()
示例8: get_best_value
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def get_best_value(self, name):
self._assert_exists(name)
return self.metrics[name].get_best_value()
示例9: get_best_step
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def get_best_step(self, name):
self._assert_exists(name)
return self.metrics[name].get_best_step()
示例10: get_statistics
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def get_statistics(self, name):
self._assert_exists(name)
return self.metrics[name].get_statistics()
示例11: get_last_value
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def get_last_value(self, name):
self._assert_exists(name)
return self.metrics[name].get_last_value()
示例12: get_direction
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def get_direction(self, name):
self._assert_exists(name)
return self.metrics[name].direction
示例13: from_config
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def from_config(cls, config):
instance = cls()
instance.metrics = {
name: MetricHistory.from_config(metric_history)
for name, metric_history in config['metrics'].items()}
return instance
示例14: to_proto
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def to_proto(self):
return kerastuner_pb2.MetricsTracker(metrics={
name: metric_history.to_proto()
for name, metric_history in self.metrics.items()})
示例15: from_proto
# 需要导入模块: from tensorflow import keras [as 别名]
# 或者: from tensorflow.keras import metrics [as 别名]
def from_proto(cls, proto):
instance = cls()
instance.metrics = {
name: MetricHistory.from_proto(metric_history)
for name, metric_history in proto.metrics.items()}
return instance