MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _eager_metrics_fn

Function _eager_metrics_fn

tensorflow/python/keras/engine/training_eager.py:42–82  ·  view source on GitHub ↗

Calculates the metrics for each output of the given model. Arguments: model: The model on which metrics are being calculated. outputs: The outputs of the given model. targets: The predictions or targets of the given model. sample_weights: Optional list of sample weights fo

(model, outputs, targets, sample_weights=None, masks=None)

Source from the content-addressed store, hash-verified

40
41
42def _eager_metrics_fn(model, outputs, targets, sample_weights=None, masks=None):
43 """Calculates the metrics for each output of the given model.
44
45 Arguments:
46 model: The model on which metrics are being calculated.
47 outputs: The outputs of the given model.
48 targets: The predictions or targets of the given model.
49 sample_weights: Optional list of sample weights for each output.
50 masks: Optional list of masks for each output.
51
52 Returns:
53 Returns the metric results for each output of the model.
54 """
55 outputs = nest.flatten(outputs)
56 targets = nest.flatten(targets)
57 # Invoke all(weighted and unweighted) metrics.
58 metric_results = []
59 if targets:
60 # Insert None values corresponding to the targets that need to be skipped
61 # on the model.
62 if len(model._targets) != len(targets):
63 new_targets = [
64 None if t is None else targets.pop(0) for t in model._targets
65 ]
66 targets = new_targets
67
68 metric_results = model._handle_metrics(
69 outputs,
70 targets=targets,
71 sample_weights=sample_weights,
72 masks=masks,
73 return_weighted_and_unweighted_metrics=True,
74 skip_target_masks=model._prepare_skip_target_masks())
75
76 # Add metric results from the `add_metric` metrics.
77 metric_results.extend([
78 m.result()
79 for m in model.metrics
80 if m not in model._compile_metric_functions
81 ])
82 return metric_results
83
84
85def _model_loss(model,

Callers 2

train_on_batchFunction · 0.85
test_on_batchFunction · 0.85

Calls 6

_handle_metricsMethod · 0.80
flattenMethod · 0.45
popMethod · 0.45
extendMethod · 0.45
resultMethod · 0.45

Tested by 1

test_on_batchFunction · 0.68