tensorflow
machine learning
model saving
error troubleshooting
python

saving a model I get module 'tensorflow.python.saved_model.registration' has no attribute 'get_registered_name'

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The error module 'tensorflow.python.saved_model.registration' has no attribute 'get_registered_name' occurs due to a version mismatch between TensorFlow and Keras (or other TensorFlow-dependent libraries like tensorflow-hub or keras-nlp). This internal function was introduced or moved in specific TensorFlow versions, and mixing incompatible versions causes the attribute lookup to fail. The fix is to ensure TensorFlow, Keras, and all TF-related packages are on compatible versions — typically by upgrading everything to the latest stable release or pinning exact compatible versions.

When This Error Occurs

python
1import tensorflow as tf
2
3model = tf.keras.Sequential([
4    tf.keras.layers.Dense(128, activation='relu'),
5    tf.keras.layers.Dense(10, activation='softmax')
6])
7model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')
8model.fit(x_train, y_train, epochs=5)
9
10model.save('my_model')
11# AttributeError: module 'tensorflow.python.saved_model.registration'
12# has no attribute 'get_registered_name'

This can also happen during tf.saved_model.save(), model.save(), or when loading a saved model with tf.keras.models.load_model().

Fix 1: Upgrade TensorFlow and Keras

bash
1# Upgrade to latest compatible versions
2pip install --upgrade tensorflow
3
4# If using separate keras package
5pip install --upgrade keras
6
7# Verify versions match
8python -c "import tensorflow as tf; print(tf.__version__)"
9python -c "import keras; print(keras.__version__)"

TensorFlow 2.x bundles Keras internally (tf.keras). If you also have a standalone keras package installed, version conflicts arise.

Fix 2: Pin Compatible Versions

bash
1# Uninstall conflicting packages first
2pip uninstall tensorflow keras tf-keras tensorflow-estimator -y
3
4# Install a known compatible set
5pip install tensorflow==2.15.0
6
7# Or for TF 2.16+ which uses standalone keras 3
8pip install tensorflow==2.16.1 keras==3.3.3

Check version compatibility:

python
1import tensorflow as tf
2import keras
3
4print(f"TensorFlow: {tf.__version__}")
5print(f"Keras: {keras.__version__}")
6print(f"tf.keras version: {tf.keras.__version__}")
7
8# Ensure tf.keras and keras point to the same version

Fix 3: Use a Virtual Environment

bash
1# Create a clean environment
2python -m venv tf_env
3source tf_env/bin/activate  # Linux/macOS
4# tf_env\Scripts\activate   # Windows
5
6# Install TensorFlow (installs compatible Keras automatically)
7pip install tensorflow
8
9# Verify clean install
10pip list | grep -i -E "tensorflow|keras"

Fix 4: Clean Reinstall

When version conflicts persist:

bash
1# Nuclear option: remove everything TF-related
2pip uninstall tensorflow tensorflow-gpu tf-keras keras \
3    tensorflow-estimator tensorflow-hub tensorboard \
4    tensorflow-io tensorflow-text -y
5
6# Clean pip cache
7pip cache purge
8
9# Fresh install
10pip install tensorflow

Fix 5: Use tf.keras Consistently

python
1# WRONG — mixing standalone keras with tf.keras
2import keras
3from keras.layers import Dense  # standalone keras
4
5import tensorflow as tf
6model = tf.keras.Sequential([Dense(128)])  # tf.keras
7
8# RIGHT — use tf.keras everywhere
9import tensorflow as tf
10
11model = tf.keras.Sequential([
12    tf.keras.layers.Dense(128, activation='relu'),
13    tf.keras.layers.Dense(10, activation='softmax')
14])
15
16# Or import from tf.keras consistently
17from tensorflow.keras.layers import Dense
18from tensorflow.keras.models import Sequential

Alternative Save Formats

If the error persists during saving, try alternative formats:

python
1# SavedModel format (default) — uses the registration module
2model.save('my_model')  # May trigger the error
3
4# HDF5 format — different serialization path
5model.save('my_model.h5')
6
7# Weights only (avoids model serialization entirely)
8model.save_weights('my_model_weights.h5')
9
10# ONNX export (framework-independent)
11# pip install tf2onnx
12import tf2onnx
13spec = (tf.TensorSpec((None, 784), tf.float32, name="input"),)
14model_proto, _ = tf2onnx.convert.from_keras(model, input_signature=spec)

Diagnosing the Issue

python
1import tensorflow as tf
2import sys
3
4# Check all TF-related package versions
5print(f"Python: {sys.version}")
6print(f"TensorFlow: {tf.__version__}")
7
8try:
9    import keras
10    print(f"Keras (standalone): {keras.__version__}")
11except ImportError:
12    print("No standalone keras")
13
14try:
15    print(f"tf.keras: {tf.keras.__version__}")
16except AttributeError:
17    print("tf.keras version not accessible")
18
19# Check if the problematic module exists
20try:
21    from tensorflow.python.saved_model import registration
22    print(f"Registration module: {dir(registration)}")
23    print(f"Has get_registered_name: {hasattr(registration, 'get_registered_name')}")
24except ImportError:
25    print("Registration module not found")

Common Pitfalls

  • Mixing keras and tf.keras imports: TensorFlow 2.x bundles its own Keras as tf.keras. Installing the standalone keras package alongside TensorFlow creates two competing Keras installations with different internal registrations. Use tf.keras exclusively, or uninstall the standalone keras package.
  • Upgrading TensorFlow without upgrading dependent packages: Libraries like tensorflow-hub, tensorflow-text, keras-nlp, and tensorflow-addons depend on specific TensorFlow internals. Upgrading TensorFlow alone while keeping old versions of these libraries causes attribute errors. Upgrade all TF-related packages together.
  • Using pip install tensorflow-gpu on TF 2.x: Since TensorFlow 2.1+, GPU support is included in the base tensorflow package. Installing tensorflow-gpu separately can pull in a different TensorFlow version, creating conflicts. Use pip install tensorflow only.
  • Conda and pip mixing: Installing TensorFlow with conda and other packages with pip (or vice versa) can cause conflicting dependency resolutions. Stick to one package manager. If using conda, install TensorFlow with conda install tensorflow.
  • Not restarting the Python runtime after upgrading: After pip install --upgrade tensorflow, existing Python processes still use the old version loaded in memory. Restart your Jupyter kernel, Python script, or IDE to pick up the new version.

Summary

  • This error is caused by TensorFlow/Keras version mismatches — the internal registration module API changed between versions
  • Upgrade TensorFlow and all TF-related packages together: pip install --upgrade tensorflow
  • Use tf.keras consistently — never mix standalone keras imports with tf.keras
  • Use a clean virtual environment to avoid dependency conflicts
  • As a workaround, save in HDF5 format (model.save('model.h5')) which bypasses the SavedModel registration system

Course illustration
Course illustration

All Rights Reserved.