บทนำ
เอกสารนี้จะให้คำแนะนำในการสร้างไปป์ไลน์ TensorFlow Extended (TFX) สำหรับชุดข้อมูลของคุณเองโดยใช้ เทมเพลตเพนกวิน ซึ่งมาพร้อมกับแพ็คเกจ TFX Python ไปป์ไลน์ที่สร้างขึ้นจะใช้ชุดข้อมูล Palmer Penguins ในขั้นต้น แต่เราจะแปลงไปป์ไลน์สำหรับชุดข้อมูลของคุณ
ข้อกำหนดเบื้องต้น
- Linux / MacOS
- หลาม 3.6-3.8
- โน๊ตบุ๊ค Jupyter
ขั้นตอนที่ 1 คัดลอกเทมเพลตที่กำหนดไว้ล่วงหน้าไปยังไดเร็กทอรีโครงการของคุณ
ในขั้นตอนนี้ เราจะสร้างไดเร็กทอรีและไฟล์โปรเจ็กต์ไปป์ไลน์ที่ใช้งานได้ โดยการคัดลอกไฟล์จาก เทมเพลตเพนกวิน ใน TFX คุณสามารถคิดว่านี่เป็นโครงสำหรับโครงการไปป์ไลน์ TFX ของคุณ
อัพเดท Pip
หากเราใช้งาน Colab เราควรตรวจสอบให้แน่ใจว่าเรามี Pip เวอร์ชันล่าสุด ระบบท้องถิ่นสามารถอัปเดตแยกต่างหากได้
import sys
if 'google.colab' in sys.modules:
!pip install --upgrade pip
ติดตั้งแพ็คเกจที่จำเป็น
ขั้นแรก ติดตั้ง TFX และ TensorFlow Model Analysis (TFMA)
pip install -U tfx tensorflow-model-analysis
มาดูเวอร์ชันของ TFX กัน
import tensorflow as tf
import tensorflow_model_analysis as tfma
import tfx
print('TF version: {}'.format(tf.__version__))
print('TFMA version: {}'.format(tfma.__version__))
print('TFX version: {}'.format(tfx.__version__))
TF version: 2.7.1 TFMA version: 0.37.0 TFX version: 1.6.0
เราพร้อมที่จะสร้างไปป์ไลน์
ตั้งค่า PROJECT_DIR เป็นปลายทางที่เหมาะสมสำหรับสภาพแวดล้อมของคุณ ค่าเริ่มต้นคือ ~/imported/${PIPELINE_NAME} ซึ่งเหมาะสำหรับสภาพแวดล้อม โน้ตบุ๊ก Google Cloud AI Platform
คุณสามารถตั้งชื่อไปป์ไลน์ของคุณโดยเปลี่ยน PIPELINE_NAME ด้านล่าง นี่จะกลายเป็นชื่อของไดเร็กทอรีโครงการที่จะใส่ไฟล์ของคุณ
PIPELINE_NAME="my_pipeline"
import os
# Set this project directory to your new tfx pipeline project.
PROJECT_DIR=os.path.join(os.path.expanduser("~"), "imported", PIPELINE_NAME)
คัดลอกไฟล์เทมเพลต
TFX มีเทมเพลต penguin พร้อมแพ็คเกจ TFX python เทมเพลต penguin มีคำแนะนำมากมายในการนำชุดข้อมูลของคุณไปยังไปป์ไลน์ ซึ่งเป็นจุดประสงค์ของบทช่วยสอนนี้
คำสั่ง CLI tfx template copy ไฟล์เทมเพลตที่กำหนดไว้ล่วงหน้าลงในไดเร็กทอรีโครงการของคุณ
# Set `PATH` to include user python binary directory and a directory containing `skaffold`.
PATH=%env PATH
%env PATH={PATH}:/home/jupyter/.local/bin
!tfx template copy \
--pipeline-name={PIPELINE_NAME} \
--destination-path={PROJECT_DIR} \
--model=penguin
env: PATH=/tmpfs/src/tf_docs_env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/opt/puppetlabs/bin:/opt/android-studio/current/bin:/usr/local/go/bin:/usr/local/go/packages/bin:/opt/kubernetes/client/bin/:/home/kbuilder/.local/bin:/home/jupyter/.local/bin CLI Copying penguin pipeline template kubeflow_runner.py -> /home/kbuilder/imported/my_pipeline/kubeflow_runner.py configs.py -> /home/kbuilder/imported/my_pipeline/pipeline/configs.py pipeline.py -> /home/kbuilder/imported/my_pipeline/pipeline/pipeline.py __init__.py -> /home/kbuilder/imported/my_pipeline/pipeline/__init__.py model.py -> /home/kbuilder/imported/my_pipeline/models/model.py features.py -> /home/kbuilder/imported/my_pipeline/models/features.py features_test.py -> /home/kbuilder/imported/my_pipeline/models/features_test.py preprocessing_test.py -> /home/kbuilder/imported/my_pipeline/models/preprocessing_test.py preprocessing.py -> /home/kbuilder/imported/my_pipeline/models/preprocessing.py model_test.py -> /home/kbuilder/imported/my_pipeline/models/model_test.py __init__.py -> /home/kbuilder/imported/my_pipeline/models/__init__.py constants.py -> /home/kbuilder/imported/my_pipeline/models/constants.py local_runner.py -> /home/kbuilder/imported/my_pipeline/local_runner.py __init__.py -> /home/kbuilder/imported/my_pipeline/__init__.py
เปลี่ยนบริบทไดเรกทอรีทำงานในสมุดบันทึกนี้เป็นไดเรกทอรีโครงการ
%cd {PROJECT_DIR}
/home/kbuilder/imported/my_pipeline
เรียกดูไฟล์ต้นฉบับที่คัดลอกของคุณ
เทมเพลต TFX มีไฟล์โครงพื้นฐานสำหรับสร้างไปป์ไลน์ ซึ่งรวมถึงซอร์สโค้ด Python และข้อมูลตัวอย่าง เทมเพลต penguin ใช้ชุดข้อมูล Palmer Penguins และโมเดล ML เดียวกันกับ ตัวอย่าง Penguin
ต่อไปนี้คือข้อมูลเบื้องต้นเกี่ยวกับไฟล์ Python แต่ละไฟล์
-
pipeline- ไดเร็กทอรีนี้มีคำจำกัดความของไปป์ไลน์-
configs.py— กำหนดค่าคงที่ทั่วไปสำหรับไพพ์ไลน์รันเนอร์ -
pipeline.py— กำหนดส่วนประกอบ TFX และไปป์ไลน์
-
-
models- ไดเร็กทอรีนี้มีคำจำกัดความโมเดล ML-
features.py,features_test.py— กำหนดคุณสมบัติสำหรับ model -
preprocessing.py,preprocessing_test.py— กำหนดรูทีนการประมวลผลล่วงหน้าสำหรับ data -
constants.py— กำหนดค่าคงที่ของ model -
model.py,model_test.py— กำหนดโมเดล ML โดยใช้เฟรมเวิร์ก ML เช่น TensorFlow
-
-
local_runner.py— กำหนดตัววิ่งสำหรับสภาพแวดล้อมในพื้นที่ซึ่งใช้เอ็นจิ้นการประสานในเครื่อง -
kubeflow_runner.py— กำหนดตัววิ่งสำหรับกลไกจัดการ Kubeflow Pipelines
ตามค่าเริ่มต้น เทมเพลตจะรวมเฉพาะส่วนประกอบ TFX มาตรฐานเท่านั้น หากคุณต้องการการดำเนินการที่กำหนดเอง คุณสามารถสร้างส่วนประกอบที่กำหนดเองสำหรับไปป์ไลน์ของคุณได้ โปรดดู คู่มือส่วนประกอบที่กำหนดเองของ TFX สำหรับรายละเอียด
ไฟล์ทดสอบหน่วย
คุณอาจสังเกตเห็นว่ามีบางไฟล์ที่มี _test.py ในชื่อ นี่คือการทดสอบหน่วยของไปป์ไลน์ และขอแนะนำให้เพิ่มการทดสอบหน่วยเพิ่มเติมเมื่อคุณใช้ไพพ์ไลน์ของคุณเอง คุณสามารถรันการทดสอบหน่วยโดยระบุชื่อโมดูลของไฟล์ทดสอบด้วยแฟล็ก -m คุณสามารถรับชื่อโมดูลได้โดยการลบนามสกุล . .py และแทนที่ / ด้วย . . ตัวอย่างเช่น:
import sys
!{sys.executable} -m models.features_test
Running tests under Python 3.7.5: /tmpfs/src/tf_docs_env/bin/python [ RUN ] FeaturesTest.testLabelKey INFO:tensorflow:time(__main__.FeaturesTest.testLabelKey): 0.0s I0203 11:08:46.306882 140258321348416 test_util.py:2309] time(__main__.FeaturesTest.testLabelKey): 0.0s [ OK ] FeaturesTest.testLabelKey [ RUN ] FeaturesTest.test_session [ SKIPPED ] FeaturesTest.test_session ---------------------------------------------------------------------- Ran 2 tests in 0.001s OK (skipped=1)
สร้างไปป์ไลน์ TFX ในสภาพแวดล้อมท้องถิ่น
TFX รองรับเอ็นจิ้นการประสานหลายตัวเพื่อรันไปป์ไลน์ เราจะใช้เครื่องมือประสานท้องถิ่น Local orchestration engine ทำงานโดยไม่มีการพึ่งพาใด ๆ เพิ่มเติม และเหมาะสำหรับการพัฒนาและการดีบักเนื่องจากทำงานบนสภาพแวดล้อมภายในเครื่อง แทนที่จะขึ้นอยู่กับคลัสเตอร์การประมวลผลระยะไกล
เราจะใช้ local_runner.py เพื่อเรียกใช้ไปป์ไลน์ของคุณโดยใช้ออร์เคสตราในพื้นที่ คุณต้องสร้างไปป์ไลน์ก่อนที่จะเรียกใช้ คุณสามารถสร้างไปป์ไลน์ด้วยคำสั่ง pipeline create
tfx pipeline create --engine=local --pipeline_path=local_runner.py
CLI Creating pipeline INFO:absl:Excluding no splits because exclude_splits is not set. INFO:absl:Excluding no splits because exclude_splits is not set. Pipeline "my_pipeline" created successfully.
คำสั่งไพพ์ pipeline create ลงทะเบียนไพพ์ไลน์ของคุณที่กำหนดไว้ใน local_runner.py โดยไม่ต้องรันมันจริงๆ
คุณจะเรียกใช้ไปป์ไลน์ที่สร้างขึ้นด้วยคำสั่ง run create ในขั้นตอนต่อไปนี้
ขั้นตอนที่ 2 นำเข้าข้อมูลของคุณไปยังไปป์ไลน์
ไปป์ไลน์เริ่มต้นนำเข้าชุดข้อมูลเพนกวินซึ่งรวมอยู่ในเทมเพลต คุณต้องใส่ข้อมูลของคุณลงในไปป์ไลน์ และไปป์ไลน์ TFX ส่วนใหญ่เริ่มต้นด้วยส่วนประกอบ ExampleGen
เลือกตัวอย่างGen
ข้อมูลของคุณสามารถจัดเก็บได้ทุกที่ที่ไปป์ไลน์ของคุณสามารถเข้าถึงได้ ทั้งบนระบบไฟล์ในเครื่องหรือแบบกระจาย หรือระบบที่สามารถสืบค้นได้ TFX มี ส่วนประกอบ ExampleGen ต่างๆ เพื่อนำข้อมูลของคุณเข้าสู่ไปป์ไลน์ TFX คุณสามารถเลือกหนึ่งรายการจากตัวอย่างการสร้างส่วนประกอบต่อไปนี้
- CsvExampleGen: อ่านไฟล์ CSV ในไดเร็กทอรี ใช้ใน ตัวอย่างนกเพนกวินและตัวอย่าง รถแท็กซี่ชิคาโก
- ImportExampleGen: นำไฟล์ TFRecord ที่มีรูปแบบข้อมูล TF Example ใช้ใน ตัวอย่าง MNIST
- FileBasedExampleGen สำหรับรูปแบบ Avro หรือ Parquet
- BigQueryExampleGen : อ่านข้อมูลใน Google Cloud BigQuery โดยตรง ใช้ใน ตัวอย่างรถแท็กซี่ชิคาโก
คุณยังสามารถสร้าง ExampleGen ของคุณเองได้ ตัวอย่างเช่น tfx มี ExecampleGen แบบกำหนดเองซึ่งใช้ Presto เป็นแหล่งข้อมูล ดู คำแนะนำ สำหรับข้อมูลเพิ่มเติมเกี่ยวกับวิธีใช้และพัฒนาตัวดำเนินการแบบกำหนดเอง
เมื่อคุณตัดสินใจว่าจะใช้ ExampleGen คุณจะต้องแก้ไขข้อกำหนดไปป์ไลน์เพื่อใช้ข้อมูลของคุณ
แก้ไข
DATA_PATHในlocal_runner.pyและตั้งค่าเป็นตำแหน่งของไฟล์ของคุณ- หากคุณมีไฟล์ในสภาพแวดล้อมท้องถิ่น ให้ระบุพาธ นี่เป็นตัวเลือกที่ดีที่สุดสำหรับการพัฒนาหรือการดีบักไปป์ไลน์
- หากไฟล์ถูกจัดเก็บไว้ใน GCS คุณสามารถใช้พาธที่ขึ้นต้นด้วย
gs://{bucket_name}/...โปรดตรวจสอบว่าคุณสามารถเข้าถึง GCS จากเทอร์มินัลได้ เช่น ใช้gsutilโปรดปฏิบัติตาม คู่มือการให้สิทธิ์ใน Google Cloud หากจำเป็น - หากคุณต้องการใช้ ExampleGen แบบ Query เช่น BigQueryExampleGen คุณต้องมีคำสั่ง Query เพื่อเลือกข้อมูลจากแหล่งข้อมูล มีอีกสองสามสิ่งที่คุณต้องตั้งค่าเพื่อใช้ Google Cloud BigQuery เป็นแหล่งข้อมูล
- ใน
pipeline/configs.py:- เปลี่ยน
GOOGLE_CLOUD_PROJECTและGCS_BUCKET_NAMEเป็นโปรเจ็กต์ GCP และชื่อที่เก็บข้อมูลของคุณ ที่ฝากข้อมูลควรมีอยู่ก่อนที่เราจะเรียกใช้ไปป์ไลน์ -
BIG_QUERY_WITH_DIRECT_RUNNER_BEAM_PIPELINE_ARGSตัวแปร - ยกเลิกการใส่ความคิดเห็นและตั้งค่าตัวแปร
BIG_QUERY_QUERYเป็น คำสั่งการสืบค้นของคุณ
- เปลี่ยน
- ใน
local_runner.py:- แสดงความคิดเห็น
data_pathอาร์กิวเมนต์และ uncomment อาร์กิวเมนต์queryแทนในไพพ์ไลน์.create_pipelinepipeline.create_pipeline()
- แสดงความคิดเห็น
- ใน
pipeline/pipeline.py:- ใส่ความคิดเห็น
data_pathอาร์กิวเมนต์และ uncommentqueryอาร์กิวเมนต์ในcreate_pipeline() - ใช้ BigQueryExampleGen แทน CsvExampleGen
- ใส่ความคิดเห็น
แทนที่ CsvExampleGen ที่มีอยู่เป็นคลาส ExampleGen ของคุณใน
pipeline/pipeline.py/pipeline.py คลาส ExampleGen แต่ละคลาสมีลายเซ็นที่แตกต่างกัน โปรดดู คู่มือส่วนประกอบ ExampleGen สำหรับรายละเอียดเพิ่มเติม อย่าลืมนำเข้าโมดูลที่จำเป็นด้วยคำสั่งimportในpipeline/pipeline.py.py
ไปป์ไลน์เริ่มต้นประกอบด้วยสี่องค์ประกอบ ExampleGen , StatisticsGen , SchemaGen และ ExampleValidator เราไม่จำเป็นต้องเปลี่ยนแปลงใดๆ สำหรับ StatisticsGen , SchemaGen และ ExampleValidator มาทำไพพ์ไลน์กันครั้งแรกกันเถอะ
# Update and run the pipeline.
!tfx pipeline update --engine=local --pipeline_path=local_runner.py \
&& tfx run create --engine=local --pipeline_name={PIPELINE_NAME}
CLI
Updating pipeline
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Excluding no splits because exclude_splits is not set.
Pipeline "my_pipeline" updated successfully.
CLI
Creating a run for pipeline: my_pipeline
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Using deployment config:
executor_specs {
key: "CsvExampleGen"
value {
beam_executable_spec {
python_executor_spec {
class_path: "tfx.components.example_gen.csv_example_gen.executor.Executor"
}
}
}
}
executor_specs {
key: "SchemaGen"
value {
python_class_executable_spec {
class_path: "tfx.components.schema_gen.executor.Executor"
}
}
}
executor_specs {
key: "StatisticsGen"
value {
beam_executable_spec {
python_executor_spec {
class_path: "tfx.components.statistics_gen.executor.Executor"
}
}
}
}
custom_driver_specs {
key: "CsvExampleGen"
value {
python_class_executable_spec {
class_path: "tfx.components.example_gen.driver.FileBasedDriver"
}
}
}
metadata_connection_config {
database_connection_config {
sqlite {
filename_uri: "./tfx_metadata/my_pipeline/metadata.db"
connection_mode: READWRITE_OPENCREATE
}
}
}
INFO:absl:Using connection config:
sqlite {
filename_uri: "./tfx_metadata/my_pipeline/metadata.db"
connection_mode: READWRITE_OPENCREATE
}
INFO:absl:Component CsvExampleGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.example_gen.csv_example_gen.component.CsvExampleGen"
}
id: "CsvExampleGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:12.120566"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
}
outputs {
outputs {
key: "examples"
value {
artifact_spec {
type {
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
}
}
}
}
}
parameters {
parameters {
key: "input_base"
value {
field_value {
string_value: "/home/kbuilder/imported/my_pipeline/data"
}
}
}
parameters {
key: "input_config"
value {
field_value {
string_value: "{\n \"splits\": [\n {\n \"name\": \"single_split\",\n \"pattern\": \"*\"\n }\n ]\n}"
}
}
}
parameters {
key: "output_config"
value {
field_value {
string_value: "{\n \"split_config\": {\n \"splits\": [\n {\n \"hash_buckets\": 2,\n \"name\": \"train\"\n },\n {\n \"hash_buckets\": 1,\n \"name\": \"eval\"\n }\n ]\n }\n}"
}
}
}
parameters {
key: "output_data_format"
value {
field_value {
int_value: 6
}
}
}
parameters {
key: "output_file_format"
value {
field_value {
int_value: 5
}
}
}
}
downstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:select span and version = (0, None)
INFO:absl:latest span and version = (0, None)
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 1
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=1, input_dict={}, output_dict=defaultdict(<class 'list'>, {'examples': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/1"
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:12.120566:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
, artifact_type: name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}), exec_properties={'input_config': '{\n "splits": [\n {\n "name": "single_split",\n "pattern": "*"\n }\n ]\n}', 'output_data_format': 6, 'output_file_format': 5, 'output_config': '{\n "split_config": {\n "splits": [\n {\n "hash_buckets": 2,\n "name": "train"\n },\n {\n "hash_buckets": 1,\n "name": "eval"\n }\n ]\n }\n}', 'input_base': '/home/kbuilder/imported/my_pipeline/data', 'span': 0, 'version': None, 'input_fingerprint': 'split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522'}, execution_output_uri='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/executor_execution/1/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/stateful_working_dir/2022-02-03T11:09:12.120566', tmp_dir='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/executor_execution/1/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.example_gen.csv_example_gen.component.CsvExampleGen"
}
id: "CsvExampleGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:12.120566"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
}
outputs {
outputs {
key: "examples"
value {
artifact_spec {
type {
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
}
}
}
}
}
parameters {
parameters {
key: "input_base"
value {
field_value {
string_value: "/home/kbuilder/imported/my_pipeline/data"
}
}
}
parameters {
key: "input_config"
value {
field_value {
string_value: "{\n \"splits\": [\n {\n \"name\": \"single_split\",\n \"pattern\": \"*\"\n }\n ]\n}"
}
}
}
parameters {
key: "output_config"
value {
field_value {
string_value: "{\n \"split_config\": {\n \"splits\": [\n {\n \"hash_buckets\": 2,\n \"name\": \"train\"\n },\n {\n \"hash_buckets\": 1,\n \"name\": \"eval\"\n }\n ]\n }\n}"
}
}
}
parameters {
key: "output_data_format"
value {
field_value {
int_value: 6
}
}
}
parameters {
key: "output_file_format"
value {
field_value {
int_value: 5
}
}
}
}
downstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:09:12.120566')
INFO:absl:Generating examples.
INFO:absl:Processing input csv data /home/kbuilder/imported/my_pipeline/data/* to TFExample.
WARNING:root:Make sure that locally built Python SDK docker image has Python 3.7 interpreter.
E0203 11:09:12.848598153 5127 fork_posix.cc:70] Fork support is only compatible with the epoll1 and poll polling strategies
WARNING:apache_beam.io.tfrecordio:Couldn't find python-snappy so the implementation of _TFRecordUtil._masked_crc32c is not as fast as it could be.
INFO:absl:Examples generated.
INFO:absl:Value type <class 'NoneType'> of key version in exec_properties is not supported, going to drop it
INFO:absl:Value type <class 'list'> of key _beam_pipeline_args in exec_properties is not supported, going to drop it
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 1 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'examples': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/1"
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:12.120566:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}) for execution 1
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component CsvExampleGen is finished.
INFO:absl:Component StatisticsGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.statistics_gen.component.StatisticsGen"
base_type: PROCESS
}
id: "StatisticsGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:12.120566"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
}
inputs {
inputs {
key: "examples"
value {
channels {
producer_node_query {
id: "CsvExampleGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:12.120566"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
artifact_query {
type {
name: "Examples"
base_type: DATASET
}
}
output_key: "examples"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "statistics"
value {
artifact_spec {
type {
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
}
upstream_nodes: "CsvExampleGen"
downstream_nodes: "SchemaGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 2
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=2, input_dict={'examples': [Artifact(artifact: id: 1
type_id: 15
uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/1"
properties {
key: "split_names"
value {
string_value: "[\"train\", \"eval\"]"
}
}
custom_properties {
key: "file_format"
value {
string_value: "tfrecords_gzip"
}
}
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:12.120566:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "payload_format"
value {
string_value: "FORMAT_TF_EXAMPLE"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
state: LIVE
create_time_since_epoch: 1643886553302
last_update_time_since_epoch: 1643886553302
, artifact_type: id: 15
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}, output_dict=defaultdict(<class 'list'>, {'statistics': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/2"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:12.120566:StatisticsGen:statistics:0"
}
}
, artifact_type: name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}), exec_properties={'exclude_splits': '[]'}, execution_output_uri='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/executor_execution/2/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/stateful_working_dir/2022-02-03T11:09:12.120566', tmp_dir='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/executor_execution/2/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.statistics_gen.component.StatisticsGen"
base_type: PROCESS
}
id: "StatisticsGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:12.120566"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
}
inputs {
inputs {
key: "examples"
value {
channels {
producer_node_query {
id: "CsvExampleGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:12.120566"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
artifact_query {
type {
name: "Examples"
base_type: DATASET
}
}
output_key: "examples"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "statistics"
value {
artifact_spec {
type {
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
}
upstream_nodes: "CsvExampleGen"
downstream_nodes: "SchemaGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:09:12.120566')
INFO:absl:Generating statistics for split train.
INFO:absl:Statistics for split train written to ./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/2/Split-train.
INFO:absl:Generating statistics for split eval.
INFO:absl:Statistics for split eval written to ./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/2/Split-eval.
WARNING:root:Make sure that locally built Python SDK docker image has Python 3.7 interpreter.
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 2 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'statistics': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/2"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:12.120566:StatisticsGen:statistics:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}) for execution 2
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component StatisticsGen is finished.
INFO:absl:Component SchemaGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.schema_gen.component.SchemaGen"
base_type: PROCESS
}
id: "SchemaGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:12.120566"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.SchemaGen"
}
}
}
}
inputs {
inputs {
key: "statistics"
value {
channels {
producer_node_query {
id: "StatisticsGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:12.120566"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
artifact_query {
type {
name: "ExampleStatistics"
base_type: STATISTICS
}
}
output_key: "statistics"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "schema"
value {
artifact_spec {
type {
name: "Schema"
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
parameters {
key: "infer_feature_shape"
value {
field_value {
int_value: 1
}
}
}
}
upstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 3
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=3, input_dict={'statistics': [Artifact(artifact: id: 2
type_id: 17
uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/2"
properties {
key: "split_names"
value {
string_value: "[\"train\", \"eval\"]"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:12.120566:StatisticsGen:statistics:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
state: LIVE
create_time_since_epoch: 1643886556588
last_update_time_since_epoch: 1643886556588
, artifact_type: id: 17
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}, output_dict=defaultdict(<class 'list'>, {'schema': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/SchemaGen/schema/3"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:12.120566:SchemaGen:schema:0"
}
}
, artifact_type: name: "Schema"
)]}), exec_properties={'infer_feature_shape': 1, 'exclude_splits': '[]'}, execution_output_uri='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/executor_execution/3/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/stateful_working_dir/2022-02-03T11:09:12.120566', tmp_dir='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/executor_execution/3/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.schema_gen.component.SchemaGen"
base_type: PROCESS
}
id: "SchemaGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:12.120566"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.SchemaGen"
}
}
}
}
inputs {
inputs {
key: "statistics"
value {
channels {
producer_node_query {
id: "StatisticsGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:12.120566"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
artifact_query {
type {
name: "ExampleStatistics"
base_type: STATISTICS
}
}
output_key: "statistics"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "schema"
value {
artifact_spec {
type {
name: "Schema"
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
parameters {
key: "infer_feature_shape"
value {
field_value {
int_value: 1
}
}
}
}
upstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:09:12.120566')
INFO:absl:Processing schema from statistics for split train.
INFO:absl:Processing schema from statistics for split eval.
INFO:absl:Schema written to ./tfx_pipeline_output/my_pipeline/SchemaGen/schema/3/schema.pbtxt.
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 3 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'schema': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/SchemaGen/schema/3"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:12.120566:SchemaGen:schema:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "Schema"
)]}) for execution 3
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component SchemaGen is finished.
คุณควรเห็น "ตัวอย่างคอมโพเนนต์Validator เสร็จสิ้น" ถ้าไปป์ไลน์ทำงานสำเร็จ
ตรวจสอบเอาต์พุตของไปป์ไลน์
ไปป์ไลน์ TFX สร้างเอาต์พุตสองประเภท สิ่งประดิษฐ์ และ DB (MLMD) ข้อมูลเมตาซึ่งมีข้อมูลเมตาของสิ่งประดิษฐ์และการดำเนินการไปป์ไลน์ ตำแหน่งไปยังเอาต์พุตถูกกำหนดใน local_runner.py โดยค่าเริ่มต้น สิ่งประดิษฐ์จะถูกเก็บไว้ภายใต้ไดเร็กทอรี tfx_pipeline_output และข้อมูลเมตาจะถูกจัดเก็บเป็นฐานข้อมูล sqlite ภายใต้ไดเร็กทอรี tfx_metadata
คุณสามารถใช้ MLMD API เพื่อตรวจสอบผลลัพธ์เหล่านี้ ขั้นแรก เราจะกำหนดฟังก์ชันยูทิลิตี้บางอย่างเพื่อค้นหาอาร์ติแฟกต์เอาต์พุตที่เพิ่งสร้างขึ้น
import tensorflow as tf
import tfx
from ml_metadata import errors
from ml_metadata.proto import metadata_store_pb2
from tfx.types import artifact_utils
# TODO(b/171447278): Move these functions into TFX library.
def get_latest_executions(store, pipeline_name, component_id = None):
"""Fetch all pipeline runs."""
if component_id is None: # Find entire pipeline runs.
run_contexts = [
c for c in store.get_contexts_by_type('run')
if c.properties['pipeline_name'].string_value == pipeline_name
]
else: # Find specific component runs.
run_contexts = [
c for c in store.get_contexts_by_type('component_run')
if c.properties['pipeline_name'].string_value == pipeline_name and
c.properties['component_id'].string_value == component_id
]
if not run_contexts:
return []
# Pick the latest run context.
latest_context = max(run_contexts,
key=lambda c: c.last_update_time_since_epoch)
return store.get_executions_by_context(latest_context.id)
def get_latest_artifacts(store, pipeline_name, component_id = None):
"""Fetch all artifacts from latest pipeline execution."""
executions = get_latest_executions(store, pipeline_name, component_id)
# Fetch all artifacts produced from the given executions.
execution_ids = [e.id for e in executions]
events = store.get_events_by_execution_ids(execution_ids)
artifact_ids = [
event.artifact_id for event in events
if event.type == metadata_store_pb2.Event.OUTPUT
]
return store.get_artifacts_by_id(artifact_ids)
def find_latest_artifacts_by_type(store, artifacts, artifact_type):
"""Get the latest artifacts of a specified type."""
# Get type information from MLMD
try:
artifact_type = store.get_artifact_type(artifact_type)
except errors.NotFoundError:
return []
# Filter artifacts with type.
filtered_artifacts = [aritfact for aritfact in artifacts
if aritfact.type_id == artifact_type.id]
# Convert MLMD artifact data into TFX Artifact instances.
return [artifact_utils.deserialize_artifact(artifact_type, artifact)
for artifact in filtered_artifacts]
from tfx.orchestration.experimental.interactive import visualizations
def visualize_artifacts(artifacts):
"""Visualizes artifacts using standard visualization modules."""
for artifact in artifacts:
visualization = visualizations.get_registry().get_visualization(
artifact.type_name)
if visualization:
visualization.display(artifact)
from tfx.orchestration.experimental.interactive import standard_visualizations
standard_visualizations.register_standard_visualizations()
import pprint
from tfx.orchestration import metadata
from tfx.types import artifact_utils
from tfx.types import standard_artifacts
def preview_examples(artifacts):
"""Preview a few records from Examples artifacts."""
pp = pprint.PrettyPrinter()
for artifact in artifacts:
print("==== Examples artifact:{}({})".format(artifact.name, artifact.uri))
for split in artifact_utils.decode_split_names(artifact.split_names):
print("==== Reading from split:{}".format(split))
split_uri = artifact_utils.get_split_uri([artifact], split)
# Get the list of files in this directory (all compressed TFRecord files)
tfrecord_filenames = [os.path.join(split_uri, name)
for name in os.listdir(split_uri)]
# Create a `TFRecordDataset` to read these files
dataset = tf.data.TFRecordDataset(tfrecord_filenames,
compression_type="GZIP")
# Iterate over the first 2 records and decode them.
for tfrecord in dataset.take(2):
serialized_example = tfrecord.numpy()
example = tf.train.Example()
example.ParseFromString(serialized_example)
pp.pprint(example)
import local_runner
metadata_connection_config = metadata.sqlite_metadata_connection_config(
local_runner.METADATA_PATH)
ตอนนี้ เราสามารถอ่านข้อมูลเมตาของสิ่งประดิษฐ์เอาท์พุตจาก MLMD ได้แล้ว
with metadata.Metadata(metadata_connection_config) as metadata_handler:
# Search all aritfacts from the previous pipeline run.
artifacts = get_latest_artifacts(metadata_handler.store, PIPELINE_NAME)
# Find artifacts of Examples type.
examples_artifacts = find_latest_artifacts_by_type(
metadata_handler.store, artifacts,
standard_artifacts.Examples.TYPE_NAME)
# Find artifacts generated from StatisticsGen.
stats_artifacts = find_latest_artifacts_by_type(
metadata_handler.store, artifacts,
standard_artifacts.ExampleStatistics.TYPE_NAME)
# Find artifacts generated from SchemaGen.
schema_artifacts = find_latest_artifacts_by_type(
metadata_handler.store, artifacts,
standard_artifacts.Schema.TYPE_NAME)
# Find artifacts generated from ExampleValidator.
anomalies_artifacts = find_latest_artifacts_by_type(
metadata_handler.store, artifacts,
standard_artifacts.ExampleAnomalies.TYPE_NAME)
ตอนนี้เราสามารถตรวจสอบผลลัพธ์จากแต่ละองค์ประกอบได้ การตรวจสอบความถูกต้องของข้อมูล Tensorflow (TFDV) ใช้ใน StatisticsGen , SchemaGen และ ExampleValidator และ TFDV สามารถใช้เพื่อแสดงเอาต์พุตจากส่วนประกอบเหล่านี้
ในบทช่วยสอนนี้ เราจะใช้เมธอดตัวช่วยการสร้างภาพใน TFX ซึ่งใช้ TFDV ภายในเพื่อแสดงการสร้างภาพ โปรดดูบทช่วย สอนเกี่ยวกับส่วนประกอบ TFX เพื่อเรียนรู้เพิ่มเติมเกี่ยวกับแต่ละองค์ประกอบ
ตรวจสอบแบบฟอร์มผลลัพธ์ ExampleGen
มาตรวจสอบผลลัพธ์จาก ExampleGen ดูตัวอย่างสองตัวอย่างแรกสำหรับการแยกแต่ละส่วน:
preview_examples(examples_artifacts)
โดยค่าเริ่มต้น TFX ExampleGen จะแบ่งตัวอย่างออกเป็นสองส่วน คือ เทรน และ eval แต่คุณสามารถ ปรับเปลี่ยนการกำหนดค่าแบบแยก ได้
ตรวจสอบผลลัพธ์จาก StatisticsGen
visualize_artifacts(stats_artifacts)
สถิติเหล่านี้ส่งให้กับ SchemaGen เพื่อสร้างสคีมาของข้อมูลโดยอัตโนมัติ
ตรวจสอบผลลัพธ์จาก SchemaGen
visualize_artifacts(schema_artifacts)
สคีมานี้อนุมานโดยอัตโนมัติจากผลลัพธ์ของ StatisticsGen เราจะใช้สคีมาที่สร้างขึ้นนี้ในบทช่วยสอนนี้ แต่คุณยังสามารถ แก้ไขและปรับแต่งสคีมา ได้อีกด้วย
ตรวจสอบผลลัพธ์จาก ExampleValidator
visualize_artifacts(anomalies_artifacts)
หากพบความผิดปกติ คุณอาจตรวจทานข้อมูลว่าตัวอย่างทั้งหมดเป็นไปตามสมมติฐานของคุณ เอาต์พุตจากส่วนประกอบอื่นๆ เช่น StatistcsGen อาจมีประโยชน์ พบความผิดปกติไม่ปิดกั้นการดำเนินการไปป์ไลน์
คุณสามารถดูคุณสมบัติที่มีได้จากผลลัพธ์ของ SchemaGen หากฟีเจอร์ของคุณใช้สร้างโมเดล ML ใน Trainer ได้โดยตรง ให้ข้ามขั้นตอนถัดไปและไปที่ขั้นตอนที่ 4 ไม่เช่นนั้น คุณจะทำงานด้านวิศวกรรมฟีเจอร์ได้ในขั้นตอนถัดไป ส่วนประกอบ Transform เป็นสิ่งจำเป็นเมื่อจำเป็นต้องมีการดำเนินการเต็มอัตรา เช่น การคำนวณค่าเฉลี่ย โดยเฉพาะอย่างยิ่งเมื่อคุณต้องการปรับขนาด
ขั้นตอนที่ 3 (ไม่บังคับ) วิศวกรรมคุณลักษณะพร้อมองค์ประกอบ Transform
ในขั้นตอนนี้ คุณจะกำหนดงานวิศวกรรมคุณลักษณะต่างๆ ที่จะใช้โดยคอมโพเนนต์ Transform ในไปป์ไลน์ ดูข้อมูลเพิ่มเติมใน คู่มือองค์ประกอบการแปลง
สิ่งนี้จำเป็นก็ต่อเมื่อโค้ดการฝึกอบรมของคุณต้องการคุณสมบัติเพิ่มเติมซึ่งไม่มีในผลลัพธ์ของ ExampleGen มิเช่นนั้น อย่าลังเลที่จะใช้ Trainer ในขั้นตอนต่อไป
กำหนดคุณสมบัติของรุ่น
models/features.py มีค่าคงที่สำหรับกำหนดคุณลักษณะสำหรับโมเดล รวมถึงชื่อคุณลักษณะ ขนาดของคำศัพท์ และอื่นๆ ตามค่าเริ่มต้น เทมเพลต penguin จะมี costant สองตัวคือ FEATURE_KEYS และ LABEL_KEY เนื่องจากโมเดล penguin ของเราจะแก้ปัญหาการจัดหมวดหมู่โดยใช้การเรียนรู้ภายใต้การดูแล และฟีเจอร์ทั้งหมดเป็นฟีเจอร์ตัวเลขต่อเนื่อง ดู คำจำกัดความคุณลักษณะจากตัวอย่างรถแท็กซี่ชิคาโก สำหรับตัวอย่างอื่น
ใช้การประมวลผลล่วงหน้าสำหรับการฝึกอบรม / การให้บริการใน preprocessing_fn()
วิศวกรรมคุณลักษณะที่เกิดขึ้นจริงเกิดขึ้นในฟังก์ชัน preprocessing_fn() ใน models/preprocessing.py
ใน preprocessing_fn คุณสามารถกำหนดชุดของฟังก์ชันที่จัดการอินพุต dict ของเทนเซอร์เพื่อสร้างเอาต์พุต dict ของเทนเซอร์ มีฟังก์ชันตัวช่วย เช่น scale_to_0_1 และ compute_and_apply_vocabulary ใน TensorFlow Transform API หรือคุณสามารถใช้ฟังก์ชัน TensorFlow ปกติก็ได้ โดยค่าเริ่มต้น เทมเพลต penguin จะมีตัวอย่างการใช้งานฟังก์ชัน tft.scale_to_z_score เพื่อทำให้ค่าคุณลักษณะเป็นปกติ
ดู คู่มือการแปลง Tensflow สำหรับข้อมูลเพิ่มเติมเกี่ยวกับการสร้าง preprocessing_fn
เพิ่มองค์ประกอบการแปลงไปยังไปป์ไลน์
หาก preprocessing_fn ของคุณพร้อม ให้เพิ่มองค์ประกอบ Transform ไปยังไปป์ไลน์
- ในไฟล์
pipeline/pipeline.py.py ให้ยกเลิกการใส่ความคิดเห็น# components.append(transform)เพื่อเพิ่มส่วนประกอบไปยังไปป์ไลน์
คุณสามารถอัปเดตไปป์ไลน์และเรียกใช้อีกครั้ง
!tfx pipeline update --engine=local --pipeline_path=local_runner.py \
&& tfx run create --engine=local --pipeline_name={PIPELINE_NAME}
CLI
Updating pipeline
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Excluding no splits because exclude_splits is not set.
Pipeline "my_pipeline" updated successfully.
CLI
Creating a run for pipeline: my_pipeline
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Using deployment config:
executor_specs {
key: "CsvExampleGen"
value {
beam_executable_spec {
python_executor_spec {
class_path: "tfx.components.example_gen.csv_example_gen.executor.Executor"
}
}
}
}
executor_specs {
key: "SchemaGen"
value {
python_class_executable_spec {
class_path: "tfx.components.schema_gen.executor.Executor"
}
}
}
executor_specs {
key: "StatisticsGen"
value {
beam_executable_spec {
python_executor_spec {
class_path: "tfx.components.statistics_gen.executor.Executor"
}
}
}
}
custom_driver_specs {
key: "CsvExampleGen"
value {
python_class_executable_spec {
class_path: "tfx.components.example_gen.driver.FileBasedDriver"
}
}
}
metadata_connection_config {
database_connection_config {
sqlite {
filename_uri: "./tfx_metadata/my_pipeline/metadata.db"
connection_mode: READWRITE_OPENCREATE
}
}
}
INFO:absl:Using connection config:
sqlite {
filename_uri: "./tfx_metadata/my_pipeline/metadata.db"
connection_mode: READWRITE_OPENCREATE
}
INFO:absl:Component CsvExampleGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.example_gen.csv_example_gen.component.CsvExampleGen"
}
id: "CsvExampleGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:37.055994"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
}
outputs {
outputs {
key: "examples"
value {
artifact_spec {
type {
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
}
}
}
}
}
parameters {
parameters {
key: "input_base"
value {
field_value {
string_value: "/home/kbuilder/imported/my_pipeline/data"
}
}
}
parameters {
key: "input_config"
value {
field_value {
string_value: "{\n \"splits\": [\n {\n \"name\": \"single_split\",\n \"pattern\": \"*\"\n }\n ]\n}"
}
}
}
parameters {
key: "output_config"
value {
field_value {
string_value: "{\n \"split_config\": {\n \"splits\": [\n {\n \"hash_buckets\": 2,\n \"name\": \"train\"\n },\n {\n \"hash_buckets\": 1,\n \"name\": \"eval\"\n }\n ]\n }\n}"
}
}
}
parameters {
key: "output_data_format"
value {
field_value {
int_value: 6
}
}
}
parameters {
key: "output_file_format"
value {
field_value {
int_value: 5
}
}
}
}
downstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:select span and version = (0, None)
INFO:absl:latest span and version = (0, None)
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 4
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=4, input_dict={}, output_dict=defaultdict(<class 'list'>, {'examples': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/4"
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:37.055994:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
, artifact_type: name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}), exec_properties={'output_file_format': 5, 'input_base': '/home/kbuilder/imported/my_pipeline/data', 'output_config': '{\n "split_config": {\n "splits": [\n {\n "hash_buckets": 2,\n "name": "train"\n },\n {\n "hash_buckets": 1,\n "name": "eval"\n }\n ]\n }\n}', 'output_data_format': 6, 'input_config': '{\n "splits": [\n {\n "name": "single_split",\n "pattern": "*"\n }\n ]\n}', 'span': 0, 'version': None, 'input_fingerprint': 'split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522'}, execution_output_uri='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/executor_execution/4/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/stateful_working_dir/2022-02-03T11:09:37.055994', tmp_dir='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/executor_execution/4/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.example_gen.csv_example_gen.component.CsvExampleGen"
}
id: "CsvExampleGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:37.055994"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
}
outputs {
outputs {
key: "examples"
value {
artifact_spec {
type {
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
}
}
}
}
}
parameters {
parameters {
key: "input_base"
value {
field_value {
string_value: "/home/kbuilder/imported/my_pipeline/data"
}
}
}
parameters {
key: "input_config"
value {
field_value {
string_value: "{\n \"splits\": [\n {\n \"name\": \"single_split\",\n \"pattern\": \"*\"\n }\n ]\n}"
}
}
}
parameters {
key: "output_config"
value {
field_value {
string_value: "{\n \"split_config\": {\n \"splits\": [\n {\n \"hash_buckets\": 2,\n \"name\": \"train\"\n },\n {\n \"hash_buckets\": 1,\n \"name\": \"eval\"\n }\n ]\n }\n}"
}
}
}
parameters {
key: "output_data_format"
value {
field_value {
int_value: 6
}
}
}
parameters {
key: "output_file_format"
value {
field_value {
int_value: 5
}
}
}
}
downstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:09:37.055994')
INFO:absl:Generating examples.
INFO:absl:Processing input csv data /home/kbuilder/imported/my_pipeline/data/* to TFExample.
WARNING:root:Make sure that locally built Python SDK docker image has Python 3.7 interpreter.
E0203 11:09:37.596944686 5287 fork_posix.cc:70] Fork support is only compatible with the epoll1 and poll polling strategies
WARNING:apache_beam.io.tfrecordio:Couldn't find python-snappy so the implementation of _TFRecordUtil._masked_crc32c is not as fast as it could be.
INFO:absl:Examples generated.
INFO:absl:Value type <class 'NoneType'> of key version in exec_properties is not supported, going to drop it
INFO:absl:Value type <class 'list'> of key _beam_pipeline_args in exec_properties is not supported, going to drop it
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 4 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'examples': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/4"
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:37.055994:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}) for execution 4
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component CsvExampleGen is finished.
INFO:absl:Component StatisticsGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.statistics_gen.component.StatisticsGen"
base_type: PROCESS
}
id: "StatisticsGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:37.055994"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
}
inputs {
inputs {
key: "examples"
value {
channels {
producer_node_query {
id: "CsvExampleGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:37.055994"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
artifact_query {
type {
name: "Examples"
base_type: DATASET
}
}
output_key: "examples"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "statistics"
value {
artifact_spec {
type {
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
}
upstream_nodes: "CsvExampleGen"
downstream_nodes: "SchemaGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 5
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=5, input_dict={'examples': [Artifact(artifact: id: 4
type_id: 15
uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/4"
properties {
key: "split_names"
value {
string_value: "[\"train\", \"eval\"]"
}
}
custom_properties {
key: "file_format"
value {
string_value: "tfrecords_gzip"
}
}
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:37.055994:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "payload_format"
value {
string_value: "FORMAT_TF_EXAMPLE"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
state: LIVE
create_time_since_epoch: 1643886578210
last_update_time_since_epoch: 1643886578210
, artifact_type: id: 15
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}, output_dict=defaultdict(<class 'list'>, {'statistics': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/5"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:37.055994:StatisticsGen:statistics:0"
}
}
, artifact_type: name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}), exec_properties={'exclude_splits': '[]'}, execution_output_uri='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/executor_execution/5/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/stateful_working_dir/2022-02-03T11:09:37.055994', tmp_dir='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/executor_execution/5/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.statistics_gen.component.StatisticsGen"
base_type: PROCESS
}
id: "StatisticsGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:37.055994"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
}
inputs {
inputs {
key: "examples"
value {
channels {
producer_node_query {
id: "CsvExampleGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:37.055994"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
artifact_query {
type {
name: "Examples"
base_type: DATASET
}
}
output_key: "examples"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "statistics"
value {
artifact_spec {
type {
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
}
upstream_nodes: "CsvExampleGen"
downstream_nodes: "SchemaGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:09:37.055994')
INFO:absl:Generating statistics for split train.
INFO:absl:Statistics for split train written to ./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/5/Split-train.
INFO:absl:Generating statistics for split eval.
INFO:absl:Statistics for split eval written to ./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/5/Split-eval.
WARNING:root:Make sure that locally built Python SDK docker image has Python 3.7 interpreter.
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 5 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'statistics': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/5"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:37.055994:StatisticsGen:statistics:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}) for execution 5
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component StatisticsGen is finished.
INFO:absl:Component SchemaGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.schema_gen.component.SchemaGen"
base_type: PROCESS
}
id: "SchemaGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:37.055994"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.SchemaGen"
}
}
}
}
inputs {
inputs {
key: "statistics"
value {
channels {
producer_node_query {
id: "StatisticsGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:37.055994"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
artifact_query {
type {
name: "ExampleStatistics"
base_type: STATISTICS
}
}
output_key: "statistics"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "schema"
value {
artifact_spec {
type {
name: "Schema"
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
parameters {
key: "infer_feature_shape"
value {
field_value {
int_value: 1
}
}
}
}
upstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 6
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=6, input_dict={'statistics': [Artifact(artifact: id: 5
type_id: 17
uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/5"
properties {
key: "split_names"
value {
string_value: "[\"train\", \"eval\"]"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:37.055994:StatisticsGen:statistics:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
state: LIVE
create_time_since_epoch: 1643886581527
last_update_time_since_epoch: 1643886581527
, artifact_type: id: 17
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}, output_dict=defaultdict(<class 'list'>, {'schema': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/SchemaGen/schema/6"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:37.055994:SchemaGen:schema:0"
}
}
, artifact_type: name: "Schema"
)]}), exec_properties={'exclude_splits': '[]', 'infer_feature_shape': 1}, execution_output_uri='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/executor_execution/6/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/stateful_working_dir/2022-02-03T11:09:37.055994', tmp_dir='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/executor_execution/6/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.schema_gen.component.SchemaGen"
base_type: PROCESS
}
id: "SchemaGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:37.055994"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.SchemaGen"
}
}
}
}
inputs {
inputs {
key: "statistics"
value {
channels {
producer_node_query {
id: "StatisticsGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:09:37.055994"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
artifact_query {
type {
name: "ExampleStatistics"
base_type: STATISTICS
}
}
output_key: "statistics"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "schema"
value {
artifact_spec {
type {
name: "Schema"
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
parameters {
key: "infer_feature_shape"
value {
field_value {
int_value: 1
}
}
}
}
upstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:09:37.055994')
INFO:absl:Processing schema from statistics for split train.
INFO:absl:Processing schema from statistics for split eval.
INFO:absl:Schema written to ./tfx_pipeline_output/my_pipeline/SchemaGen/schema/6/schema.pbtxt.
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 6 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'schema': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/SchemaGen/schema/6"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:09:37.055994:SchemaGen:schema:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "Schema"
)]}) for execution 6
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component SchemaGen is finished.
ตัวยึดตำแหน่ง23 หากไปป์ไลน์ทำงานสำเร็จ คุณจะเห็น "การแปลงคอมโพเนนต์เสร็จสิ้น" ที่ไหนสักแห่ง ในบันทึก เนื่องจากส่วนประกอบ Transform และส่วนประกอบ ExampleValidator ไม่ได้พึ่งพาซึ่งกันและกัน ลำดับการดำเนินการจึงไม่คงที่ ที่กล่าวว่า Transform และ ExampleValidator ใดตัวหนึ่งสามารถเป็นองค์ประกอบสุดท้ายในการดำเนินการไปป์ไลน์
ตรวจสอบผลลัพธ์จาก Transformer
องค์ประกอบการแปลงจะสร้างเอาต์พุตสองประเภท ได้แก่ กราฟเทนเซอร์โฟลว์และตัวอย่างที่แปลงแล้ว ตัวอย่างที่แปลงแล้วเป็นตัวอย่างประเภทสิ่งประดิษฐ์ที่สร้างขึ้นโดย ExampleGen แต่ตัวอย่างนี้มีค่าคุณลักษณะที่แปลงแล้วแทน
คุณสามารถตรวจสอบได้เช่นเดียวกับที่เราทำในขั้นตอนก่อนหน้า
with metadata.Metadata(metadata_connection_config) as metadata_handler:
# Search all aritfacts from the previous run of Transform component.
artifacts = get_latest_artifacts(metadata_handler.store,
PIPELINE_NAME, "Transform")
# Find artifacts of Examples type.
transformed_examples_artifacts = find_latest_artifacts_by_type(
metadata_handler.store, artifacts,
standard_artifacts.Examples.TYPE_NAME)
preview_examples(transformed_examples_artifacts)
ขั้นตอนที่ 4. ฝึกโมเดลของคุณด้วยส่วนประกอบ Trainer
เราจะสร้างโมเดล ML โดยใช้องค์ประกอบ Trainer ดูข้อมูลเพิ่มเติมใน คู่มือส่วนประกอบเทรนเนอร์ คุณต้องระบุรหัสรุ่นของคุณกับส่วนประกอบ Trainer
กำหนดรูปแบบของคุณ
ในเทมเพลตเพนกวิน models.model.run_fn ถูกใช้เป็นอาร์กิวเมนต์ run_fn สำหรับคอมโพเนนต์ Trainer หมายความว่า run_fn() ใน models/model.py จะถูกเรียกใช้เมื่อคอมโพเนนต์ Trainer ทำงาน คุณสามารถดูรหัสเพื่อสร้างแบบจำลอง DNN อย่างง่ายโดยใช้ keras API ในรหัสที่กำหนด ดู TensorFlow 2.x ในคู่มือ TFX สำหรับข้อมูลเพิ่มเติมเกี่ยวกับการใช้ keras API ใน TFX
ใน run_fn นี้ คุณควรสร้างโมเดลและบันทึกลงในไดเร็กทอรีที่ชี้โดย fn_args.serving_model_dir ซึ่งถูกระบุโดยคอมโพเนนต์ คุณสามารถใช้อาร์กิวเมนต์อื่นใน fn_args ซึ่งส่งผ่านไปยัง run_fn ดู รหัสที่เกี่ยวข้อง สำหรับรายการอาร์กิวเมนต์ทั้งหมดใน fn_args
กำหนดคุณสมบัติของคุณใน models/features.py และใช้งานตามต้องการ หากคุณได้เปลี่ยนแปลงคุณลักษณะของคุณในขั้นตอนที่ 3 คุณควรใช้คุณลักษณะที่แปลงแล้วเป็นอินพุตสำหรับโมเดลของคุณ
เพิ่มองค์ประกอบ Trainer ไปยังไปป์ไลน์
หาก run_fn ของคุณพร้อม ให้เพิ่มองค์ประกอบ Trainer ไปที่ไปป์ไลน์
- ในไฟล์
pipeline/pipeline.py.py ให้ยกเลิกการใส่ความคิดเห็น# components.append(trainer)เพื่อเพิ่มส่วนประกอบไปยังไปป์ไลน์
อาร์กิวเมนต์สำหรับส่วนประกอบเทรนเนอร์อาจขึ้นอยู่กับว่าคุณใช้ส่วนประกอบ Transform หรือไม่
- หากคุณ ไม่ ได้ใช้องค์ประกอบ
Transformคุณไม่จำเป็นต้องเปลี่ยนอาร์กิวเมนต์ หากคุณใช้คอมโพเนนต์
Transformคุณต้องเปลี่ยนอาร์กิวเมนต์เมื่อสร้างอินสแตนซ์คอมโพเนนต์Trainer- เปลี่ยน
examplesอาร์กิวเมนต์เป็นexamples=transform.outputs['transformed_examples'],เราจำเป็นต้องใช้ตัวอย่างที่เปลี่ยนแปลงสำหรับการฝึกอบรม - เพิ่มอาร์กิวเมนต์
transform_graphเช่นtransform_graph=transform.outputs['transform_graph'],กราฟนี้มีกราฟ TensorFlow สำหรับการดำเนินการแปลง - หลังจากการเปลี่ยนแปลงข้างต้น โค้ดสำหรับการสร้างส่วนประกอบ Trainer จะมีลักษณะดังนี้
# If you use a Transform component. trainer = Trainer( run_fn=run_fn, examples=transform.outputs['transformed_examples'], transform_graph=transform.outputs['transform_graph'], schema=schema_gen.outputs['schema'], ...- เปลี่ยน
คุณสามารถอัปเดตไปป์ไลน์และเรียกใช้อีกครั้ง
!tfx pipeline update --engine=local --pipeline_path=local_runner.py \
&& tfx run create --engine=local --pipeline_name={PIPELINE_NAME}
CLI
Updating pipeline
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Excluding no splits because exclude_splits is not set.
Pipeline "my_pipeline" updated successfully.
CLI
Creating a run for pipeline: my_pipeline
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Using deployment config:
executor_specs {
key: "CsvExampleGen"
value {
beam_executable_spec {
python_executor_spec {
class_path: "tfx.components.example_gen.csv_example_gen.executor.Executor"
}
}
}
}
executor_specs {
key: "SchemaGen"
value {
python_class_executable_spec {
class_path: "tfx.components.schema_gen.executor.Executor"
}
}
}
executor_specs {
key: "StatisticsGen"
value {
beam_executable_spec {
python_executor_spec {
class_path: "tfx.components.statistics_gen.executor.Executor"
}
}
}
}
custom_driver_specs {
key: "CsvExampleGen"
value {
python_class_executable_spec {
class_path: "tfx.components.example_gen.driver.FileBasedDriver"
}
}
}
metadata_connection_config {
database_connection_config {
sqlite {
filename_uri: "./tfx_metadata/my_pipeline/metadata.db"
connection_mode: READWRITE_OPENCREATE
}
}
}
INFO:absl:Using connection config:
sqlite {
filename_uri: "./tfx_metadata/my_pipeline/metadata.db"
connection_mode: READWRITE_OPENCREATE
}
INFO:absl:Component CsvExampleGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.example_gen.csv_example_gen.component.CsvExampleGen"
}
id: "CsvExampleGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:00.469382"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
}
outputs {
outputs {
key: "examples"
value {
artifact_spec {
type {
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
}
}
}
}
}
parameters {
parameters {
key: "input_base"
value {
field_value {
string_value: "/home/kbuilder/imported/my_pipeline/data"
}
}
}
parameters {
key: "input_config"
value {
field_value {
string_value: "{\n \"splits\": [\n {\n \"name\": \"single_split\",\n \"pattern\": \"*\"\n }\n ]\n}"
}
}
}
parameters {
key: "output_config"
value {
field_value {
string_value: "{\n \"split_config\": {\n \"splits\": [\n {\n \"hash_buckets\": 2,\n \"name\": \"train\"\n },\n {\n \"hash_buckets\": 1,\n \"name\": \"eval\"\n }\n ]\n }\n}"
}
}
}
parameters {
key: "output_data_format"
value {
field_value {
int_value: 6
}
}
}
parameters {
key: "output_file_format"
value {
field_value {
int_value: 5
}
}
}
}
downstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:select span and version = (0, None)
INFO:absl:latest span and version = (0, None)
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 7
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=7, input_dict={}, output_dict=defaultdict(<class 'list'>, {'examples': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/7"
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:00.469382:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
, artifact_type: name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}), exec_properties={'input_base': '/home/kbuilder/imported/my_pipeline/data', 'output_config': '{\n "split_config": {\n "splits": [\n {\n "hash_buckets": 2,\n "name": "train"\n },\n {\n "hash_buckets": 1,\n "name": "eval"\n }\n ]\n }\n}', 'output_data_format': 6, 'output_file_format': 5, 'input_config': '{\n "splits": [\n {\n "name": "single_split",\n "pattern": "*"\n }\n ]\n}', 'span': 0, 'version': None, 'input_fingerprint': 'split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522'}, execution_output_uri='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/executor_execution/7/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/stateful_working_dir/2022-02-03T11:10:00.469382', tmp_dir='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/executor_execution/7/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.example_gen.csv_example_gen.component.CsvExampleGen"
}
id: "CsvExampleGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:00.469382"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
}
outputs {
outputs {
key: "examples"
value {
artifact_spec {
type {
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
}
}
}
}
}
parameters {
parameters {
key: "input_base"
value {
field_value {
string_value: "/home/kbuilder/imported/my_pipeline/data"
}
}
}
parameters {
key: "input_config"
value {
field_value {
string_value: "{\n \"splits\": [\n {\n \"name\": \"single_split\",\n \"pattern\": \"*\"\n }\n ]\n}"
}
}
}
parameters {
key: "output_config"
value {
field_value {
string_value: "{\n \"split_config\": {\n \"splits\": [\n {\n \"hash_buckets\": 2,\n \"name\": \"train\"\n },\n {\n \"hash_buckets\": 1,\n \"name\": \"eval\"\n }\n ]\n }\n}"
}
}
}
parameters {
key: "output_data_format"
value {
field_value {
int_value: 6
}
}
}
parameters {
key: "output_file_format"
value {
field_value {
int_value: 5
}
}
}
}
downstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:10:00.469382')
INFO:absl:Generating examples.
INFO:absl:Processing input csv data /home/kbuilder/imported/my_pipeline/data/* to TFExample.
WARNING:root:Make sure that locally built Python SDK docker image has Python 3.7 interpreter.
E0203 11:10:01.173700221 5436 fork_posix.cc:70] Fork support is only compatible with the epoll1 and poll polling strategies
WARNING:apache_beam.io.tfrecordio:Couldn't find python-snappy so the implementation of _TFRecordUtil._masked_crc32c is not as fast as it could be.
INFO:absl:Examples generated.
INFO:absl:Value type <class 'NoneType'> of key version in exec_properties is not supported, going to drop it
INFO:absl:Value type <class 'list'> of key _beam_pipeline_args in exec_properties is not supported, going to drop it
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 7 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'examples': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/7"
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:00.469382:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}) for execution 7
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component CsvExampleGen is finished.
INFO:absl:Component StatisticsGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.statistics_gen.component.StatisticsGen"
base_type: PROCESS
}
id: "StatisticsGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:00.469382"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
}
inputs {
inputs {
key: "examples"
value {
channels {
producer_node_query {
id: "CsvExampleGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:00.469382"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
artifact_query {
type {
name: "Examples"
base_type: DATASET
}
}
output_key: "examples"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "statistics"
value {
artifact_spec {
type {
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
}
upstream_nodes: "CsvExampleGen"
downstream_nodes: "SchemaGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 8
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=8, input_dict={'examples': [Artifact(artifact: id: 7
type_id: 15
uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/7"
properties {
key: "split_names"
value {
string_value: "[\"train\", \"eval\"]"
}
}
custom_properties {
key: "file_format"
value {
string_value: "tfrecords_gzip"
}
}
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:00.469382:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "payload_format"
value {
string_value: "FORMAT_TF_EXAMPLE"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
state: LIVE
create_time_since_epoch: 1643886601629
last_update_time_since_epoch: 1643886601629
, artifact_type: id: 15
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}, output_dict=defaultdict(<class 'list'>, {'statistics': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/8"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:00.469382:StatisticsGen:statistics:0"
}
}
, artifact_type: name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}), exec_properties={'exclude_splits': '[]'}, execution_output_uri='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/executor_execution/8/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/stateful_working_dir/2022-02-03T11:10:00.469382', tmp_dir='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/executor_execution/8/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.statistics_gen.component.StatisticsGen"
base_type: PROCESS
}
id: "StatisticsGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:00.469382"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
}
inputs {
inputs {
key: "examples"
value {
channels {
producer_node_query {
id: "CsvExampleGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:00.469382"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
artifact_query {
type {
name: "Examples"
base_type: DATASET
}
}
output_key: "examples"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "statistics"
value {
artifact_spec {
type {
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
}
upstream_nodes: "CsvExampleGen"
downstream_nodes: "SchemaGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:10:00.469382')
INFO:absl:Generating statistics for split train.
INFO:absl:Statistics for split train written to ./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/8/Split-train.
INFO:absl:Generating statistics for split eval.
INFO:absl:Statistics for split eval written to ./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/8/Split-eval.
WARNING:root:Make sure that locally built Python SDK docker image has Python 3.7 interpreter.
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 8 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'statistics': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/8"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:00.469382:StatisticsGen:statistics:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}) for execution 8
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component StatisticsGen is finished.
INFO:absl:Component SchemaGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.schema_gen.component.SchemaGen"
base_type: PROCESS
}
id: "SchemaGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:00.469382"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.SchemaGen"
}
}
}
}
inputs {
inputs {
key: "statistics"
value {
channels {
producer_node_query {
id: "StatisticsGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:00.469382"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
artifact_query {
type {
name: "ExampleStatistics"
base_type: STATISTICS
}
}
output_key: "statistics"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "schema"
value {
artifact_spec {
type {
name: "Schema"
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
parameters {
key: "infer_feature_shape"
value {
field_value {
int_value: 1
}
}
}
}
upstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 9
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=9, input_dict={'statistics': [Artifact(artifact: id: 8
type_id: 17
uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/8"
properties {
key: "split_names"
value {
string_value: "[\"train\", \"eval\"]"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:00.469382:StatisticsGen:statistics:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
state: LIVE
create_time_since_epoch: 1643886605023
last_update_time_since_epoch: 1643886605023
, artifact_type: id: 17
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}, output_dict=defaultdict(<class 'list'>, {'schema': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/SchemaGen/schema/9"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:00.469382:SchemaGen:schema:0"
}
}
, artifact_type: name: "Schema"
)]}), exec_properties={'exclude_splits': '[]', 'infer_feature_shape': 1}, execution_output_uri='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/executor_execution/9/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/stateful_working_dir/2022-02-03T11:10:00.469382', tmp_dir='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/executor_execution/9/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.schema_gen.component.SchemaGen"
base_type: PROCESS
}
id: "SchemaGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:00.469382"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.SchemaGen"
}
}
}
}
inputs {
inputs {
key: "statistics"
value {
channels {
producer_node_query {
id: "StatisticsGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:00.469382"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
artifact_query {
type {
name: "ExampleStatistics"
base_type: STATISTICS
}
}
output_key: "statistics"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "schema"
value {
artifact_spec {
type {
name: "Schema"
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
parameters {
key: "infer_feature_shape"
value {
field_value {
int_value: 1
}
}
}
}
upstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:10:00.469382')
INFO:absl:Processing schema from statistics for split train.
INFO:absl:Processing schema from statistics for split eval.
INFO:absl:Schema written to ./tfx_pipeline_output/my_pipeline/SchemaGen/schema/9/schema.pbtxt.
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 9 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'schema': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/SchemaGen/schema/9"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:00.469382:SchemaGen:schema:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "Schema"
)]}) for execution 9
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component SchemaGen is finished.
เมื่อการดำเนินการนี้สำเร็จ ตอนนี้คุณได้สร้างและเรียกใช้ไปป์ไลน์ TFX แรกสำหรับโมเดลของคุณแล้ว ยินดีด้วย!
โมเดลใหม่ของคุณจะอยู่ในบางแห่งภายใต้ไดเร็กทอรีเอาต์พุต แต่จะดีกว่าถ้ามีโมเดลในตำแหน่งคงที่หรือบริการนอกไปป์ไลน์ TFX ซึ่งมีผลชั่วคราวจำนวนมาก ดียิ่งขึ้นด้วยการประเมินอย่างต่อเนื่องของแบบจำลองที่สร้างขึ้นซึ่งมีความสำคัญอย่างยิ่งในระบบการผลิต ML เราจะเห็นว่าการประเมินและการปรับใช้อย่างต่อเนื่องทำงานอย่างไรใน TFX ในขั้นตอนต่อไป
ขั้นตอนที่ 5 (ไม่บังคับ) ประเมินแบบจำลองด้วยเครื่องมือประเมินและเผยแพร่ด้วยตัวผลัก
องค์ประกอบของ Evaluator จะประเมินทุกโมเดลที่สร้างขึ้นอย่างต่อเนื่องจาก Trainer และ Pusher จะคัดลอกโมเดลไปยังตำแหน่งที่กำหนดไว้ล่วงหน้าในระบบไฟล์ หรือแม้แต่ไปที่ Google Cloud AI Platform Models
เพิ่มองค์ประกอบของตัวประเมินไปยังไปป์ไลน์
ในไฟล์ pipeline/pipeline.py .py:
- Uncomment
# components.append(model_resolver)เพื่อเพิ่มตัวแก้ไขรุ่นล่าสุดให้กับไปป์ไลน์ ตัวประเมินสามารถใช้เพื่อเปรียบเทียบแบบจำลองกับแบบจำลองพื้นฐานแบบเก่าซึ่งผ่านตัวประเมินในการรันไปป์ไลน์ครั้งล่าสุดLatestBlessedModelResolverค้นหาโมเดลล่าสุดที่ผ่าน Evaluator - ตั้งค่า
tfma.MetricsSpecที่เหมาะสมสำหรับโมเดลของคุณ การประเมินอาจแตกต่างกันไปในแต่ละรุ่น ML ในเทมเพลตเพนกวินSparseCategoricalAccuracyถูกใช้เนื่องจากเรากำลังแก้ปัญหาการจำแนกประเภทหลายหมวดหมู่ คุณต้องระบุtfma.SliceSpecเพื่อวิเคราะห์โมเดลของคุณสำหรับสไลซ์เฉพาะ สำหรับรายละเอียดเพิ่มเติม โปรดดู คู่มือส่วนประกอบสำหรับโปรแกรมประเมิน - Uncomment
# components.append(evaluator)เพื่อเพิ่มส่วนประกอบไปยังไปป์ไลน์
คุณสามารถอัปเดตไปป์ไลน์และเรียกใช้อีกครั้ง
# Update and run the pipeline.
!tfx pipeline update --engine=local --pipeline_path=local_runner.py \
&& tfx run create --engine=local --pipeline_name={PIPELINE_NAME}
CLI
Updating pipeline
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Excluding no splits because exclude_splits is not set.
Pipeline "my_pipeline" updated successfully.
CLI
Creating a run for pipeline: my_pipeline
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Using deployment config:
executor_specs {
key: "CsvExampleGen"
value {
beam_executable_spec {
python_executor_spec {
class_path: "tfx.components.example_gen.csv_example_gen.executor.Executor"
}
}
}
}
executor_specs {
key: "SchemaGen"
value {
python_class_executable_spec {
class_path: "tfx.components.schema_gen.executor.Executor"
}
}
}
executor_specs {
key: "StatisticsGen"
value {
beam_executable_spec {
python_executor_spec {
class_path: "tfx.components.statistics_gen.executor.Executor"
}
}
}
}
custom_driver_specs {
key: "CsvExampleGen"
value {
python_class_executable_spec {
class_path: "tfx.components.example_gen.driver.FileBasedDriver"
}
}
}
metadata_connection_config {
database_connection_config {
sqlite {
filename_uri: "./tfx_metadata/my_pipeline/metadata.db"
connection_mode: READWRITE_OPENCREATE
}
}
}
INFO:absl:Using connection config:
sqlite {
filename_uri: "./tfx_metadata/my_pipeline/metadata.db"
connection_mode: READWRITE_OPENCREATE
}
INFO:absl:Component CsvExampleGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.example_gen.csv_example_gen.component.CsvExampleGen"
}
id: "CsvExampleGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:24.358660"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
}
outputs {
outputs {
key: "examples"
value {
artifact_spec {
type {
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
}
}
}
}
}
parameters {
parameters {
key: "input_base"
value {
field_value {
string_value: "/home/kbuilder/imported/my_pipeline/data"
}
}
}
parameters {
key: "input_config"
value {
field_value {
string_value: "{\n \"splits\": [\n {\n \"name\": \"single_split\",\n \"pattern\": \"*\"\n }\n ]\n}"
}
}
}
parameters {
key: "output_config"
value {
field_value {
string_value: "{\n \"split_config\": {\n \"splits\": [\n {\n \"hash_buckets\": 2,\n \"name\": \"train\"\n },\n {\n \"hash_buckets\": 1,\n \"name\": \"eval\"\n }\n ]\n }\n}"
}
}
}
parameters {
key: "output_data_format"
value {
field_value {
int_value: 6
}
}
}
parameters {
key: "output_file_format"
value {
field_value {
int_value: 5
}
}
}
}
downstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:select span and version = (0, None)
INFO:absl:latest span and version = (0, None)
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 10
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=10, input_dict={}, output_dict=defaultdict(<class 'list'>, {'examples': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/10"
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:24.358660:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
, artifact_type: name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}), exec_properties={'output_file_format': 5, 'output_config': '{\n "split_config": {\n "splits": [\n {\n "hash_buckets": 2,\n "name": "train"\n },\n {\n "hash_buckets": 1,\n "name": "eval"\n }\n ]\n }\n}', 'output_data_format': 6, 'input_base': '/home/kbuilder/imported/my_pipeline/data', 'input_config': '{\n "splits": [\n {\n "name": "single_split",\n "pattern": "*"\n }\n ]\n}', 'span': 0, 'version': None, 'input_fingerprint': 'split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522'}, execution_output_uri='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/executor_execution/10/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/stateful_working_dir/2022-02-03T11:10:24.358660', tmp_dir='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/executor_execution/10/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.example_gen.csv_example_gen.component.CsvExampleGen"
}
id: "CsvExampleGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:24.358660"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
}
outputs {
outputs {
key: "examples"
value {
artifact_spec {
type {
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
}
}
}
}
}
parameters {
parameters {
key: "input_base"
value {
field_value {
string_value: "/home/kbuilder/imported/my_pipeline/data"
}
}
}
parameters {
key: "input_config"
value {
field_value {
string_value: "{\n \"splits\": [\n {\n \"name\": \"single_split\",\n \"pattern\": \"*\"\n }\n ]\n}"
}
}
}
parameters {
key: "output_config"
value {
field_value {
string_value: "{\n \"split_config\": {\n \"splits\": [\n {\n \"hash_buckets\": 2,\n \"name\": \"train\"\n },\n {\n \"hash_buckets\": 1,\n \"name\": \"eval\"\n }\n ]\n }\n}"
}
}
}
parameters {
key: "output_data_format"
value {
field_value {
int_value: 6
}
}
}
parameters {
key: "output_file_format"
value {
field_value {
int_value: 5
}
}
}
}
downstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:10:24.358660')
INFO:absl:Generating examples.
INFO:absl:Processing input csv data /home/kbuilder/imported/my_pipeline/data/* to TFExample.
WARNING:root:Make sure that locally built Python SDK docker image has Python 3.7 interpreter.
E0203 11:10:24.894390124 5584 fork_posix.cc:70] Fork support is only compatible with the epoll1 and poll polling strategies
WARNING:apache_beam.io.tfrecordio:Couldn't find python-snappy so the implementation of _TFRecordUtil._masked_crc32c is not as fast as it could be.
INFO:absl:Examples generated.
INFO:absl:Value type <class 'NoneType'> of key version in exec_properties is not supported, going to drop it
INFO:absl:Value type <class 'list'> of key _beam_pipeline_args in exec_properties is not supported, going to drop it
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 10 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'examples': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/10"
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:24.358660:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}) for execution 10
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component CsvExampleGen is finished.
INFO:absl:Component StatisticsGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.statistics_gen.component.StatisticsGen"
base_type: PROCESS
}
id: "StatisticsGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:24.358660"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
}
inputs {
inputs {
key: "examples"
value {
channels {
producer_node_query {
id: "CsvExampleGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:24.358660"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
artifact_query {
type {
name: "Examples"
base_type: DATASET
}
}
output_key: "examples"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "statistics"
value {
artifact_spec {
type {
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
}
upstream_nodes: "CsvExampleGen"
downstream_nodes: "SchemaGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 11
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=11, input_dict={'examples': [Artifact(artifact: id: 10
type_id: 15
uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/10"
properties {
key: "split_names"
value {
string_value: "[\"train\", \"eval\"]"
}
}
custom_properties {
key: "file_format"
value {
string_value: "tfrecords_gzip"
}
}
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:24.358660:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "payload_format"
value {
string_value: "FORMAT_TF_EXAMPLE"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
state: LIVE
create_time_since_epoch: 1643886625515
last_update_time_since_epoch: 1643886625515
, artifact_type: id: 15
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}, output_dict=defaultdict(<class 'list'>, {'statistics': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/11"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:24.358660:StatisticsGen:statistics:0"
}
}
, artifact_type: name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}), exec_properties={'exclude_splits': '[]'}, execution_output_uri='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/executor_execution/11/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/stateful_working_dir/2022-02-03T11:10:24.358660', tmp_dir='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/executor_execution/11/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.statistics_gen.component.StatisticsGen"
base_type: PROCESS
}
id: "StatisticsGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:24.358660"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
}
inputs {
inputs {
key: "examples"
value {
channels {
producer_node_query {
id: "CsvExampleGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:24.358660"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
artifact_query {
type {
name: "Examples"
base_type: DATASET
}
}
output_key: "examples"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "statistics"
value {
artifact_spec {
type {
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
}
upstream_nodes: "CsvExampleGen"
downstream_nodes: "SchemaGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:10:24.358660')
INFO:absl:Generating statistics for split train.
INFO:absl:Statistics for split train written to ./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/11/Split-train.
INFO:absl:Generating statistics for split eval.
INFO:absl:Statistics for split eval written to ./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/11/Split-eval.
WARNING:root:Make sure that locally built Python SDK docker image has Python 3.7 interpreter.
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 11 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'statistics': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/11"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:24.358660:StatisticsGen:statistics:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}) for execution 11
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component StatisticsGen is finished.
INFO:absl:Component SchemaGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.schema_gen.component.SchemaGen"
base_type: PROCESS
}
id: "SchemaGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:24.358660"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.SchemaGen"
}
}
}
}
inputs {
inputs {
key: "statistics"
value {
channels {
producer_node_query {
id: "StatisticsGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:24.358660"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
artifact_query {
type {
name: "ExampleStatistics"
base_type: STATISTICS
}
}
output_key: "statistics"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "schema"
value {
artifact_spec {
type {
name: "Schema"
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
parameters {
key: "infer_feature_shape"
value {
field_value {
int_value: 1
}
}
}
}
upstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 12
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=12, input_dict={'statistics': [Artifact(artifact: id: 11
type_id: 17
uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/11"
properties {
key: "split_names"
value {
string_value: "[\"train\", \"eval\"]"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:24.358660:StatisticsGen:statistics:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
state: LIVE
create_time_since_epoch: 1643886628941
last_update_time_since_epoch: 1643886628941
, artifact_type: id: 17
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}, output_dict=defaultdict(<class 'list'>, {'schema': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/SchemaGen/schema/12"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:24.358660:SchemaGen:schema:0"
}
}
, artifact_type: name: "Schema"
)]}), exec_properties={'infer_feature_shape': 1, 'exclude_splits': '[]'}, execution_output_uri='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/executor_execution/12/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/stateful_working_dir/2022-02-03T11:10:24.358660', tmp_dir='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/executor_execution/12/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.schema_gen.component.SchemaGen"
base_type: PROCESS
}
id: "SchemaGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:24.358660"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.SchemaGen"
}
}
}
}
inputs {
inputs {
key: "statistics"
value {
channels {
producer_node_query {
id: "StatisticsGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:24.358660"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
artifact_query {
type {
name: "ExampleStatistics"
base_type: STATISTICS
}
}
output_key: "statistics"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "schema"
value {
artifact_spec {
type {
name: "Schema"
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
parameters {
key: "infer_feature_shape"
value {
field_value {
int_value: 1
}
}
}
}
upstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:10:24.358660')
INFO:absl:Processing schema from statistics for split train.
INFO:absl:Processing schema from statistics for split eval.
INFO:absl:Schema written to ./tfx_pipeline_output/my_pipeline/SchemaGen/schema/12/schema.pbtxt.
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 12 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'schema': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/SchemaGen/schema/12"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:24.358660:SchemaGen:schema:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "Schema"
)]}) for execution 12
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component SchemaGen is finished.
ตรวจสอบผลลัพธ์ของผู้ประเมิน
ขั้นตอนนี้ต้องใช้ส่วนขยายโน้ตบุ๊ก TensorFlow Model Analysis (TFMA) Jupyter โปรดทราบว่าเวอร์ชันของส่วนขยายโน้ตบุ๊ก TFMA ควรเหมือนกับเวอร์ชันของแพ็กเกจ TFMA python
คำสั่งต่อไปนี้จะติดตั้งส่วนขยายโน้ตบุ๊ก TFMA จากรีจิสทรี NPM อาจใช้เวลาหลายนาทีจึงจะเสร็จสมบูรณ์
# Install TFMA notebook extension.jupyter labextension install tensorflow_model_analysis@{tfma.__version__}
usage: jupyter [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir]
[--paths] [--json] [--debug]
[subcommand]
Jupyter: Interactive Computing
positional arguments:
subcommand the subcommand to launch
optional arguments:
-h, --help show this help message and exit
--version show the versions of core jupyter packages and exit
--config-dir show Jupyter config dir
--data-dir show Jupyter data dir
--runtime-dir show Jupyter runtime dir
--paths show all Jupyter paths. Add --json for machine-readable
format.
--json output paths as machine-readable json
--debug output debug information about paths
Available subcommands: bundlerextension console dejavu execute kernel
kernelspec migrate nbconvert nbextension notebook qtconsole run
serverextension troubleshoot trust
Jupyter command `jupyter-labextension` not found.
ตัวยึดตำแหน่ง32หากการติดตั้งเสร็จสิ้น โปรด โหลดเบราว์เซอร์ของคุณใหม่ เพื่อให้ส่วนขยายมีผล
with metadata.Metadata(metadata_connection_config) as metadata_handler:
# Search all aritfacts from the previous pipeline run.
artifacts = get_latest_artifacts(metadata_handler.store, PIPELINE_NAME)
model_evaluation_artifacts = find_latest_artifacts_by_type(
metadata_handler.store, artifacts,
standard_artifacts.ModelEvaluation.TYPE_NAME)
if model_evaluation_artifacts:
tfma_result = tfma.load_eval_result(model_evaluation_artifacts[0].uri)
tfma.view.render_slicing_metrics(tfma_result)
เพิ่มองค์ประกอบ Pusher ให้กับไปป์ไลน์
หากโมเดลดูน่าสนใจ เราจำเป็นต้องเผยแพร่โมเดล คอมโพเนนต์ Pusher สามารถเผยแพร่โมเดลไปยังตำแหน่งในระบบไฟล์หรือไปยังโมเดลแพลตฟอร์ม GCP AI โดยใช้ ตัวดำเนินการที่กำหนดเอง
องค์ประกอบของ Evaluator จะประเมินทุกโมเดลที่สร้างขึ้นอย่างต่อเนื่องจาก Trainer และ Pusher จะคัดลอกโมเดลไปยังตำแหน่งที่กำหนดไว้ล่วงหน้าในระบบไฟล์ หรือแม้แต่ไปที่ Google Cloud AI Platform Models
- ใน
local_runner.pyให้ตั้งค่าSERVING_MODEL_DIRเป็นไดเร็กทอรีเพื่อเผยแพร่ - ในไฟล์
pipeline/pipeline.py.py ให้ยกเลิกการใส่ความคิดเห็น# components.append(pusher)เพื่อเพิ่มตัวดันไปยังไพพ์ไลน์
คุณสามารถอัปเดตไปป์ไลน์และเรียกใช้อีกครั้ง
# Update and run the pipeline.
!tfx pipeline update --engine=local --pipeline_path=local_runner.py \
&& tfx run create --engine=local --pipeline_name={PIPELINE_NAME}
CLI
Updating pipeline
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Excluding no splits because exclude_splits is not set.
Pipeline "my_pipeline" updated successfully.
CLI
Creating a run for pipeline: my_pipeline
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Excluding no splits because exclude_splits is not set.
INFO:absl:Using deployment config:
executor_specs {
key: "CsvExampleGen"
value {
beam_executable_spec {
python_executor_spec {
class_path: "tfx.components.example_gen.csv_example_gen.executor.Executor"
}
}
}
}
executor_specs {
key: "SchemaGen"
value {
python_class_executable_spec {
class_path: "tfx.components.schema_gen.executor.Executor"
}
}
}
executor_specs {
key: "StatisticsGen"
value {
beam_executable_spec {
python_executor_spec {
class_path: "tfx.components.statistics_gen.executor.Executor"
}
}
}
}
custom_driver_specs {
key: "CsvExampleGen"
value {
python_class_executable_spec {
class_path: "tfx.components.example_gen.driver.FileBasedDriver"
}
}
}
metadata_connection_config {
database_connection_config {
sqlite {
filename_uri: "./tfx_metadata/my_pipeline/metadata.db"
connection_mode: READWRITE_OPENCREATE
}
}
}
INFO:absl:Using connection config:
sqlite {
filename_uri: "./tfx_metadata/my_pipeline/metadata.db"
connection_mode: READWRITE_OPENCREATE
}
INFO:absl:Component CsvExampleGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.example_gen.csv_example_gen.component.CsvExampleGen"
}
id: "CsvExampleGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:48.556314"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
}
outputs {
outputs {
key: "examples"
value {
artifact_spec {
type {
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
}
}
}
}
}
parameters {
parameters {
key: "input_base"
value {
field_value {
string_value: "/home/kbuilder/imported/my_pipeline/data"
}
}
}
parameters {
key: "input_config"
value {
field_value {
string_value: "{\n \"splits\": [\n {\n \"name\": \"single_split\",\n \"pattern\": \"*\"\n }\n ]\n}"
}
}
}
parameters {
key: "output_config"
value {
field_value {
string_value: "{\n \"split_config\": {\n \"splits\": [\n {\n \"hash_buckets\": 2,\n \"name\": \"train\"\n },\n {\n \"hash_buckets\": 1,\n \"name\": \"eval\"\n }\n ]\n }\n}"
}
}
}
parameters {
key: "output_data_format"
value {
field_value {
int_value: 6
}
}
}
parameters {
key: "output_file_format"
value {
field_value {
int_value: 5
}
}
}
}
downstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:select span and version = (0, None)
INFO:absl:latest span and version = (0, None)
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 13
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=13, input_dict={}, output_dict=defaultdict(<class 'list'>, {'examples': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/13"
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:48.556314:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
, artifact_type: name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}), exec_properties={'input_config': '{\n "splits": [\n {\n "name": "single_split",\n "pattern": "*"\n }\n ]\n}', 'output_config': '{\n "split_config": {\n "splits": [\n {\n "hash_buckets": 2,\n "name": "train"\n },\n {\n "hash_buckets": 1,\n "name": "eval"\n }\n ]\n }\n}', 'output_file_format': 5, 'output_data_format': 6, 'input_base': '/home/kbuilder/imported/my_pipeline/data', 'span': 0, 'version': None, 'input_fingerprint': 'split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522'}, execution_output_uri='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/executor_execution/13/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/stateful_working_dir/2022-02-03T11:10:48.556314', tmp_dir='./tfx_pipeline_output/my_pipeline/CsvExampleGen/.system/executor_execution/13/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.example_gen.csv_example_gen.component.CsvExampleGen"
}
id: "CsvExampleGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:48.556314"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
}
outputs {
outputs {
key: "examples"
value {
artifact_spec {
type {
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
}
}
}
}
}
parameters {
parameters {
key: "input_base"
value {
field_value {
string_value: "/home/kbuilder/imported/my_pipeline/data"
}
}
}
parameters {
key: "input_config"
value {
field_value {
string_value: "{\n \"splits\": [\n {\n \"name\": \"single_split\",\n \"pattern\": \"*\"\n }\n ]\n}"
}
}
}
parameters {
key: "output_config"
value {
field_value {
string_value: "{\n \"split_config\": {\n \"splits\": [\n {\n \"hash_buckets\": 2,\n \"name\": \"train\"\n },\n {\n \"hash_buckets\": 1,\n \"name\": \"eval\"\n }\n ]\n }\n}"
}
}
}
parameters {
key: "output_data_format"
value {
field_value {
int_value: 6
}
}
}
parameters {
key: "output_file_format"
value {
field_value {
int_value: 5
}
}
}
}
downstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:10:48.556314')
INFO:absl:Generating examples.
INFO:absl:Processing input csv data /home/kbuilder/imported/my_pipeline/data/* to TFExample.
WARNING:root:Make sure that locally built Python SDK docker image has Python 3.7 interpreter.
E0203 11:10:49.163841363 5734 fork_posix.cc:70] Fork support is only compatible with the epoll1 and poll polling strategies
WARNING:apache_beam.io.tfrecordio:Couldn't find python-snappy so the implementation of _TFRecordUtil._masked_crc32c is not as fast as it could be.
INFO:absl:Examples generated.
INFO:absl:Value type <class 'NoneType'> of key version in exec_properties is not supported, going to drop it
INFO:absl:Value type <class 'list'> of key _beam_pipeline_args in exec_properties is not supported, going to drop it
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 13 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'examples': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/13"
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:48.556314:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}) for execution 13
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component CsvExampleGen is finished.
INFO:absl:Component StatisticsGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.statistics_gen.component.StatisticsGen"
base_type: PROCESS
}
id: "StatisticsGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:48.556314"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
}
inputs {
inputs {
key: "examples"
value {
channels {
producer_node_query {
id: "CsvExampleGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:48.556314"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
artifact_query {
type {
name: "Examples"
base_type: DATASET
}
}
output_key: "examples"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "statistics"
value {
artifact_spec {
type {
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
}
upstream_nodes: "CsvExampleGen"
downstream_nodes: "SchemaGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 14
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=14, input_dict={'examples': [Artifact(artifact: id: 13
type_id: 15
uri: "./tfx_pipeline_output/my_pipeline/CsvExampleGen/examples/13"
properties {
key: "split_names"
value {
string_value: "[\"train\", \"eval\"]"
}
}
custom_properties {
key: "file_format"
value {
string_value: "tfrecords_gzip"
}
}
custom_properties {
key: "input_fingerprint"
value {
string_value: "split:single_split,num_files:1,total_bytes:25648,xor_checksum:1643886522,sum_checksum:1643886522"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:48.556314:CsvExampleGen:examples:0"
}
}
custom_properties {
key: "payload_format"
value {
string_value: "FORMAT_TF_EXAMPLE"
}
}
custom_properties {
key: "span"
value {
int_value: 0
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
state: LIVE
create_time_since_epoch: 1643886649739
last_update_time_since_epoch: 1643886649739
, artifact_type: id: 15
name: "Examples"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
properties {
key: "version"
value: INT
}
base_type: DATASET
)]}, output_dict=defaultdict(<class 'list'>, {'statistics': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/14"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:48.556314:StatisticsGen:statistics:0"
}
}
, artifact_type: name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}), exec_properties={'exclude_splits': '[]'}, execution_output_uri='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/executor_execution/14/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/stateful_working_dir/2022-02-03T11:10:48.556314', tmp_dir='./tfx_pipeline_output/my_pipeline/StatisticsGen/.system/executor_execution/14/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.statistics_gen.component.StatisticsGen"
base_type: PROCESS
}
id: "StatisticsGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:48.556314"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
}
inputs {
inputs {
key: "examples"
value {
channels {
producer_node_query {
id: "CsvExampleGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:48.556314"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.CsvExampleGen"
}
}
}
artifact_query {
type {
name: "Examples"
base_type: DATASET
}
}
output_key: "examples"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "statistics"
value {
artifact_spec {
type {
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
}
upstream_nodes: "CsvExampleGen"
downstream_nodes: "SchemaGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:10:48.556314')
INFO:absl:Generating statistics for split train.
INFO:absl:Statistics for split train written to ./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/14/Split-train.
INFO:absl:Generating statistics for split eval.
INFO:absl:Statistics for split eval written to ./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/14/Split-eval.
WARNING:root:Make sure that locally built Python SDK docker image has Python 3.7 interpreter.
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 14 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'statistics': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/14"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:48.556314:StatisticsGen:statistics:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}) for execution 14
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component StatisticsGen is finished.
INFO:absl:Component SchemaGen is running.
INFO:absl:Running launcher for node_info {
type {
name: "tfx.components.schema_gen.component.SchemaGen"
base_type: PROCESS
}
id: "SchemaGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:48.556314"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.SchemaGen"
}
}
}
}
inputs {
inputs {
key: "statistics"
value {
channels {
producer_node_query {
id: "StatisticsGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:48.556314"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
artifact_query {
type {
name: "ExampleStatistics"
base_type: STATISTICS
}
}
output_key: "statistics"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "schema"
value {
artifact_spec {
type {
name: "Schema"
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
parameters {
key: "infer_feature_shape"
value {
field_value {
int_value: 1
}
}
}
}
upstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Going to run a new execution 15
INFO:absl:Going to run a new execution: ExecutionInfo(execution_id=15, input_dict={'statistics': [Artifact(artifact: id: 14
type_id: 17
uri: "./tfx_pipeline_output/my_pipeline/StatisticsGen/statistics/14"
properties {
key: "split_names"
value {
string_value: "[\"train\", \"eval\"]"
}
}
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:48.556314:StatisticsGen:statistics:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
state: LIVE
create_time_since_epoch: 1643886653128
last_update_time_since_epoch: 1643886653128
, artifact_type: id: 17
name: "ExampleStatistics"
properties {
key: "span"
value: INT
}
properties {
key: "split_names"
value: STRING
}
base_type: STATISTICS
)]}, output_dict=defaultdict(<class 'list'>, {'schema': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/SchemaGen/schema/15"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:48.556314:SchemaGen:schema:0"
}
}
, artifact_type: name: "Schema"
)]}), exec_properties={'infer_feature_shape': 1, 'exclude_splits': '[]'}, execution_output_uri='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/executor_execution/15/executor_output.pb', stateful_working_dir='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/stateful_working_dir/2022-02-03T11:10:48.556314', tmp_dir='./tfx_pipeline_output/my_pipeline/SchemaGen/.system/executor_execution/15/.temp/', pipeline_node=node_info {
type {
name: "tfx.components.schema_gen.component.SchemaGen"
base_type: PROCESS
}
id: "SchemaGen"
}
contexts {
contexts {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
contexts {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:48.556314"
}
}
}
contexts {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.SchemaGen"
}
}
}
}
inputs {
inputs {
key: "statistics"
value {
channels {
producer_node_query {
id: "StatisticsGen"
}
context_queries {
type {
name: "pipeline"
}
name {
field_value {
string_value: "my_pipeline"
}
}
}
context_queries {
type {
name: "pipeline_run"
}
name {
field_value {
string_value: "2022-02-03T11:10:48.556314"
}
}
}
context_queries {
type {
name: "node"
}
name {
field_value {
string_value: "my_pipeline.StatisticsGen"
}
}
}
artifact_query {
type {
name: "ExampleStatistics"
base_type: STATISTICS
}
}
output_key: "statistics"
}
min_count: 1
}
}
}
outputs {
outputs {
key: "schema"
value {
artifact_spec {
type {
name: "Schema"
}
}
}
}
}
parameters {
parameters {
key: "exclude_splits"
value {
field_value {
string_value: "[]"
}
}
}
parameters {
key: "infer_feature_shape"
value {
field_value {
int_value: 1
}
}
}
}
upstream_nodes: "StatisticsGen"
execution_options {
caching_options {
}
}
, pipeline_info=id: "my_pipeline"
, pipeline_run_id='2022-02-03T11:10:48.556314')
INFO:absl:Processing schema from statistics for split train.
INFO:absl:Processing schema from statistics for split eval.
INFO:absl:Schema written to ./tfx_pipeline_output/my_pipeline/SchemaGen/schema/15/schema.pbtxt.
INFO:absl:Cleaning up stateless execution info.
INFO:absl:Execution 15 succeeded.
INFO:absl:Cleaning up stateful execution info.
INFO:absl:Publishing output artifacts defaultdict(<class 'list'>, {'schema': [Artifact(artifact: uri: "./tfx_pipeline_output/my_pipeline/SchemaGen/schema/15"
custom_properties {
key: "name"
value {
string_value: "my_pipeline:2022-02-03T11:10:48.556314:SchemaGen:schema:0"
}
}
custom_properties {
key: "tfx_version"
value {
string_value: "1.6.0"
}
}
, artifact_type: name: "Schema"
)]}) for execution 15
INFO:absl:MetadataStore with DB connection initialized
INFO:absl:Component SchemaGen is finished.
ตัวยึดตำแหน่ง36 คุณควรจะสามารถค้นหาโมเดลใหม่ของคุณได้ที่ SERVING_MODEL_DIR
ขั้นตอนที่ 6 (ไม่บังคับ) ปรับใช้ไปป์ไลน์ของคุณกับ Kubeflow Pipelines บน GCP
ดังที่ได้กล่าวไว้ก่อนหน้านี้ local_runner.py นั้นดีสำหรับการดีบักหรือเพื่อการพัฒนา แต่ไม่ใช่ทางออกที่ดีที่สุดสำหรับปริมาณงานการผลิต ในขั้นตอนนี้ เราจะปรับใช้ไปป์ไลน์กับ Kubeflow Pipelines บน Google Cloud
การตระเตรียม
เราต้องการ kfp python และโปรแกรม skaffold เพื่อปรับใช้ไปป์ไลน์กับคลัสเตอร์ Kubeflow Pipelines
pip install --upgrade -q kfp# Download skaffold and set it executable.curl -Lo skaffold https://storage.googleapis.com/skaffold/releases/latest/skaffold-linux-amd64 && chmod +x skaffold
คุณต้องย้าย skaffold binary ไปยังตำแหน่งที่เชลล์ของคุณสามารถค้นหาได้ หรือคุณสามารถระบุพาธไปยัง skaffold เมื่อคุณรัน tfx binary ด้วย --skaffold-cmd flag
# Move skaffold binary into your pathmv skaffold /home/jupyter/.local/bin/
mv: cannot move 'skaffold' to '/home/jupyter/.local/bin/': No such file or directoryตัวยึดตำแหน่ง39
คุณต้องมีคลัสเตอร์ Kubeflow Pipelines เพื่อเรียกใช้ไปป์ไลน์ โปรดปฏิบัติตามขั้นตอนที่ 1 และ 2 ใน TFX บนบทแนะนำไปป์ไลน์ Cloud AI Platform
เมื่อคลัสเตอร์ของคุณพร้อม ให้เปิดแดชบอร์ดไปป์ไลน์โดยคลิก เปิดแดชบอร์ดไปป์ไลน์ ใน หน้า Pipelines ของคอนโซลระบบคลาวด์ของ Google URL ของหน้านี้คือ ENDPOINT เพื่อขอให้เรียกใช้ไปป์ไลน์ ค่าปลายทางคือทุกอย่างใน URL หลัง https:// สูงสุด และรวมถึง googleusercontent.com วางปลายทางของคุณไปยังบล็อกโค้ดต่อไปนี้
ENDPOINT='' # Enter your ENDPOINT here.
ในการรันโค้ดของเราในคลัสเตอร์ Kubeflow Pipelines เราจำเป็นต้องแพ็คโค้ดของเราลงในอิมเมจคอนเทนเนอร์ รูปภาพจะถูกสร้างขึ้นโดยอัตโนมัติในขณะที่ปรับใช้ไปป์ไลน์ของเรา และคุณจะต้องตั้งชื่อและรีจิสตรีคอนเทนเนอร์สำหรับอิมเมจของคุณเท่านั้น ในตัวอย่างของเรา เราจะใช้ รีจิสทรีของ Google Container และตั้งชื่อเป็น tfx-pipeline
# Read GCP project id from env.
shell_output=!gcloud config list --format 'value(core.project)' 2>/dev/null
GOOGLE_CLOUD_PROJECT=shell_output[0]
# Docker image name for the pipeline image.
CUSTOM_TFX_IMAGE='gcr.io/' + GOOGLE_CLOUD_PROJECT + '/tfx-pipeline'
ตั้งค่าตำแหน่งข้อมูล
ข้อมูลของคุณควรเข้าถึงได้จากคลัสเตอร์ Kubeflow Pipelines หากคุณใช้ข้อมูลในสภาพแวดล้อมภายในของคุณ คุณอาจต้องอัปโหลดไปยังที่จัดเก็บข้อมูลระยะไกล เช่น Google Cloud Storage ตัวอย่างเช่น เราสามารถอัปโหลดข้อมูลเพนกวินไปยังบัคเก็ตเริ่มต้น ซึ่งสร้างขึ้นโดยอัตโนมัติเมื่อมีการปรับใช้คลัสเตอร์ Kubeflow Pipelines ดังนี้
gsutil cp data/data.csv gs://{GOOGLE_CLOUD_PROJECT}-kubeflowpipelines-default/tfx-template/data/penguin/
Copying file://data/data.csv [Content-Type=text/csv]... NotFoundException: 404 The destination bucket gs://tf-benchmark-dashboard-kubeflowpipelines-default does not exist or the write to the destination must be restartedตัวยึดตำแหน่ง43
อัปเดตตำแหน่งข้อมูลที่เก็บไว้ที่ DATA_PATH ใน kubeflow_runner.py
หากคุณกำลังใช้ BigQueryExampleGen คุณไม่จำเป็นต้องอัปโหลดไฟล์ข้อมูล แต่โปรดตรวจสอบให้แน่ใจว่า kubeflow_runner.py ใช้การ query เดียวกันและอาร์กิวเมนต์ beam_pipeline_args สำหรับฟังก์ชัน pipeline.create_pipeline()
ปรับใช้ไปป์ไลน์
หากทุกอย่างพร้อม คุณสามารถสร้างไพพ์ไลน์โดยใช้คำสั่ง tfx pipeline create
!tfx pipeline create \
--engine=kubeflow \
--pipeline-path=kubeflow_runner.py \
--endpoint={ENDPOINT} \
--build-target-image={CUSTOM_TFX_IMAGE}
CLI [Error] --build-target-image flag was DELETED. You should specify the build target image at the `KubeflowDagRunnerConfig` class instead, and use --build-image flag without argument to build a container image when creating or updating a pipeline.
ตอนนี้เริ่มดำเนินการรันด้วยไปป์ไลน์ที่สร้างขึ้นใหม่โดยใช้คำสั่ง tfx run create
tfx run create --engine=kubeflow --pipeline-name={PIPELINE_NAME} --endpoint={ENDPOINT}
CLI
Creating a run for pipeline: my_pipeline
Failed to load kube config.
Traceback (most recent call last):
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/connection.py", line 175, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/util/connection.py", line 95, in create_connection
raise err
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/util/connection.py", line 85, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/connectionpool.py", line 710, in urlopen
chunked=chunked,
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/connection.py", line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "/usr/lib/python3.7/http/client.py", line 1256, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1302, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1251, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.7/http/client.py", line 1030, in _send_output
self.send(msg)
File "/usr/lib/python3.7/http/client.py", line 970, in send
self.connect()
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/connection.py", line 205, in connect
conn = self._new_conn()
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/connection.py", line 187, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7ff729e34190>: Failed to establish a new connection: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmpfs/src/tf_docs_env/bin/tfx", line 8, in <module>
sys.exit(cli_group())
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/tfx/tools/cli/commands/run.py", line 94, in create_run
handler = handler_factory.create_handler(ctx.flags_dict)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/tfx/tools/cli/handler/handler_factory.py", line 93, in create_handler
return kubeflow_handler.KubeflowHandler(flags_dict)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/tfx/tools/cli/handler/kubeflow_handler.py", line 62, in __init__
namespace=self.flags_dict[labels.NAMESPACE])
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/kfp/_client.py", line 197, in __init__
if not self._context_setting['namespace'] and self.get_kfp_healthz(
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/kfp/_client.py", line 411, in get_kfp_healthz
response = self._healthz_api.get_healthz()
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/kfp_server_api/api/healthz_service_api.py", line 63, in get_healthz
return self.get_healthz_with_http_info(**kwargs) # noqa: E501
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/kfp_server_api/api/healthz_service_api.py", line 148, in get_healthz_with_http_info
collection_formats=collection_formats)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/kfp_server_api/api_client.py", line 369, in call_api
_preload_content, _request_timeout, _host)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/kfp_server_api/api_client.py", line 185, in __call_api
_request_timeout=_request_timeout)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/kfp_server_api/api_client.py", line 393, in request
headers=headers)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/kfp_server_api/rest.py", line 234, in GET
query_params=query_params)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/kfp_server_api/rest.py", line 212, in request
headers=headers)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/request.py", line 75, in request
method, url, fields=fields, headers=headers, **urlopen_kw
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/request.py", line 96, in request_encode_url
return self.urlopen(method, url, **extra_kw)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/poolmanager.py", line 375, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/connectionpool.py", line 826, in urlopen
**response_kw
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/connectionpool.py", line 826, in urlopen
**response_kw
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/connectionpool.py", line 826, in urlopen
**response_kw
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/connectionpool.py", line 786, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /apis/v1beta1/healthz (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ff729e34190>: Failed to establish a new connection: [Errno 111] Connection refused'))
หรือจะเรียกใช้ไปป์ไลน์ในแดชบอร์ด Kubeflow Pipelines ก็ได้ การเรียกใช้ใหม่จะแสดงอยู่ภายใต้การ Experiments ในแดชบอร์ดไปป์ไลน์ของ Kubeflow การคลิกเข้าสู่การทดสอบจะทำให้คุณสามารถติดตามความคืบหน้าและเห็นภาพสิ่งประดิษฐ์ที่สร้างขึ้นระหว่างการดำเนินการ
หากคุณสนใจที่จะใช้งานไปป์ไลน์บน Kubeflow Pipelines โปรดดูคำแนะนำเพิ่มเติมใน TFX บนบทแนะนำไปป์ไลน์ Cloud AI Platform
การทำความสะอาด
หากต้องการล้างทรัพยากร Google Cloud ทั้งหมดที่ใช้ในขั้นตอนนี้ คุณสามารถ ลบโปรเจ็กต์ Google Cloud ที่ คุณใช้สำหรับบทช่วยสอนได้
อีกวิธีหนึ่ง คุณสามารถล้างข้อมูลทรัพยากรแต่ละรายการโดยไปที่แต่ละคอนโซล:
ดูบน TensorFlow.org
ทำงานใน Google Colab
ดูแหล่งที่มาบน GitHub
ดาวน์โหลดโน๊ตบุ๊ค