Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Class

layers.Rescaling

Keras' Rescaling layer applies the same linear transformation to every input value: multiply by scale, then add offset. It is commonly used to convert image values such as [0, 255] into a model-friendly range such as [0, 1] or [-1, 1].

How it works

Rescaling applies an affine transformation independently to every input value: the value is multiplied by scale and then offset is added. It accepts integer or floating-point inputs, normally produces floating-point outputs, and performs the same transformation during training and inference.

Syntax

keras.layers.Rescaling(scale, offset=0.0, **kwargs)

Parameters

NameTypeDescription
scaleFloatFloating-point multiplier applied to each input value.
offsetFloatFloating-point value added after scaling; defaults to 0.0.
**kwargsKeyword argumentsBase layer keyword arguments, such as name and dtype.

Returns

A layer that outputs the transformed values; by default, outputs are floating-point.

Key points

  • Rescaling is a preprocessing layer for changing the numeric range of input values.
  • The operation is elementwise, so every value receives the same scale-and-offset transformation.
  • Set scale to 1/255 when converting standard 8-bit image values to the 0–1 interval.
  • Use scale=1/127.5 with offset=-1 to transform 8-bit image values to approximately −1–1.
  • The offset is added after multiplication, giving the formula output = input × scale + offset.
  • Additional base-layer configuration can be supplied through kwargs, including a layer name and dtype.

Common mistakes

  • Do not expect this layer to behave differently between training and inference; its transformation is always active.
  • Account for the output dtype when connecting the layer to later operations, especially when the input is integer-valued.
  • The layer can be placed in supported input pipelines without requiring a separate preprocessing stage.

Example: Scale image values to [0, 1]

import keras
from keras import layers

inputs = keras.Input(shape=(224, 224, 3), dtype="uint8")
outputs = layers.Rescaling(scale=1.0 / 255)(inputs)
model = keras.Model(inputs, outputs)

x = keras.ops.ones((1, 224, 224, 3), dtype="uint8") * 255
y = model(x)
print(y.dtype, keras.ops.max(y))

This model converts pixel values from 0–255 integers to floating-point values in the 0–1 range.

When to use it

Image normalization

Convert uint8 or floating-point image pixels from [0, 255] to [0, 1].

Pretrained-model input scaling

Prepare inputs for models whose expected preprocessing range is [-1, 1].

Pipeline preprocessing

Embed deterministic numeric preprocessing directly in a model or input pipeline.

Interview questions

QWhat transformation does Rescaling perform?

It computes an elementwise affine transform: each input value becomes input * scale + offset. For example, scale=1/255 maps [0,255] to [0,1].

Follow-up: How would you map [0,255] to [-1,1]? Use scale=1/127.5 and offset=-1.

QHow do you normalize 8-bit image values?

Use scale=1/255 for normalization to [0,1]. The layer applies this operation during both training and inference.

Follow-up: Would a training flag disable it during inference? No; the documentation says the rescaling is applied in both modes.

QWhat is the constructor signature and what do its arguments mean?

The constructor is keras.layers.Rescaling(scale, offset=0.0, **kwargs). scale and offset are floating-point transformation parameters, while kwargs accepts base-layer options such as name and dtype.

Follow-up: What can be passed through kwargs? Base Layer keyword arguments, including name and dtype.

  • keras.layers.Resizing
  • keras.layers.Normalization
  • keras.layers.RandomFlip
  • keras.Layer

Source: Rescaling layer - Keras. Checked 2026-10-15.