liveBook · Manning

Pipeline

As explained in Deep Learning with Python, Third Edition

A supported way of using Keras that combines model-building and training choices for a particular level of flexibility.

A pipeline is an ordered path that turns data into model-ready batches and connects model construction with training. Keras supports several workflows, from simple fit() calls to highly flexible, manually controlled processes, so you can increase control without abandoning shared APIs. section 7.1 section 8.2.4

JPEG files to a trained image classifier

image_dataset_from_directory builds a Dataset that lists class directories, reads and decodes JPEG files, converts images to tensors, resizes them to 180×180, shuffles them, and batches them. The resulting train and validation datasets can pass directly to model.fit(), while callbacks save the best model and history records training and validation metrics. section 8.2.4

Build a practical input pipeline by composing these steps:

  • Create a Dataset from arrays or files. section 8.2.4
  • Inspect elements with iteration, then batch them with batch(). section 8.2.4
  • Transform elements with map(), optionally parallelizing preprocessing and prefetching later batches. section 8.2.4
  • Apply augmentation outside the model when CPU-side parallel processing is preferable, then train with fit(). section 8.2.5
Listing 8.9 Using image_dataset_from_directory to read images from directories
from keras.utils import image_dataset_from_directory

batch_size = 64
image_size = (180, 180)
train_dataset = image_dataset_from_directory(
    new_base_dir / "train", image_size=image_size, batch_size=batch_size
)
validation_dataset = image_dataset_from_directory(
    new_base_dir / "validation", image_size=image_size, batch_size=batch_size
)
test_dataset = image_dataset_from_directory(
    new_base_dir / "test", image_size=image_size, batch_size=batch_size
)

Use the directory-loading listing as a compact starting point for a train/validation/test image pipeline. section 8.2.4

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains file decoding, tensor conversion, resizing, batching, iteration, mapping, parallelization, prefetching, and direct fit() integration.
Examples
Uses directory-based cat-and-dog image classification, NumPy arrays, batching, mapped reshaping, augmentation, metric curves, and test evaluation.
What it assumes
Assumes basic model training, while teaching how raw files become preprocessed floating-point tensors and batches.
What you can do after
Apply it via Keras utilities and Dataset operations to prepare inputs, train models, inspect metrics, and evaluate saved checkpoints.
How it connects
Links Keras Model and Layer APIs with tf.data.Dataset, model training, data augmentation, JAX, PyTorch, scikit-learn, and NumPy.

Also explained in

Compare how 48 books explain pipeline →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.