keras-team/keras · error · ValueError

Cannot convert '{shape}' to a shape.

Error message

Cannot convert '{shape}' to a shape.

What it means

Error "Cannot convert '{shape}' to a shape." thrown in keras-team/keras.

Source

Thrown at keras/src/backend/common/variables.py:596

        dtype = dtype.name
    elif hasattr(dtype, "__name__"):
        dtype = dtype.__name__
    elif hasattr(dtype, "__str__") and (
        "torch" in str(dtype) or "jax.numpy" in str(dtype)
    ):
        dtype = str(dtype).split(".")[-1]

    if dtype not in dtypes.ALLOWED_DTYPES:
        raise ValueError(f"Invalid dtype: {dtype}")
    return dtype


def standardize_shape(shape):
    if not isinstance(shape, tuple):
        if shape is None:
            raise ValueError("Undefined shapes are not supported.")
        if not hasattr(shape, "__iter__"):
            raise ValueError(f"Cannot convert '{shape}' to a shape.")
        if config.backend() == "tensorflow":
            if isinstance(shape, tf.TensorShape):
                # `tf.TensorShape` may contain `Dimension` objects.
                # We need to convert the items in it to either int or `None`
                shape = shape.as_list()

    if config.backend() == "jax":
        # Replace `_DimExpr` (dimension expression) with None
        from jax import export as jax_export

        shape = tuple(
            None if jax_export.is_symbolic_dim(d) else d for d in shape
        )

    if config.backend() == "torch":
        # Replace symbolic dimensions with None to preserve dynamic shapes
        # during torch.export tracing
        import torch

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/backend/common/variables.py:596 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/c1118679f64ca59e. Report an issue: GitHub.