keras-team/keras · error · ValueError

For `padding='same'`, `output_size` height ({H}) must be in

Error message

For `padding='same'`, `output_size` height ({H}) must be in the range ((gH-1)*pH, gH*pH], i.e. ({static_gH * pH - pH}, {static_gH * pH}]. Got: gH={static_gH}, pH={pH}.

What it means

Error "For `padding='same'`, `output_size` height ({H}) must be in the range ((gH-1)*pH, gH*pH], i.e. ({static_gH * pH - pH}, {static_gH * pH}]. Got: gH={static_gH}, pH={pH}." thrown in keras-team/keras.

Source

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

    else:
        if static_flat % (pH * pW) != 0:
            raise ValueError(
                f"`patches` last dim ({static_flat}) is not divisible by "
                f"prod(size) ({pH * pW})."
            )
        C = static_flat // (pH * pW)

    x = backend.numpy.reshape(patches, (B, gH, gW, pH, pW, C))
    x = backend.numpy.transpose(x, axes=(0, 1, 3, 2, 4, 5))
    x = backend.numpy.reshape(x, (B, gH * pH, gW * pW, C))

    if padding == "same":
        static_gH = patches.shape[1]
        static_gW = patches.shape[2]
        if isinstance(static_gH, int) and not (
            static_gH * pH - pH < H <= static_gH * pH
        ):
            raise ValueError(
                f"For `padding='same'`, `output_size` height ({H}) must "
                f"be in the range ((gH-1)*pH, gH*pH], i.e. "
                f"({static_gH * pH - pH}, {static_gH * pH}]. "
                f"Got: gH={static_gH}, pH={pH}."
            )
        if isinstance(static_gW, int) and not (
            static_gW * pW - pW < W <= static_gW * pW
        ):
            raise ValueError(
                f"For `padding='same'`, `output_size` width ({W}) must "
                f"be in the range ((gW-1)*pW, gW*pW], i.e. "
                f"({static_gW * pW - pW}, {static_gW * pW}]. "
                f"Got: gW={static_gW}, pW={pW}."
            )
        pad_total_h = gH * pH - H
        pad_total_w = gW * pW - W
        begin = [0, pad_total_h // 2, pad_total_w // 2, 0]
        out_shape = [B, H, W, C]

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/ops/image.py:1286 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/0be04593694ebadd. Report an issue: GitHub.