{"record":{"id":"8297940446801482","repo":"keras-team/keras","slug":"theta-of-a-thresholded-relu-layer-cannot-be-none","errorCode":null,"errorMessage":"Theta of a Thresholded ReLU layer cannot be None, expecting a float. Received: {theta}","messagePattern":"Theta of a Thresholded ReLU layer cannot be None, expecting a float\\. Received: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/legacy/layers.py","lineNumber":222,"sourceCode":"\n    def get_config(self):\n        config = {\n            \"factor\": self.factor,\n            \"interpolation\": self.interpolation,\n            \"seed\": self.seed,\n        }\n        base_config = super().get_config()\n        return {**base_config, **config}\n\n\n@keras_export(\"keras._legacy.layers.ThresholdedReLU\")\nclass ThresholdedReLU(Layer):\n    \"\"\"DEPRECATED.\"\"\"\n\n    def __init__(self, theta=1.0, **kwargs):\n        super().__init__(**kwargs)\n        if theta is None:\n            raise ValueError(\n                \"Theta of a Thresholded ReLU layer cannot be None, expecting a \"\n                f\"float. Received: {theta}\"\n            )\n        if theta < 0:\n            raise ValueError(\n                \"The theta value of a Thresholded ReLU layer \"\n                f\"should be >=0. Received: {theta}\"\n            )\n        self.supports_masking = True\n        self.theta = tf.convert_to_tensor(theta, dtype=self.compute_dtype)\n\n    def call(self, inputs):\n        dtype = self.compute_dtype\n        return inputs * tf.cast(tf.greater(inputs, self.theta), dtype)\n\n    def get_config(self):\n        config = {\"theta\": float(self.theta)}\n        base_config = super().get_config()","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/legacy/layers.py#L204-L240","documentation":"The deprecated ThresholdedReLU layer requires a numeric `theta` (the activation threshold); passing theta=None raises this ValueError because the constructor immediately converts theta to a tensor of the layer's compute dtype, which None cannot satisfy. The default is 1.0, so this fires only when None is passed explicitly — most often an unset config key forwarded verbatim.","triggerScenarios":"Constructing keras._legacy.layers.ThresholdedReLU(theta=None) — typically because a config dict/YAML omitted or nullified theta and the value was forwarded via .get('theta').","commonSituations":"Building layers from hyperparameter dicts where dict.get('theta') yields None; deserializing configs written for a different layer where theta is absent; config merges where None overrides a default.","solutions":["Omit theta entirely to use the default 1.0, or pass an explicit float","Replace config.get('theta') with config.get('theta', 1.0)","If theta is computed dynamically, assert it is numeric before constructing the layer"],"exampleFix":"# before\ntheta = cfg.get('theta')  # None when missing\nlayer = ThresholdedReLU(theta=theta)\n# after\ntheta = cfg.get('theta', 1.0)\nlayer = ThresholdedReLU(theta=theta)","handlingStrategy":"type-guard","validationCode":"theta = cfg.get('theta', 1.0)\nassert isinstance(theta, (int, float)), f'theta must be a float, got {theta!r}'","typeGuard":"def is_valid_theta(t) -> bool:\n    return isinstance(t, (int, float)) and not isinstance(t, bool)","tryCatchPattern":null,"preventionTips":["Use dict.get('theta', 1.0) instead of dict.get('theta') for optional layer params","Fail fast on None values from configs rather than forwarding them"],"tags":["keras","activation","argument-validation","legacy","relu"],"backgroundTag":"missing-required-argument","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}