keras-team/keras · error · ValueError
Received an invalid value for `threshold`, expected a float…
Error message
Received an invalid value for `threshold`, expected a float or None. Received: threshold={threshold} What it means
Type guard in TernaryDense.__init__: `threshold` may be None (auto) or an int/float; any other type (string, array, etc.) is rejected before the sign check. The offending value is printed in the message.
Solutions
- Pass a float such as threshold=0.05, or None to use the automatic default
- Convert numeric strings/arrays to float before constructing the layer
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at keras/src/layers/core/ternary_dense.py:130 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/9d4179ab3df84b5c.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/core/ternary_dense.py:130
threshold=None,
activation=None,
use_bias=True,
kernel_initializer="glorot_uniform",
bias_initializer="zeros",
kernel_regularizer=None,
bias_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
bias_constraint=None,
**kwargs,
):
if not isinstance(units, int) or units <= 0:
raise ValueError(
"Received an invalid value for `units`, expected a positive "
f"integer. Received: units={units}"
)
if threshold is not None and not isinstance(threshold, (int, float)):
raise ValueError(
"Received an invalid value for `threshold`, expected a float "
f"or None. Received: threshold={threshold}"
)
if threshold is not None and threshold < 0:
raise ValueError(
"Received an invalid value for `threshold`, expected a "
"non-negative float or None. "
f"Received: threshold={threshold}"
)
super().__init__(activity_regularizer=activity_regularizer, **kwargs)
self.units = units
self.threshold = threshold
self.activation = activations.get(activation)
self.use_bias = use_bias
self.kernel_initializer = initializers.get(kernel_initializer)
self.bias_initializer = initializers.get(bias_initializer)
self.kernel_regularizer = regularizers.get(kernel_regularizer)View on GitHub (pinned to 7a34a03db6)