ZenML Integration API Reference 📖
Complete API reference for MLPotion's ZenML integration.
Auto-Generated Documentation
This page is automatically populated with API documentation from the source code.
TensorFlow Steps
mlpotion.integrations.zenml.tensorflow.steps
Classes
Functions
evaluate_model
evaluate_model(
model: keras.Model,
dataset: tf.data.Dataset,
verbose: int = 1,
metadata: dict[str, Any] | None = None,
) -> Annotated[dict[str, float], EvaluationMetrics]
Evaluate a TensorFlow/Keras model using ModelEvaluator.
This step computes metrics on a given dataset using the provided model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
keras.Model
|
The Keras model to evaluate. |
required |
dataset |
tf.data.Dataset
|
The evaluation |
required |
verbose |
int
|
Verbosity mode (0 or 1). |
1
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Type | Description |
|---|---|
Annotated[dict[str, float], EvaluationMetrics]
|
dict[str, float]: A dictionary of computed metrics. |
Source code in mlpotion/integrations/zenml/tensorflow/steps.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
export_model
export_model(
model: keras.Model,
export_path: str,
export_format: str = "keras",
metadata: dict[str, Any] | None = None,
) -> Annotated[str, ExportPath]
Export a TensorFlow/Keras model to disk using ModelExporter.
This step exports the model to a specified format (e.g., Keras format, SavedModel).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
keras.Model
|
The Keras model to export. |
required |
export_path |
str
|
The destination path for the exported model. |
required |
export_format |
str
|
The format to export to (default: "keras"). |
'keras'
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
Annotated[str, ExportPath]
|
The path to the exported model artifact. |
Source code in mlpotion/integrations/zenml/tensorflow/steps.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
inspect_model
inspect_model(
model: keras.Model,
include_layers: bool = True,
include_signatures: bool = True,
metadata: dict[str, Any] | None = None,
) -> Annotated[dict[str, Any], ModelInspection]
Inspect a TensorFlow/Keras model using ModelInspector.
This step extracts metadata about the model, such as layer configuration, input/output shapes, and parameter counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
keras.Model
|
The Keras model to inspect. |
required |
include_layers |
bool
|
Whether to include detailed layer information. |
True
|
include_signatures |
bool
|
Whether to include signature information. |
True
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Type | Description |
|---|---|
Annotated[dict[str, Any], ModelInspection]
|
dict[str, Any]: A dictionary containing the inspection results. |
Source code in mlpotion/integrations/zenml/tensorflow/steps.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 | |
load_data
load_data(
file_path: str,
batch_size: int = 32,
label_name: str = "target",
column_names: list[str] | None = None,
metadata: dict[str, Any] | None = None,
) -> Annotated[tf.data.Dataset, TFDataset]
Load data from local CSV files using TensorFlow's efficient loading.
This step uses CSVDataLoader to create a tf.data.Dataset from CSV files matching
the specified pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path |
str
|
Glob pattern for CSV files (e.g., "data/*.csv"). |
required |
batch_size |
int
|
Number of samples per batch. |
32
|
label_name |
str
|
Name of the column to use as the label. |
'target'
|
column_names |
list[str] | None
|
List of specific columns to load. |
None
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Type | Description |
|---|---|
Annotated[tf.data.Dataset, TFDataset]
|
tf.data.Dataset: The loaded TensorFlow dataset. |
Source code in mlpotion/integrations/zenml/tensorflow/steps.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
load_model
load_model(
model_path: str,
inspect: bool = True,
metadata: dict[str, Any] | None = None,
) -> Annotated[keras.Model, LoadedModel]
Load a TensorFlow/Keras model from disk using ModelPersistence.
This step loads a previously saved model. It can optionally inspect the loaded model to log metadata about its structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path |
str
|
The path to the saved model. |
required |
inspect |
bool
|
Whether to inspect the model after loading. |
True
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Type | Description |
|---|---|
Annotated[keras.Model, LoadedModel]
|
keras.Model: The loaded Keras model. |
Source code in mlpotion/integrations/zenml/tensorflow/steps.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
optimize_data
optimize_data(
dataset: tf.data.Dataset,
batch_size: int = 32,
shuffle_buffer_size: int | None = None,
prefetch: bool = True,
cache: bool = False,
metadata: dict[str, Any] | None = None,
) -> Annotated[tf.data.Dataset, TFDataset]
Optimize a TensorFlow dataset for training performance.
This step applies optimizations like caching, shuffling, and prefetching to the dataset
using DatasetOptimizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset |
tf.data.Dataset
|
The input |
required |
batch_size |
int
|
Batch size (if re-batching is needed). |
32
|
shuffle_buffer_size |
int | None
|
Size of the shuffle buffer. |
None
|
prefetch |
bool
|
Whether to prefetch data. |
True
|
cache |
bool
|
Whether to cache data in memory. |
False
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Type | Description |
|---|---|
Annotated[tf.data.Dataset, TFDataset]
|
tf.data.Dataset: The optimized TensorFlow dataset. |
Source code in mlpotion/integrations/zenml/tensorflow/steps.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
save_model
save_model(
model: keras.Model,
save_path: str,
metadata: dict[str, Any] | None = None,
) -> Annotated[str, SavePath]
Save a TensorFlow/Keras model to disk using ModelPersistence.
This step saves the model for later reloading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
keras.Model
|
The Keras model to save. |
required |
save_path |
str
|
The destination path. |
required |
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
Annotated[str, SavePath]
|
The path to the saved model. |
Source code in mlpotion/integrations/zenml/tensorflow/steps.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
train_model
train_model(
model: keras.Model,
dataset: tf.data.Dataset,
epochs: int = 10,
validation_dataset: tf.data.Dataset | None = None,
learning_rate: float = 0.001,
verbose: int = 1,
metadata: dict[str, Any] | None = None,
) -> Tuple[
Annotated[keras.Model, TrainedModel],
Annotated[dict[str, list[float]], TrainingHistory],
]
Train a TensorFlow/Keras model using ModelTrainer.
This step configures and runs a training session. It supports validation data and logging of training metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
keras.Model
|
The Keras model to train. |
required |
dataset |
tf.data.Dataset
|
The training |
required |
epochs |
int
|
Number of epochs to train. |
10
|
validation_dataset |
tf.data.Dataset | None
|
Optional validation |
None
|
learning_rate |
float
|
Learning rate for the Adam optimizer. |
0.001
|
verbose |
int
|
Verbosity mode (0, 1, or 2). |
1
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Annotated[keras.Model, TrainedModel], Annotated[dict[str, list[float]], TrainingHistory]]
|
Tuple[keras.Model, dict[str, list[float]]]: The trained model and a dictionary of history metrics. |
Source code in mlpotion/integrations/zenml/tensorflow/steps.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
transform_data
transform_data(
dataset: tf.data.Dataset,
model: keras.Model,
data_output_path: str,
data_output_per_batch: bool = False,
metadata: dict[str, Any] | None = None,
) -> Annotated[str, OutputPath]
Transform data using a TensorFlow model and save predictions to CSV.
This step uses DataToCSVTransformer to run inference on a dataset using a provided model
and saves the results to the specified output path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset |
tf.data.Dataset
|
The input |
required |
model |
keras.Model
|
The Keras model to use for transformation. |
required |
data_output_path |
str
|
Path to save the transformed data (CSV). |
required |
data_output_per_batch |
bool
|
Whether to save a separate file per batch. |
False
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
Annotated[str, OutputPath]
|
The path to the saved output file(s). |
Source code in mlpotion/integrations/zenml/tensorflow/steps.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
PyTorch Steps
mlpotion.integrations.zenml.pytorch.steps
ZenML steps for PyTorch framework.
Classes
Functions
evaluate_model
evaluate_model(
model: nn.Module,
dataloader: DataLoader,
loss_fn: str = "mse",
device: str = "cpu",
verbose: int = 1,
max_batches: int | None = None,
metadata: dict[str, Any] | None = None,
) -> Annotated[dict[str, float], EvaluationMetrics]
Evaluate a PyTorch model using ModelEvaluator.
This step computes metrics on a given dataset using the provided model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
nn.Module
|
The PyTorch model to evaluate. |
required |
dataloader |
DataLoader
|
The evaluation |
required |
loss_fn |
str
|
Name of the loss function (e.g., "mse", "cross_entropy"). |
'mse'
|
device |
str
|
Device to evaluate on ("cpu" or "cuda"). |
'cpu'
|
verbose |
int
|
Verbosity mode (0 or 1). |
1
|
max_batches |
int | None
|
Limit number of batches to evaluate (useful for debugging). |
None
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Type | Description |
|---|---|
Annotated[dict[str, float], EvaluationMetrics]
|
dict[str, float]: A dictionary of computed metrics. |
Source code in mlpotion/integrations/zenml/pytorch/steps.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
export_model
export_model(
model: nn.Module,
export_path: str,
export_format: str = "state_dict",
device: str = "cpu",
example_input: torch.Tensor | None = None,
jit_mode: str = "script",
input_names: list[str] | None = None,
output_names: list[str] | None = None,
dynamic_axes: dict[str, dict[int, str]] | None = None,
opset_version: int = 14,
metadata: dict[str, Any] | None = None,
) -> Annotated[str, ExportPath]
Export a PyTorch model to disk using ModelExporter.
This step exports the model to a specified format (TorchScript, ONNX, or state_dict).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
nn.Module
|
The PyTorch model to export. |
required |
export_path |
str
|
The destination path for the exported model. |
required |
export_format |
str
|
The format to export to ("torchscript", "onnx", "state_dict"). |
'state_dict'
|
device |
str
|
Device to use for export (important for tracing). |
'cpu'
|
example_input |
torch.Tensor | None
|
Example input tensor (required for ONNX and TorchScript trace). |
None
|
jit_mode |
str
|
TorchScript mode ("script" or "trace"). |
'script'
|
input_names |
list[str] | None
|
List of input names for ONNX export. |
None
|
output_names |
list[str] | None
|
List of output names for ONNX export. |
None
|
dynamic_axes |
dict[str, dict[int, str]] | None
|
Dictionary of dynamic axes for ONNX export. |
None
|
opset_version |
int
|
ONNX opset version. |
14
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
Annotated[str, ExportPath]
|
The path to the exported model artifact. |
Source code in mlpotion/integrations/zenml/pytorch/steps.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
load_csv_data
load_csv_data(
file_path: str,
batch_size: int = 32,
label_name: str | None = None,
column_names: list[str] | None = None,
shuffle: bool = True,
num_workers: int = 0,
pin_memory: bool = False,
drop_last: bool = False,
dtype: str = "float32",
metadata: dict[str, Any] | None = None,
) -> Annotated[DataLoader, PyTorchDataLoader]
Load data from CSV files into a PyTorch DataLoader.
This step uses CSVDataset and CSVDataLoader to load data matching the specified file pattern.
It returns a configured DataLoader ready for training or evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path |
str
|
Glob pattern for CSV files (e.g., "data/*.csv"). |
required |
batch_size |
int
|
Number of samples per batch. |
32
|
label_name |
str | None
|
Name of the column to use as the label. |
None
|
column_names |
list[str] | None
|
List of specific columns to load. |
None
|
shuffle |
bool
|
Whether to shuffle the data. |
True
|
num_workers |
int
|
Number of subprocesses to use for data loading. |
0
|
pin_memory |
bool
|
Whether to copy tensors into CUDA pinned memory. |
False
|
drop_last |
bool
|
Whether to drop the last incomplete batch. |
False
|
dtype |
str
|
Data type for the features (e.g., "float32"). |
'float32'
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DataLoader |
Annotated[DataLoader, PyTorchDataLoader]
|
The configured PyTorch DataLoader. |
Source code in mlpotion/integrations/zenml/pytorch/steps.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
load_model
load_model(
model_path: str,
model_class: type[nn.Module] | None = None,
map_location: str = "cpu",
strict: bool = True,
metadata: dict[str, Any] | None = None,
) -> Annotated[nn.Module, LoadedModel]
Load a PyTorch model from disk using ModelPersistence.
This step loads a previously saved model. If loading a state dict, model_class
must be provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path |
str
|
The path to the saved model. |
required |
model_class |
type[nn.Module] | None
|
The class of the model (required for state dict loading). |
None
|
map_location |
str
|
Device to load the model onto. |
'cpu'
|
strict |
bool
|
Whether to strictly enforce state dict keys match. |
True
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Type | Description |
|---|---|
Annotated[nn.Module, LoadedModel]
|
nn.Module: The loaded PyTorch model. |
Source code in mlpotion/integrations/zenml/pytorch/steps.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
load_streaming_csv_data
load_streaming_csv_data(
file_path: str,
batch_size: int = 32,
label_name: str | None = None,
column_names: list[str] | None = None,
num_workers: int = 0,
pin_memory: bool = False,
chunksize: int = 10000,
dtype: str = "float32",
metadata: dict[str, Any] | None = None,
) -> Annotated[DataLoader, PyTorchDataLoader]
Load large CSV files as a streaming PyTorch DataLoader.
This step uses StreamingCSVDataset to load data in chunks, making it suitable for
datasets that do not fit in memory. It returns a DataLoader wrapping the iterable dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path |
str
|
Glob pattern for CSV files (e.g., "data/*.csv"). |
required |
batch_size |
int
|
Number of samples per batch. |
32
|
label_name |
str | None
|
Name of the column to use as the label. |
None
|
column_names |
list[str] | None
|
List of specific columns to load. |
None
|
num_workers |
int
|
Number of subprocesses to use for data loading. |
0
|
pin_memory |
bool
|
Whether to copy tensors into CUDA pinned memory. |
False
|
chunksize |
int
|
Number of rows to read into memory at a time per file. |
10000
|
dtype |
str
|
Data type for the features (e.g., "float32"). |
'float32'
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
DataLoader |
Annotated[DataLoader, PyTorchDataLoader]
|
The configured streaming PyTorch DataLoader. |
Source code in mlpotion/integrations/zenml/pytorch/steps.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
save_model
save_model(
model: nn.Module,
save_path: str,
save_full_model: bool = False,
metadata: dict[str, Any] | None = None,
) -> Annotated[str, SavePath]
Save a PyTorch model to disk using ModelPersistence.
This step saves the model for later reloading. It supports saving just the state dict (recommended) or the full model object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
nn.Module
|
The PyTorch model to save. |
required |
save_path |
str
|
The destination path. |
required |
save_full_model |
bool
|
Whether to save the full model object (pickle) instead of state dict. |
False
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
Annotated[str, SavePath]
|
The path to the saved model. |
Source code in mlpotion/integrations/zenml/pytorch/steps.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
train_model
train_model(
model: nn.Module,
dataloader: DataLoader,
epochs: int = 10,
learning_rate: float = 0.001,
optimizer: str = "adam",
loss_fn: str = "mse",
device: str = "cpu",
validation_dataloader: DataLoader | None = None,
verbose: int = 1,
max_batches_per_epoch: int | None = None,
metadata: dict[str, Any] | None = None,
) -> Tuple[
Annotated[nn.Module, TrainedModel],
Annotated[dict[str, float], TrainingMetrics],
]
Train a PyTorch model using ModelTrainer.
This step configures and runs a training session. It supports validation data, custom loss functions, and automatic device management.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
nn.Module
|
The PyTorch model to train. |
required |
dataloader |
DataLoader
|
The training |
required |
epochs |
int
|
Number of epochs to train. |
10
|
learning_rate |
float
|
Learning rate for the optimizer. |
0.001
|
optimizer |
str
|
Name of the optimizer (e.g., "adam", "sgd"). |
'adam'
|
loss_fn |
str
|
Name of the loss function (e.g., "mse", "cross_entropy"). |
'mse'
|
device |
str
|
Device to train on ("cpu" or "cuda"). |
'cpu'
|
validation_dataloader |
DataLoader | None
|
Optional validation |
None
|
verbose |
int
|
Verbosity mode (0 or 1). |
1
|
max_batches_per_epoch |
int | None
|
Limit number of batches per epoch (useful for debugging). |
None
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Annotated[nn.Module, TrainedModel], Annotated[dict[str, float], TrainingMetrics]]
|
Tuple[nn.Module, dict[str, float]]: The trained model and a dictionary of final metrics. |
Source code in mlpotion/integrations/zenml/pytorch/steps.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
Keras Steps
mlpotion.integrations.zenml.keras.steps
ZenML steps for Keras framework.
Classes
Functions
evaluate_model
evaluate_model(
model: keras.Model,
data: CSVSequence,
verbose: int = 1,
metadata: dict[str, Any] | None = None,
) -> Annotated[dict[str, float], EvaluationMetrics]
Evaluate a Keras model using ModelEvaluator.
This step computes metrics on a given dataset using the provided model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
keras.Model
|
The Keras model to evaluate. |
required |
data |
CSVSequence
|
The evaluation dataset ( |
required |
verbose |
int
|
Verbosity mode (0 or 1). |
1
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Type | Description |
|---|---|
Annotated[dict[str, float], EvaluationMetrics]
|
dict[str, float]: A dictionary of computed metrics. |
Source code in mlpotion/integrations/zenml/keras/steps.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
export_model
export_model(
model: keras.Model,
export_path: str,
export_format: str | None = None,
metadata: dict[str, Any] | None = None,
) -> Annotated[str, ExportPath]
Export a Keras model to disk using ModelExporter.
This step exports the model to a specified format (e.g., SavedModel, H5, TFLite).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
keras.Model
|
The Keras model to export. |
required |
export_path |
str
|
The destination path for the exported model. |
required |
export_format |
str | None
|
The format to export to (optional). |
None
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
Annotated[str, ExportPath]
|
The path to the exported model artifact. |
Source code in mlpotion/integrations/zenml/keras/steps.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
inspect_model
inspect_model(
model: keras.Model,
include_layers: bool = True,
include_signatures: bool = True,
metadata: dict[str, Any] | None = None,
) -> Annotated[dict[str, Any], ModelInspection]
Inspect a Keras model using ModelInspector.
This step extracts metadata about the model, such as layer configuration, input/output shapes, and parameter counts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
keras.Model
|
The Keras model to inspect. |
required |
include_layers |
bool
|
Whether to include detailed layer information. |
True
|
include_signatures |
bool
|
Whether to include signature information. |
True
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Type | Description |
|---|---|
Annotated[dict[str, Any], ModelInspection]
|
dict[str, Any]: A dictionary containing the inspection results. |
Source code in mlpotion/integrations/zenml/keras/steps.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
load_data
load_data(
file_path: str,
batch_size: int = 32,
label_name: str | None = None,
column_names: list[str] | None = None,
shuffle: bool = True,
dtype: str = "float32",
metadata: dict[str, Any] | None = None,
) -> Annotated[CSVSequence, CSVSequence]
Load data from CSV files into a Keras Sequence.
This step uses CSVDataLoader to load data matching the specified file pattern.
It returns a CSVSequence which can be used for training or evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path |
str
|
Glob pattern for CSV files (e.g., "data/*.csv"). |
required |
batch_size |
int
|
Number of samples per batch. |
32
|
label_name |
str | None
|
Name of the column to use as the label. |
None
|
column_names |
list[str] | None
|
List of specific columns to load. |
None
|
shuffle |
bool
|
Whether to shuffle the data. |
True
|
dtype |
str
|
Data type for the features (e.g., "float32"). |
'float32'
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
CSVSequence |
Annotated[CSVSequence, CSVSequence]
|
The loaded Keras Sequence. |
Source code in mlpotion/integrations/zenml/keras/steps.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
load_model
load_model(
model_path: str,
inspect: bool = True,
metadata: dict[str, Any] | None = None,
) -> Annotated[keras.Model, LoadedModel]
Load a Keras model from disk using ModelPersistence.
This step loads a previously saved model. It can optionally inspect the loaded model to log metadata about its structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path |
str
|
The path to the saved model. |
required |
inspect |
bool
|
Whether to inspect the model after loading. |
True
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Type | Description |
|---|---|
Annotated[keras.Model, LoadedModel]
|
keras.Model: The loaded Keras model. |
Source code in mlpotion/integrations/zenml/keras/steps.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | |
save_model
save_model(
model: keras.Model,
save_path: str,
metadata: dict[str, Any] | None = None,
) -> Annotated[str, SavePath]
Save a Keras model to disk using ModelPersistence.
This step saves the model for later reloading, typically preserving the optimizer state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
keras.Model
|
The Keras model to save. |
required |
save_path |
str
|
The destination path. |
required |
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
Annotated[str, SavePath]
|
The path to the saved model. |
Source code in mlpotion/integrations/zenml/keras/steps.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
train_model
train_model(
model: keras.Model,
data: CSVSequence,
epochs: int = 10,
validation_data: CSVSequence | None = None,
learning_rate: float = 0.001,
verbose: int = 1,
callbacks: list[Any] | None = None,
metadata: dict[str, Any] | None = None,
) -> Tuple[
Annotated[keras.Model, TrainedModel],
Annotated[dict[str, float], TrainingMetrics],
]
Train a Keras model using ModelTrainer.
This step configures and runs a training session. It supports validation data, callbacks, and logging of training metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
keras.Model
|
The Keras model to train. |
required |
data |
CSVSequence
|
The training dataset ( |
required |
epochs |
int
|
Number of epochs to train. |
10
|
validation_data |
CSVSequence | None
|
Optional validation dataset ( |
None
|
learning_rate |
float
|
Learning rate for the Adam optimizer. |
0.001
|
verbose |
int
|
Verbosity mode (0, 1, or 2). |
1
|
callbacks |
list[Any] | None
|
List of Keras callbacks to apply during training. |
None
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Annotated[keras.Model, TrainedModel], Annotated[dict[str, float], TrainingMetrics]]
|
Tuple[keras.Model, dict[str, float]]: The trained model and a dictionary of final metrics. |
Source code in mlpotion/integrations/zenml/keras/steps.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
transform_data
transform_data(
dataset: CSVSequence,
model: keras.Model,
data_output_path: str,
data_output_per_batch: bool = False,
batch_size: int | None = None,
feature_names: list[str] | None = None,
input_columns: list[str] | None = None,
metadata: dict[str, Any] | None = None,
) -> Annotated[str, OutputPath]
Transform data using a Keras model and save predictions to CSV.
This step uses CSVDataTransformer to run inference on a dataset using a provided model
and saves the results to the specified output path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset |
CSVSequence
|
The input dataset ( |
required |
model |
keras.Model
|
The Keras model to use for transformation. |
required |
data_output_path |
str
|
Path to save the transformed data (CSV). |
required |
data_output_per_batch |
bool
|
Whether to save a separate file per batch. |
False
|
batch_size |
int | None
|
Batch size for inference (overrides dataset batch size if provided). |
None
|
feature_names |
list[str] | None
|
Optional list of feature names for the output CSV. |
None
|
input_columns |
list[str] | None
|
Optional list of input columns to pass to the model. |
None
|
metadata |
dict[str, Any] | None
|
Optional dictionary of metadata to log to ZenML. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
Annotated[str, OutputPath]
|
The path to the saved output file(s). |
Source code in mlpotion/integrations/zenml/keras/steps.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
Materializers
mlpotion.integrations.zenml.tensorflow.materializers
Custom materializers for TensorFlow types.
Classes
TFConfigDatasetMaterializer
Bases: BaseMaterializer
Materializer for tf.data.Dataset created from CSV files.
Instead of serializing the entire dataset to TFRecords, this materializer
stores only the configuration needed to recreate the dataset using
tf.data.experimental.make_csv_dataset. This is much more efficient and
avoids shape-related issues during serialization/deserialization.
This materializer works specifically with datasets created via:
- tf.data.experimental.make_csv_dataset
- MLPotion's TFCSVDataLoader
Advantages: - Lightweight: Only stores config, not data - Fast: No TFRecord serialization overhead - Reliable: Recreates dataset with exact same parameters - Flexible: Works with any subsequent transformations (batching, shuffling, etc.)
Functions
load
load(data_type: Type[Any]) -> tf.data.Dataset
Load dataset by recreating it from stored configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_type |
Type[Any]
|
The type of the data to load. |
required |
Returns:
| Type | Description |
|---|---|
tf.data.Dataset
|
Recreated tf.data.Dataset with the same configuration. |
Source code in mlpotion/integrations/zenml/tensorflow/materializers.py
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 | |
save
save(data: tf.data.Dataset) -> None
Save dataset configuration instead of actual data.
This method attempts to extract the original CSV loading configuration from the dataset. If the dataset doesn't have this metadata, it falls back to the TFRecord materializer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
tf.data.Dataset
|
The dataset to save configuration for. |
required |
Source code in mlpotion/integrations/zenml/tensorflow/materializers.py
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | |
TFRecordDatasetMaterializer
Bases: BaseMaterializer
Generic TFRecord materializer for tf.data.Dataset.
This materializer is designed to be robust and round-trip safe for
datasets produced by tf.data.experimental.make_csv_dataset, and in
general for any dataset whose element_spec is a nested structure of:
- dict / tuple / list containers
- `tf.TensorSpec` leaves
It works as follows:
-
Save:
- Reads
dataset.element_specand serializes it to JSON. - For each batch (dataset element), recursively flattens it to a list of tensors in a deterministic order implied by the spec.
- Writes a single
tf.train.Exampleper batch, with features named "f0", "f1", ... corresponding to each leaf tensor.
- Reads
-
Load:
- Deserializes
element_specfrom JSON. - Builds a
feature_descriptionfortf.io.parse_single_exampleusing the leaf specs. - Parses each example into a list of tensors.
- Recursively unflattens the list back into the same nested
structure as
element_spec.
- Deserializes
This supports all typical make_csv_dataset shapes:
1. label_name=None:
element: dict[str, Tensor]
2. label_name="target":
element: (dict[str, Tensor], Tensor)
3. label_name=["t1", "t2"]:
element: (dict[str, Tensor], dict[str, Tensor])
and also more complex nesting as long as it's composed of dict / tuple / list and TensorSpec leaves.
Functions
load
load(data_type: Type[Any]) -> tf.data.Dataset
Deserialize a tf.data.Dataset from TFRecord + metadata JSON.
Source code in mlpotion/integrations/zenml/tensorflow/materializers.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
save
save(data: tf.data.Dataset) -> None
Serialize a tf.data.Dataset to TFRecord + metadata JSON.
Source code in mlpotion/integrations/zenml/tensorflow/materializers.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
TensorMaterializer
Bases: BaseMaterializer
Materializer for TensorFlow Tensor objects.
This materializer handles the serialization and deserialization of tf.Tensor objects.
It saves tensors as binary protobuf files (tensor.pb) using tf.io.serialize_tensor.
Functions
load
load(data_type: type[Any]) -> tf.Tensor
Load a TensorFlow Tensor from the artifact store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_type |
type[Any]
|
The type of the data to load (should be |
required |
Returns:
| Type | Description |
|---|---|
tf.Tensor
|
tf.Tensor: The loaded tensor. |
Source code in mlpotion/integrations/zenml/tensorflow/materializers.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
save
save(data: tf.Tensor) -> None
Save a TensorFlow Tensor to the artifact store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
tf.Tensor
|
The tensor to save. |
required |
Source code in mlpotion/integrations/zenml/tensorflow/materializers.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
TensorSpecMaterializer
Bases: BaseMaterializer
Materializer for TensorFlow TensorSpec objects.
This materializer handles the serialization and deserialization of tf.TensorSpec objects.
It saves the spec as a JSON file (spec.json) containing shape, dtype, and other metadata.
Functions
load
load(data_type: type[Any]) -> tf.TensorSpec
Load a TensorFlow TensorSpec from the artifact store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_type |
type[Any]
|
The type of the data to load (should be |
required |
Returns:
| Type | Description |
|---|---|
tf.TensorSpec
|
tf.TensorSpec: The loaded tensor spec. |
Source code in mlpotion/integrations/zenml/tensorflow/materializers.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
save
save(data: tf.TensorSpec) -> None
Save a TensorFlow TensorSpec to the artifact store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data |
tf.TensorSpec
|
The tensor spec to save. |
required |
Source code in mlpotion/integrations/zenml/tensorflow/materializers.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
mlpotion.integrations.zenml.pytorch.materializers
See the ZenML Integration Guide for usage examples