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

TensorFlow · Class

layers.Resizing

A Keras preprocessing layer that resizes individual images or batches to a chosen height and width. It supports several interpolation methods and optional aspect-ratio-preserving cropping or padding.

How it works

Resizing transforms each 3D image or 4D image batch to the requested height and width. By default it uses bilinear interpolation and channels-last ordering; optional cropping or padding can preserve the original aspect ratio instead of distorting the image.

Syntax

tf.keras.layers.Resizing(height, width, interpolation='bilinear', crop_to_aspect_ratio=False, pad_to_aspect_ratio=False, fill_mode='constant', fill_value=0.0, data_format=None, **kwargs)

Parameters

NameTypeDescription
heightintInteger output height.
widthintInteger output width.
interpolationstrInterpolation method; defaults to bilinear.
crop_to_aspect_ratioboolWhether to crop while preserving aspect ratio.
pad_to_aspect_ratioboolWhether to pad while preserving aspect ratio.
fill_modestrPadding fill mode.
fill_valuefloatPadding value.
data_formatstrInput dimension ordering: channels_last or channels_first.
**kwargsdictAdditional layer keyword arguments.

Returns

A 3D unbatched or 4D batched tensor resized to the target dimensions, with channel placement determined by data_format.

Key points

  • Resizing is a Keras preprocessing layer for standardizing image spatial dimensions.
  • Set height and width to define the output spatial resolution.
  • Interpolation can be selected from five documented methods.
  • The layer changes spatial size without requiring a particular pixel-value range.
  • Use crop_to_aspect_ratio when cropping is acceptable and preserving proportions matters.
  • Use pad_to_aspect_ratio when padding is preferable to cropping.

Common mistakes

  • Inputs must represent either one image or a batch; other tensor ranks are unsupported.
  • Match data_format to the tensor layout, especially when using channels_first.

Example: Resize a batch of images

import tensorflow as tf

images = tf.random.uniform((2, 32, 48, 3))
resize = tf.keras.layers.Resizing(64, 64)
output = resize(images)
print(output.shape)  # (2, 64, 64, 3)

Creates a resizing layer and applies it to a batch of RGB images.

When to use it

Normalize varying image sizes to a fixed resolution

Model input preprocessing

Crop or pad images without distortion

Aspect-ratio-sensitive vision tasks

Choose nearest interpolation for discrete-valued image data

Segmentation and other label-image pipelines

Interview questions

QWhat input and output shapes does Resizing support?

The layer accepts a 3D unbatched image or a 4D batch and produces the requested spatial dimensions. It supports channels_last by default and can also use channels_first.

Follow-up: How would you avoid geometric distortion? Enable crop_to_aspect_ratio or pad_to_aspect_ratio, choosing the option that matches the preprocessing requirement.

QWhich interpolation methods can the layer use?

Bilinear interpolation is the default. The documented alternatives are nearest, bicubic, lanczos3, and lanczos5.

Follow-up: Which method is often preferable for discrete masks? Nearest-neighbor interpolation avoids blending class IDs.

QHow can Resizing preserve aspect ratio?

crop_to_aspect_ratio preserves proportions by cropping the largest matching window before producing the target size. pad_to_aspect_ratio preserves proportions by adding padding instead.

Follow-up: What constraint applies when selecting these options? They cannot both be enabled simultaneously.

  • tf.keras.layers.Rescaling
  • tf.image.resize_with_pad
  • tf.keras.layers.RandomZoom

Source: tf.keras.layers.Resizing. Checked 2026-10-15.