keras/src/backend/torch/image.py/resize
def resize(
    images,
    size,
    interpolation="bilinear",
    antialias=False,
    crop_to_aspect_ratio=False,
    pad_to_aspect_ratio=False,
    fill_mode="constant",
    fill_value=0.0,
    data_format=None,
):
    data_format = backend.standardize_data_format(data_format)
    RESIZE_INTERPOLATIONS.update(
        {
            "bilinear": torchvision.transforms.InterpolationMode.BILINEAR,
            "nearest": torchvision.transforms.InterpolationMode.NEAREST_EXACT,
            "bicubic": torchvision.transforms.InterpolationMode.BICUBIC,
        }
    )
    if interpolation in UNSUPPORTED_INTERPOLATIONS:
        raise ValueError(
            "Resizing with Lanczos interpolation is "
            "not supported by the PyTorch backend. "
            f"Received: interpolation={interpolation}."
        )
    if interpolation not in RESIZE_INTERPOLATIONS:
        raise ValueError(
            "Invalid value for argument `interpolation`. Expected of one "
            f"{RESIZE_INTERPOLATIONS}. Received: interpolation={interpolation}"
        )
    if fill_mode != "constant":
        raise ValueError(
            "Invalid value for argument `fill_mode`. Only `'constant'` "
            f"is supported. Received: fill_mode={fill_mode}"
        )
    if pad_to_aspect_ratio and crop_to_aspect_ratio:
        raise ValueError(
            "Only one of `pad_to_aspect_ratio` & `crop_to_aspect_ratio` "
            "can be `True`."
        )
    if not len(size) == 2:
        raise ValueError(
            "Argument `size` must be a tuple of two elements "
            f"(height, width). Received: size={size}"
        )
    size = tuple(size)
    images = convert_to_tensor(images)
    if images.ndim not in (3, 4):
        raise ValueError(
            "Invalid images rank: expected rank 3 (single image) "
            "or rank 4 (batch of images). Received input with shape: "
            f"images.shape={images.shape}"
        )
    if data_format == "channels_last":
        if images.ndim == 4:
            images = images.permute((0, 3, 1, 2))
        else:
            images = images.permute((2, 0, 1))

    if crop_to_aspect_ratio:
        shape = images.shape
        height, width = shape[-2], shape[-1]
        target_height, target_width = size
        crop_height = int(float(width * target_height) / target_width)
        crop_height = max(min(height, crop_height), 1)
        crop_width = int(float(height * target_width) / target_height)
        crop_width = max(min(width, crop_width), 1)
        crop_box_hstart = int(float(height - crop_height) / 2)
        crop_box_wstart = int(float(width - crop_width) / 2)
        if len(images.shape) == 4:
            images = images[
                :,
                :,
                crop_box_hstart : crop_box_hstart + crop_height,
                crop_box_wstart : crop_box_wstart + crop_width,
            ]
        else:
            images = images[
                :,
                crop_box_hstart : crop_box_hstart + crop_height,
                crop_box_wstart : crop_box_wstart + crop_width,
            ]
    elif pad_to_aspect_ratio:
        shape = images.shape
        height, width = shape[-2], shape[-1]
        target_height, target_width = size
        pad_height = int(float(width * target_height) / target_width)
        pad_height = max(height, pad_height)
        pad_width = int(float(height * target_width) / target_height)
        pad_width = max(width, pad_width)
        img_box_hstart = int(float(pad_height - height) / 2)
        img_box_wstart = int(float(pad_width - width) / 2)
        if len(images.shape) == 4:
            batch_size = images.shape[0]
            channels = images.shape[1]
            padded_img = (
                torch.ones(
                    (
                        batch_size,
                        channels,
                        pad_height + height,
                        pad_width + width,
                    ),
                    dtype=images.dtype,
                )
                * fill_value
            )
            padded_img[
                :,
                :,
                img_box_hstart : img_box_hstart + height,
                img_box_wstart : img_box_wstart + width,
            ] = images
        else:
            channels = images.shape[0]
            padded_img = (
                torch.ones(
                    (channels, pad_height + height, pad_width + width),
                    dtype=images.dtype,
                )
                * fill_value
            )
            padded_img[
                :,
                img_box_hstart : img_box_hstart + height,
                img_box_wstart : img_box_wstart + width,
            ] = images
        images = padded_img

    resized = torchvision.transforms.functional.resize(
        img=images,
        size=size,
        interpolation=RESIZE_INTERPOLATIONS[interpolation],
        antialias=antialias,
    )
    if data_format == "channels_last":
        if len(images.shape) == 4:
            resized = resized.permute((0, 2, 3, 1))
        elif len(images.shape) == 3:
            resized = resized.permute((1, 2, 0))
    return resized