{"record":{"id":"b0717a6812348683","repo":"keras-team/keras","slug":"cannot-convert-shape-to-a-shape-negative-dime","errorCode":null,"errorMessage":"Cannot convert '{shape}' to a shape. Negative dimensions are not allowed.","messagePattern":"Cannot convert '(.+?)' to a shape\\. Negative dimensions are not allowed\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/common/variables.py","lineNumber":641,"sourceCode":"            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)\n\n    # This also turns subclasses of `tuple` (e.g. `torch.Size`) to plain tuple.\n    return tuple(standardized_shape)\n\n\ndef shape_equal(a_shape, b_shape):\n    \"\"\"Return whether a_shape == b_shape (allows None entries).\"\"\"\n    if len(a_shape) != len(b_shape):\n        return False\n    for e1, e2 in zip(a_shape, b_shape):\n        if e1 is not None and e2 is not None and e1 != e2:\n            return False\n    return True\n","sourceCodeStart":623,"sourceCodeEnd":659,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/common/variables.py#L623-L659","documentation":"Error \"Cannot convert '{shape}' to a shape. Negative dimensions are not allowed.\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/backend/common/variables.py:641 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"}