템플릿을 사용하여 TFX 파이프라인 만들기

소개

이 문서는 (TFX) 파이프 라인 TFX 파이썬 패키지와 함께 제공되는 템플릿을 사용하여 확장 TensorFlow을 만들 수있는 지침을 제공합니다. 대부분의 지침은 AI Platform Notebooks 인스턴스에서 실행되는 Linux 셸 명령어입니다. 사용하여 해당 명령을 호출 해당 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 프로젝트 ID를 가져옵니다.

# 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 Platform > 파이프라인' 메뉴에서 액세스할 수 있습니다. KFP 클러스터의 "엔드포인트"는 파이프라인 대시보드의 URL에서 찾거나 이 노트북을 시작한 시작하기 페이지의 URL에서 얻을 수 있습니다. 하자가 생성 ENDPOINT 환경 변수를하고 KFP 클러스터 엔드 포인트로 설정합니다. ENDPOINT는 URL의 호스트 이름 부분만 포함해야 합니다. 예를 들어, KFP 대시 보드의 URL 인 경우 <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 파이썬 패키지 템플릿을. 분류 및 회귀를 포함하여 점별 예측 문제를 해결하려는 경우 이 템플릿을 시작점으로 사용할 수 있습니다.

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 노트북을 포함하여 파이프라인을 빌드하기 위한 기본 스캐폴드 파일을 제공합니다. taxi 템플릿은 같은 시카고 택시 데이터 세트 및 ML 모델을 사용하여 공기 흐름 자습서 .

다음은 각 Python 파일에 대한 간략한 소개입니다.

  • pipeline -이 디렉토리는 파이프 라인의 정의를 포함
    • configs.py - 파이프 라인 주자에 대한 공통의 상수를 정의
    • pipeline.py - 정의 TFX 구성 요소 및 파이프 라인
  • models -이 디렉토리는 ML 모델 정의가 포함되어 있습니다.
    • features.py , features_test.py - 정의 모델에 대한 기능
    • preprocessing.py , preprocessing_test.py - 사용하는 작업 전처리 정의하는 tf::Transform
    • estimator -이 디렉토리는 견적 기반 모델이 포함되어 있습니다.
      • constants.py - 모델을 정의 상수
      • model.py , model_test.py - TF 추정을 사용하여 DNN 모델을 정의
    • keras -이 디렉토리는 Keras 기반 모델이 포함되어 있습니다.
      • constants.py - 모델을 정의 상수
      • model.py , model_test.py - Keras를 사용하여 DNN 모델을 정의
  • 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 메타 데이터 유물 , 그들은 어딘가에 저장해야합니다. 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 대시보드에서 파이프라인을 실행할 수도 있습니다. 새 실행 실행은 KFP 대시보드의 실험 아래에 나열됩니다. 실험을 클릭하면 진행 상황을 모니터링하고 실행 실행 중에 생성된 아티팩트를 시각화할 수 있습니다.

그러나 KFP 대시보드를 방문하는 것이 좋습니다. Google Cloud Console의 Cloud AI Platform 파이프라인 메뉴에서 KFP 대시보드에 액세스할 수 있습니다. 대시보드를 방문하면 파이프라인을 찾고 파이프라인에 대한 풍부한 정보에 액세스할 수 있습니다. 예를 들어, 실험 메뉴에서 러닝을 찾을 수 있으며 당신이 실험에서 당신의 실행 실행을 열 때 당신은 유물 메뉴의 파이프 라인에서 모든 유물을 찾을 수 있습니다.

실패의 주요 원인 중 하나는 권한 관련 문제입니다. KFP 클러스터에 Google Cloud API에 액세스할 수 있는 권한이 있는지 확인하세요. 이 구성 할 수 있습니다 당신은 GCP에 KFP 클러스터를 만들 때 , 또는 참조 GCP의 문제 해결 문서를 .

5단계. 데이터 유효성 검사를 위한 구성 요소를 추가합니다.

이 단계에서는 포함하여 데이터 유효성 검사를위한 구성 요소를 추가합니다 StatisticsGen , SchemaGenExampleValidator . 당신이 데이터 유효성 검사에 관심이 있다면, 참조하시기 바랍니다 Tensorflow 데이터 유효성 검사 시작하기 .

