บทนำ
เอกสารนี้จะให้คำแนะนำในการสร้าง TensorFlow ขยาย (TFX) ท่อโดยใช้แม่แบบที่มีให้กับแพคเกจ TFX หลาม คำแนะนำจำนวนมากคือคำสั่งเชลล์ของ Linux ซึ่งจะทำงานบนอินสแตนซ์ AI Platform Notebooks สอดคล้อง Jupyter เซลล์รหัสโน๊ตบุ๊คที่เรียกคำสั่งที่ใช้ ! ถูกจัดหา.
คุณจะสร้างท่อส่งโดยใช้ รถแท็กซี่การเดินทางชุดข้อมูลที่ ปล่อยออกมาจากเมืองชิคาโก เราขอแนะนำให้คุณลองสร้างไปป์ไลน์ของคุณเองโดยใช้ชุดข้อมูลโดยใช้ไปป์ไลน์นี้เป็นพื้นฐาน
ขั้นตอนที่ 1. ตั้งค่าสภาพแวดล้อมของคุณ
AI Platform Pipelines จะเตรียมสภาพแวดล้อมการพัฒนาเพื่อสร้างไปป์ไลน์ และคลัสเตอร์ Kubeflow Pipeline เพื่อเรียกใช้ไปป์ไลน์ที่สร้างขึ้นใหม่
ติดตั้ง tfx แพคเกจหลามกับ kfp ความต้องการพิเศษ
import sys
# Use the latest version of pip.
!pip install --upgrade pip
# Install tfx and kfp Python packages.
!pip install --upgrade "tfx[kfp]<2"
มาดูเวอร์ชันของ TFX กัน
python3 -c "from tfx import version ; print('TFX version: {}'.format(version.__version__))"
TFX version: 0.29.0
ใน AI แพลตฟอร์มท่อ TFX ทำงานในสภาพแวดล้อมที่ Kubernetes โฮสต์ที่ใช้ Kubeflow วางท่อ
มาตั้งค่าตัวแปรสภาพแวดล้อมบางอย่างเพื่อใช้ Kubeflow Pipelines
ขั้นแรก รับรหัสโปรเจ็กต์ GCP
# Read GCP project id from env.
shell_output=!gcloud config list --format 'value(core.project)' 2>/dev/null
GOOGLE_CLOUD_PROJECT=shell_output[0]
%env GOOGLE_CLOUD_PROJECT={GOOGLE_CLOUD_PROJECT}
print("GCP project ID:" + GOOGLE_CLOUD_PROJECT)
env: GOOGLE_CLOUD_PROJECT=tf-benchmark-dashboard GCP project ID:tf-benchmark-dashboard
เราจำเป็นต้องเข้าถึงคลัสเตอร์ KFP ของคุณด้วย คุณสามารถเข้าถึงได้ใน Google Cloud Console ของคุณภายใต้เมนู "แพลตฟอร์ม AI > ไปป์ไลน์" สามารถค้นหา "จุดปลาย" ของคลัสเตอร์ KFP ได้จาก URL ของแดชบอร์ดไปป์ไลน์ หรือคุณสามารถรับได้จาก URL ของหน้าเริ่มต้นใช้งานที่คุณเปิดสมุดบันทึกนี้ ลองสร้าง ENDPOINT ตัวแปรสภาพแวดล้อมและการตั้งค่าไปยังปลายทางคลัสเตอร์ KFP ENDPOINT ควรมีเฉพาะส่วนชื่อโฮสต์ของ URL ตัวอย่างเช่นถ้า URL ของแดชบอร์ด KFP เป็น <a href="https://1e9deb537390ca22-dot-asia-east1.pipelines.googleusercontent.com/#/start">https://1e9deb537390ca22-dot-asia-east1.pipelines.googleusercontent.com/#/start</a> ค่าปลายทางกลายเป็น 1e9deb537390ca22-dot-asia-east1.pipelines.googleusercontent.com
# This refers to the KFP cluster endpoint
ENDPOINT='' # Enter your ENDPOINT here.
if not ENDPOINT:
from absl import logging
logging.error('Set your ENDPOINT in this cell.')
ERROR:absl:Set your ENDPOINT in this cell.
ตั้งชื่อภาพเป็น tfx-pipeline ภายใต้โครงการ GCP ปัจจุบัน
# Docker image name for the pipeline image.
CUSTOM_TFX_IMAGE='gcr.io/' + GOOGLE_CLOUD_PROJECT + '/tfx-pipeline'
และเสร็จแล้ว เราพร้อมที่จะสร้างไปป์ไลน์
ขั้นตอนที่ 2 คัดลอกเทมเพลตที่กำหนดไว้ล่วงหน้าไปยังไดเร็กทอรีโครงการของคุณ
ในขั้นตอนนี้ เราจะสร้างไดเร็กทอรีและไฟล์โปรเจ็กต์ไปป์ไลน์ที่ใช้งานได้ โดยการคัดลอกไฟล์เพิ่มเติมจากเทมเพลตที่กำหนดไว้ล่วงหน้า
คุณอาจจะทำให้ท่อส่งชื่อที่แตกต่างกันโดยการเปลี่ยน PIPELINE_NAME ด้านล่าง นี่จะกลายเป็นชื่อของไดเร็กทอรีโครงการที่จะใส่ไฟล์ของคุณ
PIPELINE_NAME="my_pipeline"
import os
PROJECT_DIR=os.path.join(os.path.expanduser("~"),"imported",PIPELINE_NAME)
TFX รวมถึง taxi แม่แบบกับแพคเกจหลาม TFX หากคุณกำลังวางแผนที่จะแก้ปัญหาการคาดคะเนแบบ point-wise รวมทั้งการจำแนกและการถดถอย คุณสามารถใช้เทมเพลตนี้เป็นจุดเริ่มต้นได้
tfx template copy CLI สำเนาคำสั่งที่กำหนดไว้ล่วงหน้าแฟ้มแม่แบบลงในไดเรกทอรีโครงการของคุณ
!tfx template copy \
--pipeline-name={PIPELINE_NAME} \
--destination-path={PROJECT_DIR} \
--model=taxi
CLI
Copying taxi pipeline template
kubeflow_runner.py -> /home/kbuilder/imported/my_pipeline/kubeflow_runner.py
kubeflow_v2_dag_runner.py -> /home/kbuilder/imported/my_pipeline/kubeflow_v2_dag_runner.py
features_test.py -> /home/kbuilder/imported/my_pipeline/models/features_test.py
model_test.py -> /home/kbuilder/imported/my_pipeline/models/estimator/model_test.py
constants.py -> /home/kbuilder/imported/my_pipeline/models/estimator/constants.py
model.py -> /home/kbuilder/imported/my_pipeline/models/estimator/model.py
__init__.py -> /home/kbuilder/imported/my_pipeline/models/estimator/__init__.py
model_test.py -> /home/kbuilder/imported/my_pipeline/models/keras/model_test.py
constants.py -> /home/kbuilder/imported/my_pipeline/models/keras/constants.py
model.py -> /home/kbuilder/imported/my_pipeline/models/keras/model.py
__init__.py -> /home/kbuilder/imported/my_pipeline/models/keras/__init__.py
preprocessing_test.py -> /home/kbuilder/imported/my_pipeline/models/preprocessing_test.py
preprocessing.py -> /home/kbuilder/imported/my_pipeline/models/preprocessing.py
__init__.py -> /home/kbuilder/imported/my_pipeline/models/__init__.py
features.py -> /home/kbuilder/imported/my_pipeline/models/features.py
pipeline.py -> /home/kbuilder/imported/my_pipeline/pipeline/pipeline.py
configs.py -> /home/kbuilder/imported/my_pipeline/pipeline/configs.py
__init__.py -> /home/kbuilder/imported/my_pipeline/pipeline/__init__.py
local_runner.py -> /home/kbuilder/imported/my_pipeline/local_runner.py
model_analysis.ipynb -> /home/kbuilder/imported/my_pipeline/model_analysis.ipynb
__init__.py -> /home/kbuilder/imported/my_pipeline/__init__.py
data_validation.ipynb -> /home/kbuilder/imported/my_pipeline/data_validation.ipynb
.gitignore -> /home/kbuilder/imported/my_pipeline/.gitignore
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/template.py", line 73, in copy
template_handler.copy_template(ctx.flags_dict)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/tfx/tools/cli/handler/template_handler.py", line 185, in copy_template
fileio.copy(src_path, dst_path)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/tfx/dsl/io/fileio.py", line 51, in copy
src_fs.copy(src, dst, overwrite=overwrite)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/tfx/dsl/io/plugins/tensorflow_gfile.py", line 48, in copy
tf.io.gfile.copy(src, dst, overwrite=overwrite)
File "/tmpfs/src/tf_docs_env/lib/python3.7/site-packages/tensorflow/python/lib/io/file_io.py", line 516, in copy_v2
compat.path_to_bytes(src), compat.path_to_bytes(dst), overwrite)
tensorflow.python.framework.errors_impl.AlreadyExistsError: file already exists
เปลี่ยนบริบทไดเรกทอรีทำงานในสมุดบันทึกนี้เป็นไดเรกทอรีโครงการ
%cd {PROJECT_DIR}
/home/kbuilder/imported/my_pipeline
ขั้นตอนที่ 3 เรียกดูไฟล์ต้นฉบับที่คัดลอกของคุณ
เทมเพลต TFX มีไฟล์นั่งร้านพื้นฐานสำหรับสร้างไปป์ไลน์ ซึ่งรวมถึงซอร์สโค้ด Python ข้อมูลตัวอย่าง และ Jupyter Notebooks เพื่อวิเคราะห์เอาต์พุตของไปป์ไลน์ taxi แม่แบบใช้ชุดเดียวกันชิคาโกแท็กซี่และรุ่น ML เป็น Airflow กวดวิชา
ต่อไปนี้คือข้อมูลเบื้องต้นเกี่ยวกับไฟล์ Python แต่ละไฟล์
-
pipeline- ไดเรกทอรีนี้มีความหมายของท่อ-
configs.py- กำหนดค่าคงที่พบบ่อยสำหรับนักวิ่งท่อ -
pipeline.py- กำหนดส่วนประกอบ TFX และท่อ
-
-
models- ไดเรกทอรีนี้ประกอบด้วย ML นิยามรูปแบบ-
features.py,features_test.py- กำหนดให้บริการสำหรับรูปแบบ -
preprocessing.py,preprocessing_test.py- กำหนด preprocessing งานโดยใช้tf::Transform -
estimator- ไดเรกทอรีนี้มีรูปแบบการประมาณการตาม-
constants.py- กำหนดค่าคงที่ของรูปแบบ -
model.py,model_test.py- กำหนดรูปแบบ DNN ใช้ประมาณการ TF
-
-
keras- ไดเรกทอรีนี้มีรูปแบบการ Keras ตาม-
constants.py- กำหนดค่าคงที่ของรูปแบบ -
model.py,model_test.py- กำหนดรูปแบบการใช้ DNN Keras
-
-
-
local_runner.py,kubeflow_runner.py- กำหนดวิ่งสำหรับเครื่องยนต์ประสานแต่ละ
คุณอาจพบว่ามีไฟล์บางอย่างกับ _test.py ในชื่อของพวกเขา นี่คือการทดสอบหน่วยของไปป์ไลน์ และขอแนะนำให้เพิ่มการทดสอบหน่วยเพิ่มเติมเมื่อคุณใช้ไพพ์ไลน์ของคุณเอง คุณสามารถเรียกใช้การทดสอบหน่วยโดยการจัดหาชื่อโมดูลของไฟล์ที่ทดสอบด้วย -m ธง คุณมักจะได้รับชื่อโมดูลโดยการลบ .py ขยายและการเปลี่ยน / . . ตัวอย่างเช่น:
{sys.executable} -m models.features_test{sys.executable} -m models.keras.model_test
Running tests under Python 3.7.5: /tmpfs/src/tf_docs_env/bin/python [ RUN ] FeaturesTest.testNumberOfBucketFeatureBucketCount INFO:tensorflow:time(__main__.FeaturesTest.testNumberOfBucketFeatureBucketCount): 0.0s I1204 11:33:54.064224 139808961349440 test_util.py:2076] time(__main__.FeaturesTest.testNumberOfBucketFeatureBucketCount): 0.0s [ OK ] FeaturesTest.testNumberOfBucketFeatureBucketCount [ RUN ] FeaturesTest.testTransformedNames INFO:tensorflow:time(__main__.FeaturesTest.testTransformedNames): 0.0s I1204 11:33:54.064666 139808961349440 test_util.py:2076] time(__main__.FeaturesTest.testTransformedNames): 0.0s [ OK ] FeaturesTest.testTransformedNames [ RUN ] FeaturesTest.test_session [ SKIPPED ] FeaturesTest.test_session ---------------------------------------------------------------------- Ran 3 tests in 0.001s OK (skipped=1) Running tests under Python 3.7.5: /tmpfs/src/tf_docs_env/bin/python [ RUN ] ModelTest.testBuildKerasModel 2021-12-04 11:33:57.507456: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'libcusolver.so.10'; dlerror: libcusolver.so.10: cannot open shared object file: No such file or directory 2021-12-04 11:33:57.508566: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1757] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform. Skipping registering GPU devices... I1204 11:33:57.581331 139740839778112 layer_utils.py:191] Model: "model" I1204 11:33:57.581501 139740839778112 layer_utils.py:192] __________________________________________________________________________________________________ I1204 11:33:57.581558 139740839778112 layer_utils.py:189] Layer (type) Output Shape Param # Connected to I1204 11:33:57.581596 139740839778112 layer_utils.py:194] ================================================================================================== I1204 11:33:57.581741 139740839778112 layer_utils.py:189] pickup_latitude_xf (InputLayer) [(None,)] 0 I1204 11:33:57.581793 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.581883 139740839778112 layer_utils.py:189] trip_miles_xf (InputLayer) [(None,)] 0 I1204 11:33:57.581926 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.582010 139740839778112 layer_utils.py:189] trip_start_hour_xf (InputLayer) [(None,)] 0 I1204 11:33:57.582052 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.582189 139740839778112 layer_utils.py:189] dense_features (DenseFeatures) (None, 1) 0 pickup_latitude_xf[0][0] I1204 11:33:57.582241 139740839778112 layer_utils.py:189] trip_miles_xf[0][0] I1204 11:33:57.582280 139740839778112 layer_utils.py:189] trip_start_hour_xf[0][0] I1204 11:33:57.582315 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.582462 139740839778112 layer_utils.py:189] dense (Dense) (None, 1) 2 dense_features[0][0] I1204 11:33:57.582518 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.582629 139740839778112 layer_utils.py:189] dense_1 (Dense) (None, 1) 2 dense[0][0] I1204 11:33:57.582674 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.582824 139740839778112 layer_utils.py:189] dense_features_1 (DenseFeatures (None, 34) 0 pickup_latitude_xf[0][0] I1204 11:33:57.582879 139740839778112 layer_utils.py:189] trip_miles_xf[0][0] I1204 11:33:57.582921 139740839778112 layer_utils.py:189] trip_start_hour_xf[0][0] I1204 11:33:57.582957 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.583053 139740839778112 layer_utils.py:189] concatenate (Concatenate) (None, 35) 0 dense_1[0][0] I1204 11:33:57.583099 139740839778112 layer_utils.py:189] dense_features_1[0][0] I1204 11:33:57.583143 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.583260 139740839778112 layer_utils.py:189] dense_2 (Dense) (None, 1) 36 concatenate[0][0] I1204 11:33:57.583309 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.583389 139740839778112 layer_utils.py:189] tf.compat.v1.squeeze (TFOpLambd (None,) 0 dense_2[0][0] I1204 11:33:57.583432 139740839778112 layer_utils.py:256] ================================================================================================== I1204 11:33:57.583687 139740839778112 layer_utils.py:267] Total params: 40 I1204 11:33:57.583751 139740839778112 layer_utils.py:268] Trainable params: 40 I1204 11:33:57.583794 139740839778112 layer_utils.py:269] Non-trainable params: 0 I1204 11:33:57.583832 139740839778112 layer_utils.py:270] __________________________________________________________________________________________________ I1204 11:33:57.649701 139740839778112 layer_utils.py:191] Model: "model_1" I1204 11:33:57.649825 139740839778112 layer_utils.py:192] __________________________________________________________________________________________________ I1204 11:33:57.649878 139740839778112 layer_utils.py:189] Layer (type) Output Shape Param # Connected to I1204 11:33:57.649932 139740839778112 layer_utils.py:194] ================================================================================================== I1204 11:33:57.650066 139740839778112 layer_utils.py:189] pickup_latitude_xf (InputLayer) [(None,)] 0 I1204 11:33:57.650120 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.650207 139740839778112 layer_utils.py:189] trip_miles_xf (InputLayer) [(None,)] 0 I1204 11:33:57.650259 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.650356 139740839778112 layer_utils.py:189] trip_start_hour_xf (InputLayer) [(None,)] 0 I1204 11:33:57.650398 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.650552 139740839778112 layer_utils.py:189] dense_features_2 (DenseFeatures (None, 1) 0 pickup_latitude_xf[0][0] I1204 11:33:57.650603 139740839778112 layer_utils.py:189] trip_miles_xf[0][0] I1204 11:33:57.650644 139740839778112 layer_utils.py:189] trip_start_hour_xf[0][0] I1204 11:33:57.650682 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.650812 139740839778112 layer_utils.py:189] dense_3 (Dense) (None, 1) 2 dense_features_2[0][0] I1204 11:33:57.650864 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.651007 139740839778112 layer_utils.py:189] dense_features_3 (DenseFeatures (None, 34) 0 pickup_latitude_xf[0][0] I1204 11:33:57.651061 139740839778112 layer_utils.py:189] trip_miles_xf[0][0] I1204 11:33:57.651102 139740839778112 layer_utils.py:189] trip_start_hour_xf[0][0] I1204 11:33:57.651146 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.651229 139740839778112 layer_utils.py:189] concatenate_1 (Concatenate) (None, 35) 0 dense_3[0][0] I1204 11:33:57.651274 139740839778112 layer_utils.py:189] dense_features_3[0][0] I1204 11:33:57.651311 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.651462 139740839778112 layer_utils.py:189] dense_4 (Dense) (None, 1) 36 concatenate_1[0][0] I1204 11:33:57.651547 139740839778112 layer_utils.py:258] __________________________________________________________________________________________________ I1204 11:33:57.651632 139740839778112 layer_utils.py:189] tf.compat.v1.squeeze_1 (TFOpLam (None,) 0 dense_4[0][0] I1204 11:33:57.651675 139740839778112 layer_utils.py:256] ================================================================================================== I1204 11:33:57.651959 139740839778112 layer_utils.py:267] Total params: 38 I1204 11:33:57.652019 139740839778112 layer_utils.py:268] Trainable params: 38 I1204 11:33:57.652061 139740839778112 layer_utils.py:269] Non-trainable params: 0 I1204 11:33:57.652098 139740839778112 layer_utils.py:270] __________________________________________________________________________________________________ INFO:tensorflow:time(__main__.ModelTest.testBuildKerasModel): 0.84s I1204 11:33:57.652639 139740839778112 test_util.py:2076] time(__main__.ModelTest.testBuildKerasModel): 0.84s [ OK ] ModelTest.testBuildKerasModel [ RUN ] ModelTest.test_session [ SKIPPED ] ModelTest.test_session ---------------------------------------------------------------------- Ran 2 tests in 0.836s OK (skipped=1)
ขั้นตอนที่ 4 เรียกใช้ไปป์ไลน์ TFX แรกของคุณ
ส่วนประกอบในท่อ TFX จะสร้างผลสำหรับแต่ละวิ่งเป็น สิ่งประดิษฐ์ ML Metadata และพวกเขาจะต้องเก็บไว้ที่อื่น คุณสามารถใช้ที่เก็บข้อมูลใดก็ได้ที่คลัสเตอร์ KFP สามารถเข้าถึงได้ และสำหรับตัวอย่างนี้ เราจะใช้ Google Cloud Storage (GCS) ควรสร้างที่เก็บข้อมูล GCS เริ่มต้นโดยอัตโนมัติ ชื่อของมันจะเป็น <your-project-id>-kubeflowpipelines-default
มาอัปโหลดข้อมูลตัวอย่างของเราไปที่บัคเก็ต GCS เพื่อให้เรานำไปใช้ในไปป์ไลน์ได้ในภายหลัง
gsutil cp data/data.csv gs://{GOOGLE_CLOUD_PROJECT}-kubeflowpipelines-default/tfx-template/data/taxi/data.csv
BucketNotFoundException: 404 gs://tf-benchmark-dashboard-kubeflowpipelines-default bucket does not exist.
ขอสร้างท่อ TFX ใช้ tfx pipeline create คำสั่ง
!tfx pipeline create --pipeline-path=kubeflow_runner.py --endpoint={ENDPOINT} \
--build-image
CLI Usage: tfx pipeline create [OPTIONS] Try 'tfx pipeline create --help' for help. Error: no such option: --build-image
ขณะที่การสร้างท่อ Dockerfile จะถูกสร้างขึ้นเพื่อสร้างภาพเทียบท่า อย่าลืมเพิ่มลงในระบบควบคุมต้นทาง (เช่น git) พร้อมกับไฟล์ต้นทางอื่นๆ
ตอนนี้เริ่มต้นการดำเนินการดำเนินการกับท่อที่สร้างขึ้นใหม่โดยใช้ tfx run create คำสั่ง
tfx run create --pipeline-name={PIPELINE_NAME} --endpoint={ENDPOINT}
CLI Creating a run for pipeline: my_pipeline Detected Beam. [WARNING] Default engine will be changed to "local" in the near future. Use --engine flag if you intend to use a different orchestrator. Pipeline "my_pipeline" does not exist.
หรือจะเรียกใช้ไปป์ไลน์ใน KFP Dashboard ก็ได้ การดำเนินการใหม่จะแสดงอยู่ภายใต้การทดสอบในแดชบอร์ด KFP การคลิกเข้าสู่การทดสอบจะทำให้คุณสามารถติดตามความคืบหน้าและเห็นภาพสิ่งประดิษฐ์ที่สร้างขึ้นระหว่างการดำเนินการ
อย่างไรก็ตาม เราแนะนำให้ไปที่แดชบอร์ด KFP คุณเข้าถึง KFP Dashboard ได้จากเมนูไปป์ไลน์ Cloud AI Platform ใน Google Cloud Console เมื่อคุณไปที่แดชบอร์ด คุณจะสามารถค้นหาไปป์ไลน์ และเข้าถึงข้อมูลมากมายเกี่ยวกับไปป์ไลน์ ตัวอย่างเช่นคุณสามารถค้นหาการวิ่งของคุณภายใต้การทดลองเมนูและเมื่อคุณเปิดดำเนินการของคุณทำงานได้ภายใต้การทดลองคุณสามารถหาสิ่งประดิษฐ์ทั้งหมดของคุณจากท่อภายใต้เมนูสิ่งประดิษฐ์
สาเหตุหลักของความล้มเหลวประการหนึ่งคือปัญหาที่เกี่ยวข้องกับการอนุญาต โปรดตรวจสอบว่าคลัสเตอร์ KFP ของคุณมีสิทธิ์เข้าถึง Google Cloud API นี้สามารถกำหนดค่า เมื่อคุณสร้างคลัสเตอร์ KFP ใน GCP หรือดู เอกสารการแก้ไขปัญหาใน GCP
ขั้นตอนที่ 5. เพิ่มส่วนประกอบสำหรับการตรวจสอบข้อมูล
ในขั้นตอนนี้คุณจะเพิ่มชิ้นส่วนสำหรับการตรวจสอบข้อมูลรวมทั้ง StatisticsGen , SchemaGen และ ExampleValidator หากคุณมีความสนใจในการตรวจสอบข้อมูลโปรดดูที่ เริ่มต้นด้วยการตรวจสอบข้อมูล Tensorflow
ดับเบิลคลิกเพื่อเปลี่ยนไดเรกทอรีไปยัง
pipelineและดับเบิลคลิกอีกครั้งเพื่อเปิดpipeline.pyค้นหาและ uncomment 3 สายที่เพิ่มStatisticsGen,SchemaGenและExampleValidatorการท่อ (เคล็ดลับ: การค้นหาสำหรับความคิดเห็นที่มีTODO(step 5):) ตรวจสอบให้แน่ใจว่าได้บันทึกpipeline.pyหลังจากที่คุณแก้ไขมัน
ตอนนี้คุณต้องอัปเดตไปป์ไลน์ที่มีอยู่ด้วยข้อกำหนดไปป์ไลน์ที่แก้ไข ใช้ tfx pipeline update คำสั่งในการปรับปรุงท่อของคุณตามด้วย tfx run create คำสั่งในการสร้างการดำเนินการการทำงานใหม่ของท่อที่อัปเดตของคุณ
# Update the pipeline
!tfx pipeline update \
--pipeline-path=kubeflow_runner.py \
--endpoint={ENDPOINT}
# You can run the pipeline the same way.
!tfx run create --pipeline-name {PIPELINE_NAME} --endpoint={ENDPOINT}
CLI Updating pipeline Detected Beam. [WARNING] Default engine will be changed to "local" in the near future. Use --engine flag if you intend to use a different orchestrator. beam runner not found in dsl. CLI Creating a run for pipeline: my_pipeline Detected Beam. [WARNING] Default engine will be changed to "local" in the near future. Use --engine flag if you intend to use a different orchestrator. Pipeline "my_pipeline" does not exist.
ตรวจสอบเอาต์พุตไปป์ไลน์
ไปที่แดชบอร์ด KFP เพื่อค้นหาเอาต์พุตไปป์ไลน์ในหน้าสำหรับการรันไปป์ไลน์ของคุณ คลิกที่แท็บการทดลองทางด้านซ้ายและวิ่งทั้งหมดในหน้าการทดสอบ คุณควรจะสามารถค้นหาการทำงานล่าสุดภายใต้ชื่อไปป์ไลน์ของคุณ
ขั้นตอนที่ 6 เพิ่มส่วนประกอบสำหรับการฝึกอบรม
ในขั้นตอนนี้คุณจะเพิ่มส่วนประกอบสำหรับการฝึกอบรมและการตรวจสอบรูปแบบรวมทั้ง Transform , Trainer , Resolver , Evaluator และ Pusher
ดับเบิลคลิกเพื่อเปิด
pipeline.pyค้นหาและ uncomment 5 สายที่เพิ่มTransform,Trainer,Resolver,EvaluatorและPusherการท่อ (เคล็ดลับ: การค้นหาTODO(step 6):)
อย่างที่คุณทำก่อนหน้านี้ ตอนนี้คุณต้องอัปเดตไปป์ไลน์ที่มีอยู่ด้วยข้อกำหนดไปป์ไลน์ที่แก้ไข คำแนะนำที่เป็นเช่นเดียวกับขั้นตอนที่ 5. การปรับปรุงท่อโดยใช้ tfx pipeline update และสร้างการดำเนินการการดำเนินการโดยใช้ tfx run create
!tfx pipeline update \
--pipeline-path=kubeflow_runner.py \
--endpoint={ENDPOINT}
!tfx run create --pipeline-name {PIPELINE_NAME} --endpoint={ENDPOINT}
CLI Updating pipeline Detected Beam. [WARNING] Default engine will be changed to "local" in the near future. Use --engine flag if you intend to use a different orchestrator. beam runner not found in dsl. CLI Creating a run for pipeline: my_pipeline Detected Beam. [WARNING] Default engine will be changed to "local" in the near future. Use --engine flag if you intend to use a different orchestrator. Pipeline "my_pipeline" does not exist.
เมื่อการดำเนินการนี้เสร็จสิ้น คุณได้สร้างและรันไปป์ไลน์ TFX แรกของคุณในไปป์ไลน์ AI Platform แล้ว!
ขั้นตอนที่ 7 (อุปกรณ์เสริม) ลอง BigQueryExampleGen
BigQuery เป็น serverless ปรับขนาดได้สูงและคลังข้อมูลระบบคลาวด์ที่มีประสิทธิภาพ สามารถใช้ BigQuery เป็นแหล่งสำหรับตัวอย่างการฝึกอบรมใน TFX ในขั้นตอนนี้เราจะเพิ่ม BigQueryExampleGen การท่อ
ดับเบิลคลิกเพื่อเปิด
pipeline.pyแสดงความคิดเห็นออกCsvExampleGenและ uncomment บรรทัดซึ่งจะสร้างตัวอย่างของBigQueryExampleGenนอกจากนี้คุณยังต้องบรรทัดเหล่าqueryอาร์กิวเมนต์ของcreate_pipelineฟังก์ชั่น
เราจำเป็นต้องระบุว่าโครงการ GCP ที่จะใช้สำหรับ BigQuery และนี้จะทำโดยการตั้งค่า --project ใน beam_pipeline_args เมื่อมีการสร้างท่อ
ดับเบิลคลิกเพื่อเปิด
configs.pyuncomment นิยามของGOOGLE_CLOUD_REGION,BIG_QUERY_WITH_DIRECT_RUNNER_BEAM_PIPELINE_ARGSและBIG_QUERY_QUERYคุณควรแทนที่ค่าภูมิภาคในไฟล์นี้ด้วยค่าที่ถูกต้องสำหรับโปรเจ็กต์ GCP
เปลี่ยนไดเร็กทอรีขึ้นหนึ่งระดับ คลิกชื่อไดเร็กทอรีเหนือรายการไฟล์ ชื่อของไดเรกทอรีที่เป็นชื่อของท่อซึ่งเป็น
my_pipelineถ้าคุณไม่ได้เปลี่ยน
ดับเบิลคลิกเพื่อเปิด
kubeflow_runner.pyuncomment สองข้อโต้แย้งqueryและbeam_pipeline_argsสำหรับcreate_pipelineฟังก์ชั่น
ตอนนี้ไปป์ไลน์พร้อมที่จะใช้ BigQuery เป็นแหล่งตัวอย่างแล้ว อัปเดตไปป์ไลน์เหมือนเมื่อก่อนและสร้างการดำเนินการใหม่ตามที่เราทำในขั้นตอนที่ 5 และ 6
!tfx pipeline update \
--pipeline-path=kubeflow_runner.py \
--endpoint={ENDPOINT}
!tfx run create --pipeline-name {PIPELINE_NAME} --endpoint={ENDPOINT}
CLI Updating pipeline Detected Beam. [WARNING] Default engine will be changed to "local" in the near future. Use --engine flag if you intend to use a different orchestrator. beam runner not found in dsl. CLI Creating a run for pipeline: my_pipeline Detected Beam. [WARNING] Default engine will be changed to "local" in the near future. Use --engine flag if you intend to use a different orchestrator. Pipeline "my_pipeline" does not exist.
ขั้นตอนที่ 8 (อุปกรณ์เสริม) ลอง Dataflow กับ KFP
หลาย TFX ส่วนประกอบใช้ Apache บีม ที่จะใช้ท่อส่งข้อมูลแบบขนานและมันหมายความว่าคุณสามารถกระจายการประมวลผลข้อมูลปริมาณงานโดยใช้ Google Cloud Dataflow ในขั้นตอนนี้ เราจะตั้งค่า Kubeflow orchestrator ให้ใช้ dataflow เป็นแบ็คเอนด์การประมวลผลข้อมูลสำหรับ Apache Beam
ดับเบิลคลิกที่
pipelineไปยังไดเรกทอรีการเปลี่ยนแปลงและดับเบิลคลิกเพื่อเปิดconfigs.pyuncomment นิยามของGOOGLE_CLOUD_REGIONและDATAFLOW_BEAM_PIPELINE_ARGS
เปลี่ยนไดเร็กทอรีขึ้นหนึ่งระดับ คลิกชื่อไดเร็กทอรีเหนือรายการไฟล์ ชื่อของไดเรกทอรีที่เป็นชื่อของท่อซึ่งเป็น
my_pipelineถ้าคุณไม่ได้เปลี่ยน
ดับเบิลคลิกเพื่อเปิด
kubeflow_runner.pyuncommentbeam_pipeline_args(ยังให้แน่ใจว่าจะแสดงความคิดเห็นออกมาในปัจจุบันbeam_pipeline_argsที่คุณเพิ่มเข้าไปในขั้นตอนที่ 7)
ตอนนี้ไปป์ไลน์พร้อมที่จะใช้ Dataflow แล้ว อัปเดตไปป์ไลน์และสร้างการดำเนินการตามที่เราทำในขั้นตอนที่ 5 และ 6
!tfx pipeline update \
--pipeline-path=kubeflow_runner.py \
--endpoint={ENDPOINT}
!tfx run create --pipeline-name {PIPELINE_NAME} --endpoint={ENDPOINT}
CLI Updating pipeline Detected Beam. [WARNING] Default engine will be changed to "local" in the near future. Use --engine flag if you intend to use a different orchestrator. beam runner not found in dsl. CLI Creating a run for pipeline: my_pipeline Detected Beam. [WARNING] Default engine will be changed to "local" in the near future. Use --engine flag if you intend to use a different orchestrator. Pipeline "my_pipeline" does not exist.
คุณสามารถหางาน Dataflow คุณใน Dataflow ในคอนโซลเมฆ
ขั้นตอนที่ 9 (อุปกรณ์เสริม) ลองเมฆ AI การฝึกอบรมและแพลตฟอร์มการทำนายด้วย KFP
ทำงานร่วมกับหลาย TFX การจัดการบริการ GCP เช่น แพลตฟอร์ม AI เมฆสำหรับการฝึกอบรมและการทำนาย คุณสามารถตั้งค่าของคุณ Trainer องค์ประกอบที่จะใช้ระบบคลาวด์แพลตฟอร์มการฝึกอบรมเอไอซึ่งเป็นบริการที่มีการจัดการสำหรับการฝึกอบรมรุ่น ML นอกจากนี้เมื่อรูปแบบของคุณถูกสร้างขึ้นและพร้อมที่จะให้บริการคุณสามารถผลักดันรูปแบบของคุณที่จะทำนายเมฆ AI แพลตฟอร์มสำหรับการให้บริการ ในขั้นตอนนี้เราจะตั้งค่าของเรา Trainer และ Pusher องค์ประกอบที่จะใช้บริการคลาวด์เอไอแพลทฟอร์ม
ก่อนที่จะแก้ไขไฟล์แรกคุณอาจจะมีการเปิดใช้งานการฝึกอบรมเอไอแพลทฟอร์มและ Prediction API
ดับเบิลคลิกที่
pipelineไปยังไดเรกทอรีการเปลี่ยนแปลงและดับเบิลคลิกเพื่อเปิดconfigs.pyuncomment นิยามของGOOGLE_CLOUD_REGION,GCP_AI_PLATFORM_TRAINING_ARGSและGCP_AI_PLATFORM_SERVING_ARGSเราจะใช้ภาพภาชนะตัวเองของเราในการฝึกอบรมในรูปแบบการฝึกอบรมเอไอคลาวด์แพลตฟอร์มดังนั้นเราจึงควรตั้งmasterConfig.imageUriในGCP_AI_PLATFORM_TRAINING_ARGSกับค่าเช่นเดียวกับCUSTOM_TFX_IMAGEดังกล่าวข้างต้น
เปลี่ยนไดเรกทอรีหนึ่งระดับขึ้นและดับเบิลคลิกเพื่อเปิด
kubeflow_runner.pyuncommentai_platform_training_argsและai_platform_serving_args
อัปเดตไปป์ไลน์และสร้างการดำเนินการตามที่เราทำในขั้นตอนที่ 5 และ 6
!tfx pipeline update \
--pipeline-path=kubeflow_runner.py \
--endpoint={ENDPOINT}
!tfx run create --pipeline-name {PIPELINE_NAME} --endpoint={ENDPOINT}
CLI Updating pipeline Detected Beam. [WARNING] Default engine will be changed to "local" in the near future. Use --engine flag if you intend to use a different orchestrator. beam runner not found in dsl. CLI Creating a run for pipeline: my_pipeline Detected Beam. [WARNING] Default engine will be changed to "local" in the near future. Use --engine flag if you intend to use a different orchestrator. Pipeline "my_pipeline" does not exist.
คุณสามารถหางานฝึกอบรมของคุณใน เมฆ AI งานแพลทฟอร์ม หากท่อของคุณเสร็จเรียบร้อยแล้วคุณสามารถหารูปแบบของคุณใน รุ่นเมฆ AI แพลตฟอร์ม
ขั้นตอนที่ 10. นำเข้าข้อมูลของคุณไปยังไปป์ไลน์
เราทำไปป์ไลน์สำหรับโมเดลโดยใช้ชุดข้อมูล Chicago Taxi ถึงเวลาใส่ข้อมูลของคุณลงในไปป์ไลน์แล้ว
ข้อมูลของคุณจัดเก็บได้ทุกที่ที่ไปป์ไลน์เข้าถึงได้ รวมถึง GCS หรือ BigQuery คุณจะต้องแก้ไขข้อกำหนดไปป์ไลน์เพื่อเข้าถึงข้อมูลของคุณ
- ถ้าข้อมูลของคุณจะถูกเก็บไว้ในไฟล์, การปรับเปลี่ยน
DATA_PATHในkubeflow_runner.pyหรือlocal_runner.pyและการตั้งค่าไปยังตำแหน่งของไฟล์ของคุณ ถ้าข้อมูลของคุณถูกเก็บไว้ใน BigQuery แก้ไขBIG_QUERY_QUERYในpipeline/configs.pyอย่างถูกต้องแบบสอบถามสำหรับข้อมูลของคุณ - เพิ่มคุณสมบัติใน
models/features.py - ปรับเปลี่ยน
models/preprocessing.pyที่จะ เปลี่ยนการป้อนข้อมูลสำหรับการฝึกอบรม - ปรับเปลี่ยน
models/keras/model.pyและmodels/keras/constants.pyเพื่อ อธิบายรุ่น ML ของคุณ- คุณสามารถใช้แบบจำลองตามตัวประมาณการได้เช่นกัน เปลี่ยน
RUN_FNอย่างต่อเนื่องเพื่อmodels.estimator.model.run_fnในpipeline/configs.py
- คุณสามารถใช้แบบจำลองตามตัวประมาณการได้เช่นกัน เปลี่ยน
โปรดดู เทรนเนอร์คู่มือส่วนประกอบ สำหรับการแนะนำเพิ่มเติม
การทำความสะอาด
ในการทำความสะอาดทรัพยากร Google Cloud ทั้งหมดที่ใช้ในโครงการนี้คุณสามารถ ลบโครงการ Google Cloud ที่คุณใช้สำหรับการกวดวิชา
อีกวิธีหนึ่ง คุณสามารถล้างข้อมูลทรัพยากรแต่ละรายการโดยไปที่แต่ละคอนโซล:
ดูบน TensorFlow.org
ทำงานใน Google Colab
ดูแหล่งที่มาบน GitHub
ดาวน์โหลดโน๊ตบุ๊ค