Evaluator TFXパイプラインコンポーネントは、モデルのトレーニング結果に対して詳細な分析を実行し、データのサブセットに対してモデルがどのように機能するかを理解するのに役立ちます。 Evaluatorは、エクスポートされたモデルの検証にも役立ち、本番環境にプッシュするのに「十分」であることを確認します。
検証が有効になっている場合、エバリュエーターは新しいモデルをベースライン(現在提供されているモデルなど)と比較して、ベースラインに対して「十分に良い」かどうかを判断します。これは、評価データセットで両方のモデルを評価し、メトリック(AUC、損失など)でそれらのパフォーマンスを計算することによって行われます。新モデルのメトリックは、(例えばAUCが低くはない)ベースラインモデルに比べて、開発者が指定した基準を満たしている場合は、モデルは(良いとしてマーク)「恵まれ」され、に示すプッシャー生産するモデルをプッシュしても大丈夫であること。
- 消費:
- evalを分割ExampleGen
- 訓練されたモデルトレーナー
- 以前に祝福されたモデル(検証を実行する場合)
- 放出:
EvaluatorおよびTensorFlowモデル分析
評価者は、活用TensorFlowモデル分析、解析を実行するためのライブラリをどの順番で使用中のApacheビームスケーラブルな処理のために。
エバリュエーターコンポーネントの使用
Evaluatorパイプラインコンポーネントは通常、展開が非常に簡単で、ほとんどの作業がEvaluator TFXコンポーネントによって行われるため、カスタマイズはほとんど必要ありません。
評価者を設定するには、次の情報が必要です。
- 構成するメトリック(モデルとともに保存されたメトリック以外に追加のメトリックが追加されている場合にのみ必要)。参照してくださいTensorflowモデル分析指標を詳細については。
- 構成するスライス(スライスが指定されていない場合、デフォルトで「全体」スライスが追加されます)。参照してくださいTensorflowモデル解析の設定を詳細については。
検証を含める場合は、次の追加情報が必要です。
- どのモデルと比較するか(最新の祝福など)。
- 検証するモデル検証(しきい値)。参照してくださいTensorflowモデル解析モデルの検証を詳細については。
有効にすると、定義されたすべてのメトリックとスライスに対して検証が実行されます。
典型的なコードは次のようになります。
import tensorflow_model_analysis as tfma
...
# For TFMA evaluation
eval_config = tfma.EvalConfig(
model_specs=[
# This assumes a serving model with signature 'serving_default'. If
# using estimator based EvalSavedModel, add signature_name='eval' and
# remove the label_key. Note, if using a TFLite model, then you must set
# model_type='tf_lite'.
tfma.ModelSpec(label_key='<label_key>')
],
metrics_specs=[
tfma.MetricsSpec(
# The metrics added here are in addition to those saved with the
# model (assuming either a keras model or EvalSavedModel is used).
# Any metrics added into the saved model (for example using
# model.compile(..., metrics=[...]), etc) will be computed
# automatically.
metrics=[
tfma.MetricConfig(class_name='ExampleCount'),
tfma.MetricConfig(
class_name='BinaryAccuracy',
threshold=tfma.MetricThreshold(
value_threshold=tfma.GenericValueThreshold(
lower_bound={'value': 0.5}),
change_threshold=tfma.GenericChangeThreshold(
direction=tfma.MetricDirection.HIGHER_IS_BETTER,
absolute={'value': -1e-10})))
]
)
],
slicing_specs=[
# An empty slice spec means the overall slice, i.e. the whole dataset.
tfma.SlicingSpec(),
# Data can be sliced along a feature column. In this case, data is
# sliced along feature column trip_start_hour.
tfma.SlicingSpec(feature_keys=['trip_start_hour'])
])
# The following component is experimental and may change in the future. This is
# required to specify the latest blessed model will be used as the baseline.
model_resolver = Resolver(
strategy_class=dsl.experimental.LatestBlessedModelStrategy,
model=Channel(type=Model),
model_blessing=Channel(type=ModelBlessing)
).with_id('latest_blessed_model_resolver')
model_analyzer = Evaluator(
examples=examples_gen.outputs['examples'],
model=trainer.outputs['model'],
baseline_model=model_resolver.outputs['model'],
# Change threshold will be ignored if there is no baseline (first run).
eval_config=eval_config)
評価者は、生成EvalResult (および任意ValidationResult検証が使用された場合)を使用してロードすることができるTFMAを。以下は、結果をJupyterノートブックにロードする方法の例です。
import tensorflow_model_analysis as tfma
output_path = evaluator.outputs['evaluation'].get()[0].uri
# Load the evaluation results.
eval_result = tfma.load_eval_result(output_path)
# Visualize the metrics and plots using tfma.view.render_slicing_metrics,
# tfma.view.render_plot, etc.
tfma.view.render_slicing_metrics(tfma_result)
...
# Load the validation results
validation_result = tfma.load_validation_result(output_path)
if not validation_result.validation_ok:
...
詳細はで利用可能な評価者のAPIリファレンス。