רכיב ה-Evaluator TFX Pipeline

רכיב הצינור של Evaluator TFX מבצע ניתוח מעמיק של תוצאות האימון עבור המודלים שלך, כדי לעזור לך להבין כיצד המודל שלך מתפקד על תת-קבוצות של הנתונים שלך. ה-Evaluator גם עוזר לך לאמת את הדגמים המיוצאים שלך, ומבטיח שהם "טובים מספיק" כדי להידחף לייצור.

כאשר אימות מופעל, ה-Evaluator משווה מודלים חדשים מול קו בסיס (כגון המודל המשמש כעת) כדי לקבוע אם הם "טובים מספיק" ביחס לקו הבסיס. זה עושה זאת על ידי הערכת שני המודלים על מערך נתונים של eval ומחשוב הביצועים שלהם על מדדים (למשל AUC, הפסד). אם המדדים של המודל החדש עומדים בקריטריונים שצוינו על ידי מפתח ביחס למודל הבסיסי (למשל, AUC אינו נמוך יותר), המודל "מבורך" (מסומן כטוב), מה שמצביע על ה- Pusher שזה בסדר לדחוף את המודל לייצור.

  • צורכת:
    • פיצול eval מדוגמאות
    • דוגמנית מאומנת מבית Trainer
    • מודל מבורך בעבר (אם יש לבצע אימות)
  • פולט:
    • תוצאות ניתוח ל- ML Metadata
    • תוצאות אימות ל- ML Metadata (אם יש לבצע אימות)

מעריך וניתוח מודל TensorFlow

Evaluator ממנף את ספריית TensorFlow Model Analysis לביצוע הניתוח, אשר בתורו משתמש ב-Apache Beam לעיבוד ניתן להרחבה.

שימוש ברכיב ה-Evaluator

רכיב צינור של Evaluator הוא בדרך כלל קל מאוד לפריסה ודורש מעט התאמה אישית, מכיוון שרוב העבודה נעשית על ידי רכיב Evaluator TFX.

כדי להגדיר את המעריך יש צורך במידע הבא:

אם יש לכלול אימות, יש צורך במידע הנוסף הבא:

כאשר מופעל, יתבצע אימות מול כל המדדים והפרוסות שהוגדרו.

קוד טיפוסי נראה כך:

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:
  ...

פרטים נוספים זמינים בהפניה של Evaluator API .