本文整理汇总了Python中tensorflow.compat.v1.metrics方法的典型用法代码示例。如果您正苦于以下问题:Python v1.metrics方法的具体用法?Python v1.metrics怎么用?Python v1.metrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.compat.v1
的用法示例。
在下文中一共展示了v1.metrics方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testDoesNotModifyTF2
# 需要导入模块: from tensorflow.compat import v1 [as 别名]
# 或者: from tensorflow.compat.v1 import metrics [as 别名]
def testDoesNotModifyTF2(self):
modules_no_overwritten = [
(tf2.data, tf1.data),
(tf2.graph_util, tf1.graph_util),
(tf2.image, tf1.image),
(tf2.initializers, tf1.initializers),
(tf2.io, tf1.io),
(tf2.losses, tf1.losses),
(tf2.metrics, tf1.metrics),
(tf2.nn, tf1.nn),
(tf2.random, tf1.random),
(tf2.saved_model, tf1.saved_model),
(tf2.strings, tf1.strings),
(tf2.summary, tf1.summary),
(tf2.test, tf1.test),
(tf2.train, tf1.train),
]
for modules in modules_no_overwritten:
self.assertIsNot(modules[0], modules[1])
示例2: reconstruction_loss
# 需要导入模块: from tensorflow.compat import v1 [as 别名]
# 或者: from tensorflow.compat.v1 import metrics [as 别名]
def reconstruction_loss(self, x_input, x_target, x_length, z=None,
c_input=None):
"""Reconstruction loss calculation.
Args:
x_input: Batch of decoder input sequences for teacher forcing, sized
`[batch_size, max(x_length), output_depth]`.
x_target: Batch of expected output sequences to compute loss against,
sized `[batch_size, max(x_length), output_depth]`.
x_length: Length of input/output sequences, sized `[batch_size]`.
z: (Optional) Latent vectors. Required if model is conditional. Sized
`[n, z_size]`.
c_input: (Optional) Batch of control sequences, sized
`[batch_size, max(x_length), control_depth]`. Required if conditioning
on control sequences.
Returns:
r_loss: The reconstruction loss for each sequence in the batch.
metric_map: Map from metric name to tf.metrics return values for logging.
"""
pass
示例3: hamming_loss
# 需要导入模块: from tensorflow.compat import v1 [as 别名]
# 或者: from tensorflow.compat.v1 import metrics [as 别名]
def hamming_loss(preds, targets, sign=False):
"""Implements hamming loss.
Args:
preds: Tensor of predicted values.
targets: Tensor of target values.
sign (bool): Set to True if targets={-1, 1} to take the sign of preds
before calculating loss.
Returns:
A tf.metrics tuple containing the proportion of incorrect predictions and an
update op for the metric.
"""
if sign:
preds = tf.sign(preds)
equal = tf.equal(preds, tf.cast(targets, preds.dtype))
proportion_correct, update_op = tf.metrics.mean(tf.cast(equal, tf.float32))
return 1 - proportion_correct, update_op
示例4: eval
# 需要导入模块: from tensorflow.compat import v1 [as 别名]
# 或者: from tensorflow.compat.v1 import metrics [as 别名]
def eval(self, input_sequence, output_sequence, sequence_length,
control_sequence=None):
"""Evaluate on the given sequences, returning metric update ops.
Args:
input_sequence: The sequence to be fed to the encoder.
output_sequence: The sequence expected from the decoder.
sequence_length: The length of the given sequences (which must be
identical).
control_sequence: (Optional) sequence on which to condition the decoder.
Returns:
metric_update_ops: tf.metrics update ops.
"""
metric_map, scalars_to_summarize = self._compute_model_loss(
input_sequence, output_sequence, sequence_length, control_sequence)
for n, t in scalars_to_summarize.items():
metric_map[n] = tf.metrics.mean(t)
metrics_to_values, metrics_to_updates = (
tf_slim.metrics.aggregate_metric_map(metric_map))
for metric_name, metric_value in metrics_to_values.items():
tf.summary.scalar(metric_name, metric_value)
return list(metrics_to_updates.values())
示例5: _flat_reconstruction_loss
# 需要导入模块: from tensorflow.compat import v1 [as 别名]
# 或者: from tensorflow.compat.v1 import metrics [as 别名]
def _flat_reconstruction_loss(self, flat_x_target, flat_rnn_output):
"""Core loss calculation method for flattened outputs.
Args:
flat_x_target: The flattened ground truth vectors, sized
`[sum(x_length), self._output_depth]`.
flat_rnn_output: The flattened output from all timeputs of the RNN,
sized `[sum(x_length), rnn_output_size]`.
Returns:
r_loss: The unreduced reconstruction losses, sized `[sum(x_length)]`.
metric_map: A map of metric names to tuples, each of which contain the
pair of (value_tensor, update_op) from a tf.metrics streaming metric.
"""
pass