{"record":{"id":"be1143b8a14cab7a","repo":"keras-team/keras","slug":"input-shape-must-be-a-non-nested-tuple-or-list-o","errorCode":null,"errorMessage":"`input_shape` must be a non-nested tuple or list of rank-1 with size 3 (unbatched) or 4 (batched). ","messagePattern":"`input_shape` must be a non-nested tuple or list of rank-1 with size 3 \\(unbatched\\) or 4 \\(batched\\)\\. ","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/image_preprocessing/center_crop.py","lineNumber":251,"sourceCode":"                return inputs[\n                    h_start : h_start + self.height,\n                    w_start : w_start + self.width,\n                    :,\n                ]\n        return image_utils.smart_resize(\n            inputs,\n            [self.height, self.width],\n            interpolation=interpolation,\n            data_format=self.data_format,\n            backend_module=self.backend,\n        )\n\n    def compute_output_shape(self, input_shape):\n        input_shape = list(input_shape)\n        if isinstance(input_shape[0], (list, tuple)) or len(\n            input_shape\n        ) not in (3, 4):\n            raise ValueError(\n                \"`input_shape` must be a non-nested tuple or list \"\n                \"of rank-1 with size 3 (unbatched) or 4 (batched). \"\n            )\n        if len(input_shape) == 4:\n            if self.data_format == \"channels_last\":\n                input_shape[1] = self.height\n                input_shape[2] = self.width\n            else:\n                input_shape[2] = self.height\n                input_shape[3] = self.width\n        else:\n            if self.data_format == \"channels_last\":\n                input_shape[0] = self.height\n                input_shape[1] = self.width\n            else:\n                input_shape[1] = self.height\n                input_shape[2] = self.width\n        return tuple(input_shape)","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/image_preprocessing/center_crop.py#L233-L269","documentation":"CenterCrop.compute_output_shape only accepts a flat rank-1 shape of length 3 (H, W, C) or 4 (batch, H, W, C). Passing a nested structure (list of shapes, as when input is a dict/tuple of inputs) or a shape of length != 3/4 raises this ValueError.","triggerScenarios":"Calling layer.compute_output_shape([(None, 224, 224, 3)]) or compute_output_shape((None, 10, 224, 224, 3)); also building a model whose input spec is a nested structure routed to this layer.","commonSituations":"Multi-input models where Keras passes a list of shapes to each layer's compute_output_shape; manually probing output shapes with a wrapped shape; functional API with dict inputs.","solutions":["Pass a single flat shape: layer.compute_output_shape((None, 224, 224, 3))","If the layer receives nested inputs, extract the image shape: input_shape[0] or input_shape['images']","Upgrade keras — newer versions handle nested input specs in compute_output_shape for preprocessing layers"],"exampleFix":"# before\nout = layer.compute_output_shape([(None, 224, 224, 3)])\n# after\nout = layer.compute_output_shape((None, 224, 224, 3))","handlingStrategy":"validation","validationCode":"def flat_img_shape(s):\n    if isinstance(s[0], (list, tuple)):\n        s = s[0]\n    assert len(s) in (3, 4), f'bad image shape {s}'\n    return tuple(s)","typeGuard":"def is_flat_shape3or4(s):\n    return not isinstance(s[0], (list, tuple)) and len(s) in (3, 4)","tryCatchPattern":"try:\n    out = layer.compute_output_shape(input_shape)\nexcept ValueError:\n    out = layer.compute_output_shape(input_shape[0])","preventionTips":["Pass flat tuples of ints/None to compute_output_shape","Build the model with the exact input spec you feed at runtime to catch this at build time"],"tags":["keras","compute-output-shape","center-crop","model-building"],"backgroundTag":"input-shape-validation-failed","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}