로 변경 디렉토리를 더블 클릭 pipeline 및 오픈에 다시 더블 클릭 pipeline.py . 찾기 및 추가 3 줄의 주석 StatisticsGen , SchemaGenExampleValidator 파이프 라인을. (팁 : 포함 된 의견에 대한 검색 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 , EvaluatorPusher .

두 번 클릭하여 엽니 다 pipeline.py . 찾기 및 추가 5 줄의 주석 Transform , Trainer , Resolver , EvaluatorPusher 파이프 라인을. (팁 : 검색 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.

이 실행 실행이 성공적으로 완료되면 이제 AI Platform Pipelines에서 첫 번째 TFX 파이프라인을 만들고 실행한 것입니다.

7 단계 (선택 사항) BigQueryExampleGen 시도

BigQuery를이 서버없는, 높은 확장 성, 비용 효율적인 클라우드 데이터웨어 하우스입니다. BigQuery는 TFX에서 학습 예제의 소스로 사용할 수 있습니다. 이 단계에서, 우리는 추가합니다 BigQueryExampleGen 파이프 라인에.

두 번 클릭하여 엽니 다 pipeline.py . 주석 CsvExampleGen 하고 인스턴스 생성 라인 주석 BigQueryExampleGen . 또한 주석을 해제 할 필요가 query 의 인수 create_pipeline 기능을.

우리의 BigQuery에 사용할 GCP 프로젝트를 지정해야하고, 이것은 설정하면됩니다 --projectbeam_pipeline_args 파이프 라인을 만들 때.

두 번 클릭하여 엽니 다 configs.py . 의 주석의 정의 GOOGLE_CLOUD_REGION , BIG_QUERY_WITH_DIRECT_RUNNER_BEAM_PIPELINE_ARGSBIG_QUERY_QUERY . 이 파일의 지역 값을 GCP 프로젝트의 올바른 값으로 바꿔야 합니다.

디렉토리를 한 단계 위로 변경하십시오. 파일 목록 위의 디렉터리 이름을 클릭합니다. 디렉토리의 이름은 파이프 라인의 이름입니다 my_pipeline 변경하지 않은 경우.

두 번 클릭하여 엽니 다 kubeflow_runner.py . 의 주석을 두 개의 인수, querybeam_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. (선택 사항) KFP와 데이터 흐름을 시도 단계

여러 TFX 구성 요소 아파치 빔을 사용하여 데이터 병렬 파이프 라인을 구현하기 위해, 그리고 당신이 사용하는 데이터를 처리하는 워크로드를 배포 할 수 있다는 것을 의미 Google 클라우드 데이터 흐름을 . 이 단계에서는 데이터 흐름을 Apache Beam의 데이터 처리 백엔드로 사용하도록 Kubeflow 오케스트레이터를 설정합니다.

두 번 클릭 pipeline 변경 디렉토리, 그리고 두 번 클릭하여 엽니 다 configs.py . 의 주석 정의 GOOGLE_CLOUD_REGIONDATAFLOW_BEAM_PIPELINE_ARGS .

디렉토리를 한 단계 위로 변경하십시오. 파일 목록 위의 디렉터리 이름을 클릭합니다. 디렉토리의 이름은 파이프 라인의 이름입니다 my_pipeline 변경하지 않은 경우.

두 번 클릭하여 엽니 다 kubeflow_runner.py . 의 주석 beam_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.

당신은 당신의 데이터 흐름 작업을 찾을 수 있습니다 클라우드 콘솔에서 데이터 흐름을 .

단계 9. (선택 사항) KFP와 클라우드 AI 플랫폼 교육 및 예측을 시도

다음과 같은 몇 가지 관리 GCP 서비스와 TFX의 상호 호환 교육 및 예측을위한 클라우드 AI 플랫폼 . 당신은 설정할 수 있습니다 Trainer 클라우드 AI 플랫폼 교육, ML 모델을 훈련에 대한 관리 서비스를 사용하는 구성 요소를. 모델이 제공하는 내장하고 준비하는 경우 또한, 당신은 봉사 클라우드 AI 플랫폼 예측 모델을 푸시 할 수 있습니다. 이 단계에서, 우리는 우리의 설정합니다 TrainerPusher 클라우드 AI 플랫폼 서비스를 사용하는 구성 요소를.

파일을 편집하기 전에 먼저 AI 플랫폼 교육 및 예측 API를 사용 설정해야 할 수도 있습니다.

두 번 클릭 pipeline 변경 디렉토리, 그리고 두 번 클릭하여 엽니 다 configs.py . 의 주석 정의 GOOGLE_CLOUD_REGION , GCP_AI_PLATFORM_TRAINING_ARGSGCP_AI_PLATFORM_SERVING_ARGS . 우리가 설정해야합니다, 그래서 우리는 클라우드 AI 플랫폼 교육의 모델을 학습하기 위해 사용자 정의 내장 된 컨테이너 이미지를 사용합니다 masterConfig.imageUriGCP_AI_PLATFORM_TRAINING_ARGS 와 같은 값으로 CUSTOM_TFX_IMAGE 위.

디렉토리를 변경 한 수준까지, 그리고 두 번 클릭하여 엽니 다 kubeflow_runner.py . 의 주석 ai_platform_training_argsai_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를 포함하여 파이프라인이 액세스할 수 있는 모든 곳에 저장할 수 있습니다. 데이터에 액세스하려면 파이프라인 정의를 수정해야 합니다.

  1. 데이터가 파일에 저장되는 경우, 수정 DATA_PATHkubeflow_runner.py 또는 local_runner.py 및 파일의 위치로 설정합니다. 데이터가 BigQuery에서 저장되어있는 경우, 수정 BIG_QUERY_QUERYpipeline/configs.py 제대로 쿼리 데이터에 대한에.
  2. 에 기능 추가 models/features.py .
  3. 수정 models/preprocessing.py 위해 훈련을위한 입력 데이터를 변환 .
  4. 수정 models/keras/model.pymodels/keras/constants.py 제품에 대해 설명 당신의 ML 모델 .
    • 추정기 기반 모델을 사용할 수도 있습니다. 변경 RUN_FN 상수하기 models.estimator.model.run_fnpipeline/configs.py .

참조하십시오 트레이너 요소 가이드를 더 도입.

청소

이 프로젝트에 사용 된 모든 Google 클라우드 자원을 청소하려면 다음을 수행 할 수 있습니다 Google 클라우드 프로젝트 삭제 자습서에 사용합니다.

또는 각 콘솔을 방문하여 개별 리소스를 정리할 수 있습니다.