本文整理匯總了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