Machine learning 如何为KubeFlow管道构建映像?
我最近发现了kubeflow和kubeflow管道,但我不清楚如何从python程序构建映像 假设我有一个简单的python函数来裁剪图像:Machine learning 如何为KubeFlow管道构建映像?,machine-learning,kubernetes,kubeflow,kubeflow-pipelines,Machine Learning,Kubernetes,Kubeflow,Kubeflow Pipelines,我最近发现了kubeflow和kubeflow管道,但我不清楚如何从python程序构建映像 假设我有一个简单的python函数来裁剪图像: class Image_Proc: def crop_image(self, image, start_pixel, end_pixel): # crop return cropped_image 我该如何将其装箱并在KubeFlow管道中使用?我是否需要将其包装在API中(例如使用Flask),或者需要连接到某个
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注册表,但我认为这对初学者来说可能太多了)。大致列出以下步骤:
输入
和/或输出
部分
class Image_Proc:
def crop_image(self, image, start_pixel, end_pixel):
# crop
return cropped_image
您可以通过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={})