{"record":{"id":"91e170dd91460e7a","repo":"keras-team/keras","slug":"the-fill-value-argument-should-be-a-number-or-a","errorCode":null,"errorMessage":"The `fill_value` argument should be a number (or a list of three numbers) ","messagePattern":"The `fill_value` argument should be a number \\(or a list of three numbers\\) ","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/image_preprocessing/random_erasing.py","lineNumber":196,"sourceCode":"    def _get_fill_value(self, images, images_shape, seed):\n        fill_value = self.fill_value\n        if fill_value is None:\n            fill_value = (\n                self.backend.random.normal(\n                    images_shape,\n                    dtype=self.compute_dtype,\n                    seed=seed,\n                )\n                * self.value_range[1]\n            )\n        else:\n            error_msg = (\n                \"The `fill_value` argument should be a number \"\n                \"(or a list of three numbers) \"\n            )\n            if isinstance(fill_value, (tuple, list)):\n                if len(fill_value) != 3:\n                    raise ValueError(error_msg)\n                fill_value = self.backend.numpy.full_like(\n                    images, fill_value, dtype=self.compute_dtype\n                )\n            elif isinstance(fill_value, (int, float)):\n                fill_value = (\n                    self.backend.numpy.ones(\n                        images_shape, dtype=self.compute_dtype\n                    )\n                    * fill_value\n                )\n            else:\n                raise ValueError(error_msg)\n        fill_value = self.backend.numpy.clip(\n            fill_value, self.value_range[0], self.value_range[1]\n        )\n        return fill_value\n\n    def get_random_transformation(self, data, training=True, seed=None):","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/image_preprocessing/random_erasing.py#L178-L214","documentation":"RandomErasing._get_fill_value validates the fill_value argument at transformation-sampling time (called from get_random_transformation). When fill_value is a sequence it must contain exactly three numbers (one per RGB channel); any other length raises this ValueError. This only fires when a list/tuple was supplied instead of a scalar.","triggerScenarios":"fill_value=[0.5] or fill_value=[255, 255] (wrong length), or a per-channel list with a typo'd fourth entry.","commonSituations":"Assuming single-channel or grayscale semantics (one value) while the layer expects RGB triples; copying 4-element RGBA defaults from image tooling.","solutions":["Use a list of exactly three numbers, e.g. fill_value=[0.5, 0.5, 0.5]","Or pass a single scalar, e.g. fill_value=0.5, which is broadcast to all channels","Remember values are clipped to value_range afterwards, so supply them in the layer's value scale (e.g. 0-1 or 0-255 consistently)"],"exampleFix":"# before\nlayers.RandomErasing(fill_value=[125])\n# after\nlayers.RandomErasing(fill_value=0.5)","handlingStrategy":"validation","validationCode":"fv = [0.5, 0.5, 0.5]\nassert isinstance(fv, (int, float)) or (isinstance(fv, (tuple, list)) and len(fv) == 3), \"fill_value must be a number or 3 numbers\"","typeGuard":"def is_valid_fill_value(v) -> bool:\n    return isinstance(v, (int, float)) or (isinstance(v, (tuple, list)) and len(v) == 3)","tryCatchPattern":"try:\n    layer = RandomErasing(fill_value=fv)\nexcept ValueError:\n    layer = RandomErasing(fill_value=float(fv[0]) if len(fv) == 1 else 0.5)","preventionTips":["Prefer scalar fill_value; the layer broadcasts it","Keep fill values consistent with value_range (0-1 vs 0-255)"],"tags":["keras","preprocessing","argument-validation","shape"],"backgroundTag":"argument-shape-validation","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}