This layer resizes an image input to a target height and width. The input
should be a 4D (batched) or 3D (unbatched) tensor in "channels_last"
format. Input pixel values can be of any range
(e.g. [0., 1.) or [0, 255]).
Input shape
3D
unbatched) or 4D (batched) tensor with shape
(..., height, width, channels), in "channels_last" format,
or (..., channels, height, width), in "channels_first" format.
Output shape
3D
unbatched) or 4D (batched) tensor with shape
(..., target_height, target_width, channels),
or (..., channels, target_height, target_width),
in "channels_first" format.
Args
height
Integer, the height of the output shape.
width
Integer, the width of the output shape.
interpolation
String, the interpolation method.
Supports "bilinear", "nearest", "bicubic",
"lanczos3", "lanczos5". Defaults to "bilinear".
crop_to_aspect_ratio
If True, resize the images without aspect
ratio distortion. When the original aspect ratio differs
from the target aspect ratio, the output image will be
cropped so as to return the
largest possible window in the image (of size (height, width))
that matches the target aspect ratio. By default
(crop_to_aspect_ratio=False), aspect ratio may not be preserved.
pad_to_aspect_ratio
If True, pad the images without aspect
ratio distortion. When the original aspect ratio differs
from the target aspect ratio, the output image will be
evenly padded on the short side.
fill_mode
When using pad_to_aspect_ratio=True, padded areas
are filled according to the given mode. Only "constant" is
supported at this time
(fill with constant value, equal to fill_value).
fill_value
Float. Padding value to use when pad_to_aspect_ratio=True.
data_format
string, either "channels_last" or "channels_first".
The ordering of the dimensions in the inputs. "channels_last"
corresponds to inputs with shape (batch, height, width, channels)
while "channels_first" corresponds to inputs with shape
(batch, channels, height, width). It defaults to the
image_data_format value found in your Keras config file at
~/.keras/keras.json. If you never set it, then it will be
"channels_last".
**kwargs
Base layer keyword arguments, such as name and dtype.
Attributes
input
Retrieves the input tensor(s) of a symbolic operation.
Only returns the tensor(s) corresponding to the first time
the operation was called.
output
Retrieves the output tensor(s) of a layer.
Only returns the tensor(s) corresponding to the first time
the operation was called.
This method is the reverse of get_config,
capable of instantiating the same layer from the config
dictionary. It does not handle layer connectivity
(handled by Network), nor weights (handled by set_weights).
Args
config
A Python dictionary, typically the
output of get_config.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.layers.Resizing\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/layers/preprocessing/resizing.py#L6-L127) |\n\nA preprocessing layer which resizes images.\n\nInherits From: [`Layer`](../../../tf/keras/Layer), [`Operation`](../../../tf/keras/Operation) \n\n tf.keras.layers.Resizing(\n height,\n width,\n interpolation='bilinear',\n crop_to_aspect_ratio=False,\n pad_to_aspect_ratio=False,\n fill_mode='constant',\n fill_value=0.0,\n data_format=None,\n **kwargs\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Simple audio recognition: Recognizing keywords](https://www.tensorflow.org/tutorials/audio/simple_audio) - [Data augmentation](https://www.tensorflow.org/tutorials/images/data_augmentation) |\n\nThis layer resizes an image input to a target height and width. The input\nshould be a 4D (batched) or 3D (unbatched) tensor in `\"channels_last\"`\nformat. Input pixel values can be of any range\n(e.g. `[0., 1.)` or `[0, 255]`).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Input shape ----------- ||\n|------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `3D` | `unbatched) or 4D (batched) tensor with shape` \u003cbr /\u003e `(..., height, width, channels)`, in `\"channels_last\"` format, or `(..., channels, height, width)`, in `\"channels_first\"` format. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Output shape ------------ ||\n|------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `3D` | `unbatched) or 4D (batched) tensor with shape` \u003cbr /\u003e `(..., target_height, target_width, channels)`, or `(..., channels, target_height, target_width)`, in `\"channels_first\"` format. |\n\n\u003cbr /\u003e\n\n| **Note:** This layer is safe to use inside a [`tf.data`](../../../tf/data) pipeline (independently of which backend you're using).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `height` | Integer, the height of the output shape. |\n| `width` | Integer, the width of the output shape. |\n| `interpolation` | String, the interpolation method. Supports `\"bilinear\"`, `\"nearest\"`, `\"bicubic\"`, `\"lanczos3\"`, `\"lanczos5\"`. Defaults to `\"bilinear\"`. |\n| `crop_to_aspect_ratio` | If `True`, resize the images without aspect ratio distortion. When the original aspect ratio differs from the target aspect ratio, the output image will be cropped so as to return the largest possible window in the image (of size `(height, width)`) that matches the target aspect ratio. By default (`crop_to_aspect_ratio=False`), aspect ratio may not be preserved. |\n| `pad_to_aspect_ratio` | If `True`, pad the images without aspect ratio distortion. When the original aspect ratio differs from the target aspect ratio, the output image will be evenly padded on the short side. |\n| `fill_mode` | When using `pad_to_aspect_ratio=True`, padded areas are filled according to the given mode. Only `\"constant\"` is supported at this time (fill with constant value, equal to `fill_value`). |\n| `fill_value` | Float. Padding value to use when `pad_to_aspect_ratio=True`. |\n| `data_format` | string, either `\"channels_last\"` or `\"channels_first\"`. The ordering of the dimensions in the inputs. `\"channels_last\"` corresponds to inputs with shape `(batch, height, width, channels)` while `\"channels_first\"` corresponds to inputs with shape `(batch, channels, height, width)`. It defaults to the `image_data_format` value found in your Keras config file at `~/.keras/keras.json`. If you never set it, then it will be `\"channels_last\"`. |\n| `**kwargs` | Base layer keyword arguments, such as `name` and `dtype`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|----------|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input` | Retrieves the input tensor(s) of a symbolic operation. \u003cbr /\u003e Only returns the tensor(s) corresponding to the *first time* the operation was called. |\n| `output` | Retrieves the output tensor(s) of a layer. \u003cbr /\u003e Only returns the tensor(s) corresponding to the *first time* the operation was called. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `from_config`\n\n[View source](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/operation.py#L191-L213) \n\n @classmethod\n from_config(\n config\n )\n\nCreates a layer from its config.\n\nThis method is the reverse of `get_config`,\ncapable of instantiating the same layer from the config\ndictionary. It does not handle layer connectivity\n(handled by Network), nor weights (handled by `set_weights`).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------|----------------------------------------------------------|\n| `config` | A Python dictionary, typically the output of get_config. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A layer instance. ||\n\n\u003cbr /\u003e\n\n### `symbolic_call`\n\n[View source](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/operation.py#L58-L70) \n\n symbolic_call(\n *args, **kwargs\n )"]]