{"record":{"id":"6807f06e9f899921","repo":"keras-team/keras","slug":"cannot-convert-shape-to-a-shape-found-invalid","errorCode":null,"errorMessage":"Cannot convert '{shape}' to a shape. Found invalid dimension '{d}' of type '{type(d)}'. ","messagePattern":"Cannot convert '(.+?)' to a shape\\. Found invalid dimension '(.+?)' of type '(.+?)'\\. ","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/common/variables.py","lineNumber":627,"sourceCode":"        )\n\n    if config.backend() == \"torch\":\n        # Replace symbolic dimensions with None to preserve dynamic shapes\n        # during torch.export tracing\n        import torch\n\n        shape = tuple(None if isinstance(d, torch.SymInt) else d for d in shape)\n\n    # Handle dimensions that are not ints and not None, verify they're >= 0.\n    standardized_shape = []\n    for d in shape:\n        if d is None:\n            standardized_shape.append(d)\n            continue\n\n        # Reject these even if they can be cast to int successfully.\n        if isinstance(d, (str, float)):\n            raise ValueError(\n                f\"Cannot convert '{shape}' to a shape. \"\n                f\"Found invalid dimension '{d}' of type '{type(d)}'. \"\n            )\n\n        try:\n            # Cast numpy scalars, tf constant tensors, etc.\n            d = int(d)\n        except Exception as e:\n            raise ValueError(\n                f\"Cannot convert '{shape}' to a shape. \"\n                f\"Found invalid dimension '{d}' of type '{type(d)}'. \"\n            ) from e\n        if d < 0:\n            raise ValueError(\n                f\"Cannot convert '{shape}' to a shape. \"\n                \"Negative dimensions are not allowed.\"\n            )\n        standardized_shape.append(d)","sourceCodeStart":609,"sourceCodeEnd":645,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/common/variables.py#L609-L645","documentation":"Error \"Cannot convert '{shape}' to a shape. Found invalid dimension '{d}' of type '{type(d)}'. \" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/backend/common/variables.py:627 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}