Slide 68
Slide 68 text
Lightweight
Python
function-based
components
from kfp import dsl
from kfp.dsl import Input, Output, Dataset, Model
@dsl.component(
base_image='python:3.9',
packages_to_install=['tensorflow==2.10.0'],
)
def train_model(
dataset: Input[Dataset],
num_epochs: int,
model: Output[Model],
):
from tensorflow import keras
# load and process the Dataset artifact
with open(dataset.path) as f:
x, y = ...
my_model = keras.Sequential(
[
layers.Dense(4, activation='relu', name='layer_1'),
layers.Dense(2, activation='relu', name='layer_2'),
layers.Dense(1, name='layer_3'),
]
)
my_model.compile(...)
# train for num_epochs
my_model.fit(x, y, epochs=num_epochs)
# save the Model artifact
my_model.save(model.path)