我最近发现了kubeflow和kubeflow管道,但我不清楚如何从python程序中构建映像。
让我们假设我有一个简单的python函数,它可以对图像进行裁剪:
class Image_Proc:
def crop_image(self, image, start_pixel, end_pixel):
# crop
return cropped_image我应该如何在KubeFlow管道中封装它并使用它呢?我是否需要将它封装在API中(例如用Flask ),还是需要连接到某些媒体/数据代理?
KubeFlow管道如何向此代码发送输入并将此代码的输出传输到下一步?
发布于 2020-02-06 03:22:08
基本上,您可以按照Docker 这里提供的步骤创建Docker映像并发布到Docker (或者您可以构建自己的专用码头注册中心,但我认为对于初学者来说,这可能是太多的工作)。简单地列出步骤:
另外,您可以阅读这个文档来了解如何创建管道(Kubeflow管道只是argo工作流)。对于您的情况,只需在管道YAML文件中填写所需步骤的inputs和/或outputs部分即可。
发布于 2020-06-20 01:28:23
让我们假设我有一个简单的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={})https://stackoverflow.com/questions/60041794
复制相似问题