keras-team/keras · error · ValueError
Invalid `floatx` configuration. Expected one of
Error message
Invalid `floatx` configuration. Expected one of {'float16', 'float32', 'float64'}. Received: floatx={_floatx} What it means
Raised at keras.backend.config import time when ~/.keras/keras.json sets 'floatx' to a value outside {'float16','float32','float64'}. The config file is parsed eagerly on first import, so a hand-edited or corrupted floatx value aborts import of the module itself.
Solutions
- Edit ~/.keras/keras.json and set "floatx" to "float16", "float32", or "float64".
- Or delete/rename ~/.keras/keras.json so defaults are regenerated.
- Note this file is also written by keras.config.set_floatx; fix any code that wrote an invalid value.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/backend/config.py:305 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/caa3d273fd1dcefa.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/config.py:305
_KERAS_DIR = os.path.join(_keras_base_dir, ".keras")
def keras_home():
# Private accessor for the keras home location.
return _KERAS_DIR
# Attempt to read Keras config file.
_config_path = os.path.expanduser(os.path.join(_KERAS_DIR, "keras.json"))
if os.path.exists(_config_path):
try:
with open(_config_path) as f:
_config = json.load(f)
except ValueError:
_config = {}
_floatx = _config.get("floatx", floatx())
if _floatx not in {"float16", "float32", "float64"}:
raise ValueError(
"Invalid `floatx` configuration. "
"Expected one of {'float16', 'float32', 'float64'}. "
f"Received: floatx={_floatx}"
)
_epsilon = _config.get("epsilon", epsilon())
if not isinstance(_epsilon, float):
raise ValueError(
"Invalid `epsilon` configuration. "
"Expected a float. "
f"Received: epsilon={_epsilon}"
)
_backend = _config.get("backend", _BACKEND)
_image_data_format = _config.get("image_data_format", image_data_format())
if _image_data_format not in {"channels_last", "channels_first"}:
raise ValueError(
"Invalid `image_data_format` configuration. "
"Expected one of {'channels_last', 'channels_first'}. "
f"Received: image_data_format={_image_data_format}"View on GitHub (pinned to 7a34a03db6)