keras-team/keras · error · ValueError
Theta of a Thresholded ReLU layer cannot be None, expecting
Error message
Theta of a Thresholded ReLU layer cannot be None, expecting a float. Received: {theta} What it means
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.
Source
Thrown at keras/src/legacy/layers.py:222
def get_config(self):
config = {
"factor": self.factor,
"interpolation": self.interpolation,
"seed": self.seed,
}
base_config = super().get_config()
return {**base_config, **config}
@keras_export("keras._legacy.layers.ThresholdedReLU")
class ThresholdedReLU(Layer):
"""DEPRECATED."""
def __init__(self, theta=1.0, **kwargs):
super().__init__(**kwargs)
if theta is None:
raise ValueError(
"Theta of a Thresholded ReLU layer cannot be None, expecting a "
f"float. Received: {theta}"
)
if theta < 0:
raise ValueError(
"The theta value of a Thresholded ReLU layer "
f"should be >=0. Received: {theta}"
)
self.supports_masking = True
self.theta = tf.convert_to_tensor(theta, dtype=self.compute_dtype)
def call(self, inputs):
dtype = self.compute_dtype
return inputs * tf.cast(tf.greater(inputs, self.theta), dtype)
def get_config(self):
config = {"theta": float(self.theta)}
base_config = super().get_config()View on GitHub (pinned to 7a34a03db6)
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
Example fix
# before
theta = cfg.get('theta') # None when missing
layer = ThresholdedReLU(theta=theta)
# after
theta = cfg.get('theta', 1.0)
layer = ThresholdedReLU(theta=theta) Defensive patterns
Strategy: type-guard
Validate before calling
theta = cfg.get('theta', 1.0)
assert isinstance(theta, (int, float)), f'theta must be a float, got {theta!r}' Type guard
def is_valid_theta(t) -> bool:
return isinstance(t, (int, float)) and not isinstance(t, bool) Prevention
- 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
When it happens
Trigger: 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').
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- The theta value of a Thresholded ReLU layer should be >=0. R
- Expected `padding` to be a tuple of 3 tuples of 2 integers.
- Expected `padding` to be a tuple of 2 integers. Received: pa
- `factor` argument cannot have an upper bound lesser than the
- `factor` argument must have values larger than -1. Received:
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/8297940446801482.
Report an issue: GitHub.