我最近发现了有关kubeflow和kubeflow管道的信息,但我不清楚如何从python程序构建图像。
让我们假设我有一个裁剪图像的简单python函数:
class Image_Proc:
def crop_image(self, image, start_pixel, end_pixel):
# crop
return cropped_image
如何将其容器化并在KubeFlow管道中使用?我是否需要将其包装在API中(例如,使用Flask)还是需要连接到某些媒体/数据代理?
KubeFlow管道如何将输入发送到此代码并将此代码的输出传输到下一步?
答案 0 :(得分:1)
您不需要构建映像。对于中小型组件,您可以在现有图像上使用。检查lightweight components sample。 对于python,请参见Data passing in python components 对于非python,请参见 Creating components from command-line programs
KFP SDK支持构建容器映像。请参见container_build示例。
阅读创作documentation的官方组件。
让我们假设我有一个裁剪图像的简单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={})
答案 1 :(得分:0)
基本上,您可以按照Docker here提供的步骤来创建Docker映像并将其发布到Docker Hub(或者您可以构建自己的私有Docker注册表,但是我认为对于初学者而言,这可能会花费太多精力)。只需大致列出步骤:
此外,您可以阅读此doc来了解如何创建管道(Kubeflow管道只是argo工作流程)。对于您的情况,只需在管道YAML文件中填写所需步骤的inputs
和/或outputs
部分即可。