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





















