您不需要构建图像。对于中小型组件,您可以在现有图像之上工作。检查轻量级组件样品。对于 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={})