[英]How to build an image for KubeFlow pipeline?
我最近發現了 kubeflow 和 kubeflow 管道,但我不清楚如何從我的 python 程序構建圖像。
讓我們假設我有一個簡單的 python 函數來裁剪圖像:
class Image_Proc:
def crop_image(self, image, start_pixel, end_pixel):
# crop
return cropped_image
我應該如何將其容器化並在 KubeFlow 管道中使用它? 我需要將它包裝在 API 中(例如使用 Flask)還是需要連接到某些媒體/數據代理?
KubeFlow 管道如何向此代碼發送輸入並將此代碼的輸出傳輸到下一步?
基本上你可以按照 Docker 提供的步驟在這里創建 Docker 鏡像並發布到 Docker Hub(或者你可以構建自己的私有 docker 注冊表,但我認為這對初學者來說可能太多了)。 簡單羅列一下步驟:
此外,您可以閱讀此文檔以了解如何創建管道(Kubeflow 管道只是 argo 工作流)。 對於您的情況,只需在管道 YAML 文件中填寫您想要的步驟的inputs
和/或outputs
部分。
您不需要構建圖像。 對於中小型組件,您可以在現有圖像之上工作。 檢查輕量級組件示例。 對於python,請參閱python組件中的數據傳遞對於非python,請參閱從命令行程序創建組件
KFP SDK 對構建容器鏡像有一定的支持。 請參閱container_build示例。
閱讀官方組件創作文檔。
讓我們假設我有一個簡單的 python 函數來裁剪圖像:
您可以像這樣從 python 函數創建一個組件:
from kfp.components import InputPath, OutputPath, create_component_from_func
# Declare function (with annotations)
def crop_image(
image_path: InputPath(),
start_pixel: int,
end_pixel: int,
cropped_image_path: OutputPath(),
):
import some_image_lib
some_image_lib.crop(image_path, start_pixel, end_pixel, cropped_image_path)
# Create component
crop_image_op = create_component_from_func(
crop_image,
# base_image=..., # Optional. Base image that has most of the packages that you need. E.g. tensorflow/tensorflow:2.2.0
packages_to_install=['some_image_lib==1.2.3'],
output_component_file='component.yaml', # Optional. Use this to share the component between pipelines, teams or people in the world
)
# Create pipeline
def my_pipeline():
download_image_task = download_image_op(...)
crop_image_task = crop_image_op(
image=download_image_task.output,
start_pixel=10,
end_pixel=200,
)
# Submit pipeline
kfp.Client(host=...).create_run_from_pipeline_func(my_pipeline, arguments={})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.