keras-team/keras · error · ValueError
The theta value of a Thresholded ReLU layer should be >=0. R
Error message
The theta value of a Thresholded ReLU layer should be >=0. Received: {theta} What it means
ThresholdedReLU activates inputs strictly greater than `theta`, and the layer requires theta >= 0 so it behaves as a threshold on positive activations. __init__ raises this ValueError when a negative theta is passed, whether directly or from a loaded config.
Source
Thrown at keras/src/legacy/layers.py:227
"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()
return {**base_config, **config}
def compute_output_shape(self, input_shape):
return input_shape
View on GitHub (pinned to 7a34a03db6)
Solutions
- Use theta >= 0, e.g. ThresholdedReLU(theta=0.5); theta=0 degenerates toward plain ReLU — prefer keras.layers.ReLU then
- Clip swept theta values to [0, inf) or constrain the search space
- Validate deserialized configs before layer construction
Example fix
# before layer = ThresholdedReLU(theta=-0.5) # after layer = ThresholdedReLU(theta=0.5)
Defensive patterns
Strategy: validation
Validate before calling
theta = cfg.get('theta', 1.0)
assert theta >= 0, f'theta must be >= 0, got {theta}' Type guard
def is_valid_theta(t) -> bool:
return isinstance(t, (int, float)) and t >= 0 Prevention
- Clip theta in sweeps: theta = max(0.0, theta)
- Prefer keras.layers.ReLU(threshold=...) in new code; it documents the same >=0 contract
When it happens
Trigger: Constructing ThresholdedReLU(theta=-0.5) or loading a serialized model config containing a negative theta value.
Common situations: Tuning theta via a sweep that crosses zero without constraints; hand-editing saved model configs; confusing theta with a bias-like parameter that is allowed to be negative.
Related errors
- Theta of a Thresholded ReLU layer cannot be None, expecting
- 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/b6081c039308d9aa.
Report an issue: GitHub.