Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Custom eval hooks #1284

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tensor2tensor/data_generators/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ class Problem(object):
Eval:
* eval_metrics
- Specify the set of evaluation metrics for this problem.
* eval_hooks
- Specify the set of evalueation hooks for this problem.

Inference:
* feature_encoders(data_dir)
Expand Down Expand Up @@ -365,6 +367,9 @@ def eval_metrics(self):
metrics.Metrics.ACC_PER_SEQ, metrics.Metrics.NEG_LOG_PERPLEXITY
]

def eval_hooks(self, features, logits, hparams):
return []

@property
def task_id(self):
if self._task_id == -1 and hasattr(self, "global_task_id"):
Expand Down
3 changes: 3 additions & 0 deletions tensor2tensor/utils/t2t_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ def estimator_spec_eval(self, features, logits, labels, loss, losses_dict):
raise NotImplementedError(_no_problem_err("estimator_spec_eval"))

problem = hparams.problem

if common_layers.is_xla_compiled():
remove_summaries()
if isinstance(logits, dict):
Expand Down Expand Up @@ -1509,6 +1510,8 @@ def estimator_spec_eval(self, features, logits, labels, loss, losses_dict):
summary_op=tf.summary.merge_all())
evaluation_hooks.append(eval_summary_hook)

evaluation_hooks += problem.eval_hooks(features, logits, hparams)

return tf.estimator.EstimatorSpec(
tf.estimator.ModeKeys.EVAL,
predictions=predictions,
Expand Down