keras-team/keras · error · ValueError

When the width of the images is unknown, `target_width` must

Error message

When the width of the images is unknown, `target_width` must be specified.Received images.shape={images_shape} and target_width={self.target_width}

What it means

Error "When the width of the images is unknown, `target_width` must be specified.Received images.shape={images_shape} and target_width={self.target_width}" thrown in keras-team/keras.

Source

Thrown at keras/src/ops/image.py:1935

            self.target_height,
            self.target_width,
        )

        if self.data_format == "channels_last":
            height_axis, width_axis = -3, -2
        else:
            height_axis, width_axis = -2, -1
        height, width = images_shape[height_axis], images_shape[width_axis]

        if height is None and self.target_height is None:
            raise ValueError(
                "When the height of the images is unknown, `target_height` "
                "must be specified."
                f"Received images.shape={images_shape} and "
                f"target_height={self.target_height}"
            )
        if width is None and self.target_width is None:
            raise ValueError(
                "When the width of the images is unknown, `target_width` "
                "must be specified."
                f"Received images.shape={images_shape} and "
                f"target_width={self.target_width}"
            )

        target_height = self.target_height
        if target_height is None:
            target_height = height - self.top_cropping - self.bottom_cropping
        target_width = self.target_width
        if target_width is None:
            target_width = width - self.left_cropping - self.right_cropping

        if height is not None:
            top_cropping = self.top_cropping
            bottom_cropping = self.bottom_cropping
            if top_cropping is None:
                top_cropping = height - target_height - bottom_cropping

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/ops/image.py:1935 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/0bff8044ec01c1e9. Report an issue: GitHub.