Python
AutoTrackable
error
callable
programming

'AutoTrackable' object is not callable in Python

Master System Design with Codemia

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

Introduction

The 'AutoTrackable' object is not callable error occurs in TensorFlow when you try to call (invoke with parentheses) a loaded SavedModel object as if it were a function, but TensorFlow cannot find a callable signature. This typically happens when loading a SavedModel that was saved without specifying a concrete function signature, when accessing the wrong attribute on the loaded model, or when the model was saved using a method that does not preserve the __call__ method. The fix involves loading the model correctly and calling the right method or signature.

The Error

python
1import tensorflow as tf
2
3model = tf.saved_model.load('saved_model_dir/')
4
5# ERROR — trying to call the loaded object directly
6predictions = model(input_data)
7# TypeError: 'AutoTrackable' object is not callable

tf.saved_model.load() returns an AutoTrackable object (TensorFlow's base trackable class), not a Keras model. Unlike tf.keras.models.load_model(), it does not automatically have a __call__ method.

Why This Happens

TensorFlow's SavedModel format stores computation graphs as concrete functions. When you load a SavedModel, TensorFlow creates an AutoTrackable object with the saved functions as attributes. If the model was not saved with explicit signatures, the loaded object has no default callable.

python
1# How the model was saved matters
2model = tf.keras.Sequential([
3    tf.keras.layers.Dense(64, activation='relu'),
4    tf.keras.layers.Dense(10)
5])
6
7# Method 1: Keras save (preserves __call__)
8model.save('keras_model/')  # SavedModel format by default in TF2
9
10# Method 2: tf.saved_model.save (may not preserve __call__)
11tf.saved_model.save(model, 'saved_model/')

Fix 1: Use tf.keras.models.load_model() for Keras Models

python
1# If the model was saved with model.save()
2model = tf.keras.models.load_model('keras_model/')
3
4# Now it's a proper Keras model with __call__
5predictions = model(input_data)  # Works
6predictions = model.predict(input_data)  # Also works

Fix 2: Access the Concrete Function Signature

python
1# Load with tf.saved_model.load
2loaded = tf.saved_model.load('saved_model/')
3
4# List available signatures
5print(list(loaded.signatures.keys()))
6# ['serving_default']
7
8# Call using the signature
9infer = loaded.signatures['serving_default']
10result = infer(tf.constant(input_data))
11print(result)
12# {'output_0': <tf.Tensor: shape=(1, 10), ...>}

Fix 3: Access the __call__ Method Explicitly

python
1loaded = tf.saved_model.load('saved_model/')
2
3# Check if the model has a __call__ attribute
4if hasattr(loaded, '__call__'):
5    predictions = loaded(input_data)
6else:
7    # Try the serving signature
8    infer = loaded.signatures['serving_default']
9    predictions = infer(input_data=tf.constant(input_data))

Fix 4: Save with Explicit Signatures

When saving, specify concrete function signatures to ensure the model is callable after loading.

python
1# Save with explicit input signature
2model = tf.keras.Sequential([
3    tf.keras.layers.Dense(64, activation='relu', input_shape=(784,)),
4    tf.keras.layers.Dense(10)
5])
6
7# Method 1: Keras save (recommended)
8model.save('model_dir/')
9
10# Method 2: tf.saved_model.save with signatures
11call_fn = tf.function(model.__call__)
12concrete_fn = call_fn.get_concrete_function(
13    tf.TensorSpec(shape=[None, 784], dtype=tf.float32)
14)
15
16tf.saved_model.save(model, 'model_dir/', signatures={
17    'serving_default': concrete_fn
18})

Fix 5: Custom Model with @tf.function

python
1class MyModel(tf.Module):
2    def __init__(self):
3        self.dense = tf.keras.layers.Dense(10)
4
5    @tf.function(input_signature=[tf.TensorSpec(shape=[None, 784], dtype=tf.float32)])
6    def __call__(self, x):
7        return self.dense(x)
8
9model = MyModel()
10model(tf.zeros([1, 784]))  # Build the model
11
12tf.saved_model.save(model, 'custom_model/')
13
14# Loading — __call__ is preserved because of @tf.function with input_signature
15loaded = tf.saved_model.load('custom_model/')
16result = loaded(tf.constant([[1.0] * 784]))  # Works

Debugging the Loaded Object

python
1loaded = tf.saved_model.load('saved_model/')
2
3# Inspect available attributes
4print(dir(loaded))
5
6# Check signatures
7print(loaded.signatures)
8
9# List concrete functions
10for attr_name in dir(loaded):
11    attr = getattr(loaded, attr_name, None)
12    if callable(attr):
13        print(f"Callable: {attr_name}")
14
15# Check if it has variables (indicates a model with weights)
16print("Variables:", loaded.variables)
17print("Trainable:", loaded.trainable_variables)

Common Pitfalls

  • Using tf.saved_model.load for Keras models: tf.saved_model.load() returns an AutoTrackable, not a Keras model. For models saved with model.save(), always use tf.keras.models.load_model() which returns a fully functional Keras model with predict(), evaluate(), and __call__.
  • Not specifying input signatures when saving: Models saved without input_signature on @tf.function or without explicit signatures in tf.saved_model.save() may not have a callable default signature. Always provide input signatures for models intended for serving or loading.
  • Confusing the SavedModel directory with an HDF5 file: tf.keras.models.load_model() accepts both SavedModel directories and .h5 files. tf.saved_model.load() only accepts SavedModel directories. Using the wrong loader for the format causes errors.
  • Signature key mismatch: The default signature key is 'serving_default', but custom models may use different keys. Always check loaded.signatures.keys() to find available signatures before calling.
  • TensorFlow version mismatch: A SavedModel created with one TensorFlow version may not load correctly in another. Major version differences (TF 1.x vs 2.x) are especially problematic. Use the same TensorFlow version for saving and loading, or export to a version-compatible format.

Summary

  • Use tf.keras.models.load_model() for Keras models — it returns a callable model
  • Use loaded.signatures['serving_default'] to call models loaded with tf.saved_model.load()
  • Save with explicit input_signature or signatures parameter to ensure loaded models are callable
  • Inspect loaded.signatures.keys() and dir(loaded) to debug missing callable methods
  • AutoTrackable is TensorFlow's base class — it is not callable by default without saved signatures

Course illustration
Course illustration

All Rights Reserved.