liveBook · Manning

Preprocessing

As explained in Distributed Machine Learning Patterns

The transformation and preparation of raw data into a form suitable for downstream computation or model training.

Preprocessing transforms raw inputs into forms a model or downstream computation can use. Common image steps include resizing, grayscale conversion, normalization, type casting, and more expensive operations such as convolutions. These steps can add substantial memory pressure when datasets are loaded across a distributed cluster. section 7.2.1 section 2.1

Feature scaling is a practical baseline when models are sensitive to feature scale. For MNIST images stored as uint8 values from 0 to 255, dividing by 255 converts pixels to floating-point values in the [0, 1] range before training and evaluation. section 8.1.1

Build a training input pipeline

A tf.data pipeline can cast Fashion-MNIST images to float32, scale them by 255, then cache and shuffle the training split. Each dataset element carries an image and label, allowing the pipeline to read data, transform it, and prepare batches for training. section 9.1.1 section 2.1

Preprocess at the serving boundary

Inference inputs may arrive as JSON containing image bytes rather than tensors. A serving signature can decode each JPEG, resize it to 28 × 28, cast it to uint8, and pass the resulting images to the saved model before TensorFlow Serving handles prediction calls. section 9.3.1

Listing 8.7 The preprocessing function
def preprocess(ds):
   return ds / 255.0

x_train = preprocess(x_train)
x_test = preprocess(x_test)

> x_train.dtype
dtype('float64')

> x_train.min()
0.0

> x_train.max()
1.0

A minimal preprocessing function shows the normalization operation and verifies the resulting dtype and value range. section 8.1.1

How Distributed Machine Learning Patterns covers it

How deep it goes
Demonstrates scaling, casting, caching, shuffling, decoding, resizing, and serving signatures without detailing transformation internals.
Examples
Uses MNIST normalization, a Fashion-MNIST tf.data pipeline, and JPEG-byte decoding for image inference.
What it assumes
Assumes familiarity with Python arrays and TensorFlow while explaining image ranges, shapes, dtypes, and scaling directly.
What you can do after
Apply it via TensorFlow and tf.data to normalize training data and define preprocessing in a serving signature.
How it connects
Connects data ingestion, feature scaling, tf.data.Dataset, model training, TensorFlow Serving, and KServe.

Also explained in

Compare how 22 books explain preprocessing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Distributed Machine Learning Patterns. The section links point to the parts of the book it draws on.