{"record":{"id":"386c1c0061c2957a","repo":"keras-team/keras","slug":"patches-last-dim-flat-is-not-divisible-by-pr","errorCode":null,"errorMessage":"`patches` last dim ({flat}) is not divisible by prod(size) ({patch_volume}).","messagePattern":"`patches` last dim \\((.+?)\\) is not divisible by prod\\(size\\) \\((.+?)\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/image.py","lineNumber":1004,"sourceCode":"            expected_ndim_batched = 4\n            expected_ndim_unbatched = 3\n            spatial = self.output_size  # (H, W)\n\n        if original_ndim == expected_ndim_batched:\n            batch = patches_shape[0]\n        elif original_ndim == expected_ndim_unbatched:\n            batch = None\n        else:\n            raise ValueError(\n                f\"`patches` has unexpected rank for \"\n                f\"{'3D' if self.is_3d else '2D'} reconstruction. \"\n                f\"Expected {expected_ndim_unbatched} (unbatched) or \"\n                f\"{expected_ndim_batched} (batched). \"\n                f\"Received shape: {patches.shape}\"\n            )\n\n        if flat is not None and flat % patch_volume != 0:\n            raise ValueError(\n                f\"`patches` last dim ({flat}) is not divisible by \"\n                f\"prod(size) ({patch_volume}).\"\n            )\n\n        if self.data_format == \"channels_last\":\n            grid_offset = 1 if original_ndim == expected_ndim_batched else 0\n            grid = patches_shape[grid_offset : grid_offset + len(self.size)]\n        else:\n            # channels_first: the grid dims are the trailing dims,\n            # (B, flat, *grid) batched or (flat, *grid) unbatched.\n            grid = patches_shape[-len(self.size) :]\n        dim_names = (\"depth\", \"height\", \"width\")[-len(self.size) :]\n        for g, p, o, dim_name in zip(\n            grid, self.size, self.output_size, dim_names\n        ):\n            if not isinstance(g, int):\n                continue\n            if self.padding == \"valid\":","sourceCodeStart":986,"sourceCodeEnd":1022,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/image.py#L986-L1022","documentation":"Error \"`patches` last dim ({flat}) is not divisible by prod(size) ({patch_volume}).\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/ops/image.py:1004 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"}