Browse Source

_prepare_metric函数增加检查evaluate与get_metric方法

tags/v0.2.0^2
yh 6 years ago
parent
commit
84024aaaa4
1 changed files with 5 additions and 0 deletions
  1. +5
    -0
      fastNLP/core/metrics.py

+ 5
- 0
fastNLP/core/metrics.py View File

@@ -193,6 +193,11 @@ def _prepare_metrics(metrics):
if isinstance(metric, type):
metric = metric()
if isinstance(metric, MetricBase):
metric_name = metric.__class__.__name__
if not callable(metric.evaluate):
raise TypeError(f"{metric_name}.evaluate must be callable, got {type(metric.evaluate)}.")
if not callable(metric.get_metric):
raise TypeError(f"{metric_name}.get_metric must be callable, got {type(metric.get_metric)}.")
_metrics.append(metric)
else:
raise TypeError(f"The type of metric in metrics must be `fastNLP.MetricBase`, not `{type(metric)}`.")


Loading…
Cancel
Save