ส่วนประกอบไปป์ไลน์ TFX ของผู้ประเมิน

ส่วนประกอบไปป์ไลน์ TFX ของ Evaluator ทำการวิเคราะห์เชิงลึกเกี่ยวกับผลการฝึกสำหรับโมเดลของคุณ เพื่อช่วยให้คุณเข้าใจว่าโมเดลของคุณทำงานอย่างไรกับชุดย่อยของข้อมูลของคุณ Service Checker ยังช่วยให้คุณตรวจสอบแบบจำลองที่คุณส่งออก เพื่อให้แน่ใจว่าโมเดลเหล่านั้น "ดีเพียงพอ" ที่จะผลักดันไปสู่การใช้งานจริง

เมื่อเปิดใช้งานการตรวจสอบความถูกต้อง ผู้ประเมินจะเปรียบเทียบโมเดลใหม่กับพื้นฐาน (เช่น โมเดลที่ให้บริการในปัจจุบัน) เพื่อพิจารณาว่าโมเดลเหล่านั้น "ดีเพียงพอ" เมื่อเทียบกับพื้นฐานหรือไม่ ทำได้โดยการประเมินทั้งสองโมเดลบนชุดข้อมูล eval และคำนวณประสิทธิภาพบนหน่วยเมตริก (เช่น AUC, การสูญเสีย) หากตัววัดของโมเดลใหม่ตรงตามเกณฑ์ที่นักพัฒนากำหนดโดยสัมพันธ์กับโมเดลพื้นฐาน (เช่น AUC ไม่ต่ำกว่า) โมเดลดังกล่าวจะ "ได้รับพร" (ทำเครื่องหมายว่าดี) บ่งบอกให้ Pusher ทราบว่าสามารถผลักดันโมเดลไปสู่การใช้งานจริงได้

  • สิ้นเปลือง:
    • การแยกประเมินจาก ตัวอย่าง
    • โมเดลที่ผ่านการฝึกอบรมจาก เทรนเนอร์
    • แบบจำลองที่ได้รับพรก่อนหน้านี้ (หากต้องดำเนินการตรวจสอบความถูกต้อง)
  • ปล่อยเสียง:
    • ผลการวิเคราะห์ไปยัง ML Metadata
    • ผลการตรวจสอบความถูกต้องของ ML Metadata (หากจะดำเนินการตรวจสอบความถูกต้อง)

การวิเคราะห์แบบจำลองผู้ประเมินและ TensorFlow

Evaluator ใช้ประโยชน์จากไลบรารี การวิเคราะห์โมเดล TensorFlow เพื่อทำการวิเคราะห์ ซึ่งในทางกลับกันจะใช้ Apache Beam สำหรับการประมวลผลที่ปรับขนาดได้

การใช้ส่วนประกอบผู้ประเมิน

โดยทั่วไปส่วนประกอบไปป์ไลน์ของ Evaluator นั้นง่ายต่อการปรับใช้และต้องการการปรับแต่งเพียงเล็กน้อย เนื่องจากงานส่วนใหญ่เสร็จสิ้นโดยส่วนประกอบ TFX ของ Evaluator

ในการตั้งค่าผู้ประเมิน จำเป็นต้องมีข้อมูลต่อไปนี้:

หากต้องการรวมการตรวจสอบความถูกต้อง จำเป็นต้องมีข้อมูลเพิ่มเติมต่อไปนี้:

เมื่อเปิดใช้งาน การตรวจสอบจะดำเนินการกับหน่วยวัดและส่วนทั้งหมดที่กำหนดไว้

รหัสทั่วไปมีลักษณะดังนี้:

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