本文整理汇总了Python中tensorflow.contrib.metrics.streaming_mean方法的典型用法代码示例。如果您正苦于以下问题:Python metrics.streaming_mean方法的具体用法?Python metrics.streaming_mean怎么用?Python metrics.streaming_mean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.metrics
的用法示例。
在下文中一共展示了metrics.streaming_mean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_eval_ops
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _get_eval_ops(self, features, labels, metrics):
"""Method that builds model graph and returns evaluation ops.
Expected to be overriden by sub-classes that require custom support.
This implementation uses `model_fn` passed as parameter to constructor to
build model.
Args:
features: `Tensor` or `dict` of `Tensor` objects.
labels: `Tensor` or `dict` of `Tensor` objects.
metrics: Dict of metrics to run. If None, the default metric functions
are used; if {}, no metrics are used. Otherwise, `metrics` should map
friendly names for the metric to a `MetricSpec` object defining which
model outputs to evaluate against which labels with which metric
function. Metric ops should support streaming, e.g., returning
update_op and value tensors. See more details in
`../../../../metrics/python/metrics/ops/streaming_metrics.py` and
`../metric_spec.py`.
Returns:
`ModelFnOps` object.
Raises:
ValueError: if `metrics` don't match `labels`.
"""
model_fn_ops = self._call_model_fn(
features, labels, model_fn_lib.ModeKeys.EVAL)
features, labels = self._feature_engineering_fn(features, labels)
# Custom metrics should overwrite defaults.
if metrics:
model_fn_ops.eval_metric_ops.update(_make_metrics_ops(
metrics, features, labels, model_fn_ops.predictions))
if metric_key.MetricKey.LOSS not in model_fn_ops.eval_metric_ops:
model_fn_ops.eval_metric_ops[metric_key.MetricKey.LOSS] = (
metrics_lib.streaming_mean(model_fn_ops.loss))
return model_fn_ops
示例2: _metrics
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _metrics(self, eval_loss, predictions, labels, weights):
"""Returns a dict of metrics keyed by name."""
del predictions, labels, weights # Unused by this head.
with ops.name_scope("metrics", values=[eval_loss]):
return {
_summary_key(self.head_name, mkey.LOSS):
metrics_lib.streaming_mean(eval_loss)}
示例3: _indicator_labels_streaming_mean
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _indicator_labels_streaming_mean(labels, weights=None, class_id=None):
labels = math_ops.to_float(labels)
weights = _float_weights_or_none(weights)
if weights is not None:
weights = weights_broadcast_ops.broadcast_weights(weights, labels)
if class_id is not None:
if weights is not None:
weights = weights[:, class_id]
labels = labels[:, class_id]
return metrics_lib.streaming_mean(labels, weights=weights)
示例4: _predictions_streaming_mean
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _predictions_streaming_mean(predictions,
weights=None,
class_id=None):
predictions = math_ops.to_float(predictions)
weights = _float_weights_or_none(weights)
if weights is not None:
weights = weights_broadcast_ops.broadcast_weights(weights, predictions)
if class_id is not None:
if weights is not None:
weights = weights[:, class_id]
predictions = predictions[:, class_id]
return metrics_lib.streaming_mean(predictions, weights=weights)
# TODO(ptucker): Add support for SparseTensor labels.
示例5: _class_predictions_streaming_mean
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _class_predictions_streaming_mean(predictions, weights, class_id):
return metrics_lib.streaming_mean(
array_ops.where(
math_ops.equal(
math_ops.to_int32(class_id), math_ops.to_int32(predictions)),
array_ops.ones_like(predictions),
array_ops.zeros_like(predictions)),
weights=weights)
示例6: _class_labels_streaming_mean
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _class_labels_streaming_mean(labels, weights, class_id):
return metrics_lib.streaming_mean(
array_ops.where(
math_ops.equal(
math_ops.to_int32(class_id), math_ops.to_int32(labels)),
array_ops.ones_like(labels), array_ops.zeros_like(labels)),
weights=weights)
示例7: _get_eval_ops
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _get_eval_ops(self, features, labels, metrics):
"""Method that builds model graph and returns evaluation ops.
Expected to be overriden by sub-classes that require custom support.
This implementation uses `model_fn` passed as parameter to constructor to
build model.
Args:
features: `Tensor` or `dict` of `Tensor` objects.
labels: `Tensor` or `dict` of `Tensor` objects.
metrics: Dict of metrics to run. If None, the default metric functions
are used; if {}, no metrics are used. Otherwise, `metrics` should map
friendly names for the metric to a `MetricSpec` object defining which
model outputs to evaluate against which labels with which metric
function. Metric ops should support streaming, e.g., returning
update_op and value tensors. See more details in
`../../../../metrics/python/metrics/ops/streaming_metrics.py` and
`../metric_spec.py`.
Returns:
`ModelFnOps` object.
Raises:
ValueError: if `metrics` don't match `labels`.
"""
model_fn_ops = self._call_model_fn(
features, labels, model_fn_lib.ModeKeys.EVAL)
# Custom metrics should overwrite defaults.
if metrics:
model_fn_ops.eval_metric_ops.update(_make_metrics_ops(
metrics, features, labels, model_fn_ops.predictions))
if metric_key.MetricKey.LOSS not in model_fn_ops.eval_metric_ops:
model_fn_ops.eval_metric_ops[metric_key.MetricKey.LOSS] = (
metrics_lib.streaming_mean(model_fn_ops.loss))
return model_fn_ops
示例8: _weighted_average_loss_metric_spec
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _weighted_average_loss_metric_spec(loss_fn, pred_key, label_key,
weight_key):
def _streaming_weighted_average_loss(predictions, labels, weights=None):
loss_unweighted = loss_fn(predictions, labels)
if weights is not None:
weights = math_ops.to_float(weights)
_, weighted_average_loss = _loss(loss_unweighted, weights, name="eval_loss")
return metrics_lib.streaming_mean(weighted_average_loss)
return metric_spec.MetricSpec(_streaming_weighted_average_loss, pred_key,
label_key, weight_key)
示例9: _indicator_labels_streaming_mean
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _indicator_labels_streaming_mean(predictions,
labels,
weights=None,
class_id=None):
del predictions
if class_id is not None:
labels = labels[:, class_id]
return metrics_lib.streaming_mean(labels, weights=weights)
示例10: _predictions_streaming_mean
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _predictions_streaming_mean(predictions,
labels,
weights=None,
class_id=None):
del labels
if class_id is not None:
predictions = predictions[:, class_id]
return metrics_lib.streaming_mean(predictions, weights=weights)
# TODO(ptucker): Add support for SparseTensor labels.
示例11: _get_eval_ops
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _get_eval_ops(self, features, labels, metrics):
"""Method that builds model graph and returns evaluation ops.
Expected to be overriden by sub-classes that require custom support.
This implementation uses `model_fn` passed as parameter to constructor to
build model.
Args:
features: `Tensor` or `dict` of `Tensor` objects.
labels: `Tensor` or `dict` of `Tensor` objects.
metrics: Dict of metrics to run. If None, the default metric functions
are used; if {}, no metrics are used. Otherwise, `metrics` should map
friendly names for the metric to a `MetricSpec` object defining which
model outputs to evaluate against which labels with which metric
function. Metric ops should support streaming, e.g., returning
update_op and value tensors. See more details in
`../../../../metrics/python/metrics/ops/streaming_metrics.py` and
`../metric_spec.py`.
Returns:
metrics: `dict` of `Tensor` objects.
Raises:
ValueError: if `metrics` don't match `labels`.
"""
model_fn_ops = self._call_model_fn(features, labels, ModeKeys.EVAL)
all_metrics = model_fn_ops.default_metrics
# Custom metrics should overwrite defaults.
if metrics:
all_metrics.update(metrics)
result = _make_metrics_ops(all_metrics, features, labels,
model_fn_ops.predictions)
if metric_key.MetricKey.LOSS not in result:
result[metric_key.MetricKey.LOSS] = metrics_lib.streaming_mean(
model_fn_ops.loss)
return result
示例12: _weighted_average_loss_metric_spec
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _weighted_average_loss_metric_spec(loss_fn, predictoin_key,
label_key, weight_key):
def _streaming_weighted_average_loss(predictions, labels, weights=None):
loss_unweighted = loss_fn(predictions, labels)
if weights is not None:
weights = math_ops.to_float(weights)
_, weighted_average_loss = _loss(loss_unweighted,
weights,
name="eval_loss")
return metrics_lib.streaming_mean(weighted_average_loss)
return metric_spec.MetricSpec(_streaming_weighted_average_loss,
predictoin_key, label_key, weight_key)
示例13: _labels_streaming_mean
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _labels_streaming_mean(unused_predictions, labels, weights=None):
return metrics_lib.streaming_mean(labels, weights=weights)
示例14: _predictions_streaming_mean
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _predictions_streaming_mean(predictions, unused_labels, weights=None):
return metrics_lib.streaming_mean(predictions, weights=weights)
示例15: _labels_streaming_mean
# 需要导入模块: from tensorflow.contrib import metrics [as 别名]
# 或者: from tensorflow.contrib.metrics import streaming_mean [as 别名]
def _labels_streaming_mean(unused_predictions, labels):
return metrics_lib.streaming_mean(labels)