TensorFlow
SavedModel
TensorFlow Hub
Machine Learning
Troubleshooting

SavedModel file does not exist when using Tensorflow hub

Master System Design with Codemia

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

Introduction

The "SavedModel file does not exist" error usually means TensorFlow Hub was pointed at the wrong location, not that TensorFlow Hub itself is broken. Hub loaders expect either a valid remote module handle or a local directory that contains a proper SavedModel layout, including saved_model.pb or saved_model.pbtxt.

What TensorFlow Hub Expects

A local SavedModel module directory normally looks like this:

text
1my_module/
2  saved_model.pb
3  variables/
4  assets/

If you pass a path that points one level too high or one level too low, Hub cannot find the model entry file and raises the error.

A Correct Local Load

python
1import tensorflow_hub as hub
2
3handle = "/path/to/my_module"
4layer = hub.KerasLayer(handle, trainable=False)
5print("module loaded")

The important detail is that handle must point at the directory containing the SavedModel files, not at a zip file, not at the parent download cache, and not at a random checkpoint directory.

Common Wrong Paths

These path mistakes cause the error frequently:

  • passing a compressed archive path instead of an extracted directory
  • passing the parent directory of the SavedModel
  • passing a checkpoints directory instead of the SavedModel root
  • passing a model URL string that is not a valid TF Hub handle

A quick filesystem check usually reveals the problem faster than reading stack traces.

Verify the Directory Before Loading

python
1from pathlib import Path
2
3handle = Path("/path/to/my_module")
4
5print("exists:", handle.exists())
6print("saved_model.pb exists:", (handle / "saved_model.pb").exists())
7print("variables dir exists:", (handle / "variables").exists())

If saved_model.pb is missing at the exact directory you supplied, Hub is going to fail.

Remote Handle Versus Local Path

TensorFlow Hub supports two broad styles of handles:

  • a remote TF Hub module handle
  • a local filesystem path

For a local path:

python
layer = hub.KerasLayer("/models/text_encoder")

For a remote handle:

python
layer = hub.KerasLayer("https://tfhub.dev/google/nnlm-en-dim50/2")

If you download a module manually, make sure the extracted directory is complete and that you are pointing at the extracted SavedModel root, not the original download artifact.

Keras and SavedModel Compatibility

Sometimes the directory exists but still is not the kind of SavedModel TensorFlow Hub expects. Not every TensorFlow export is a Hub-ready module in the way your code assumes.

That is why it helps to test the directory with TensorFlow itself:

python
1import tensorflow as tf
2
3model = tf.saved_model.load("/path/to/my_module")
4print("loaded:", model)

If plain TensorFlow cannot load it either, the issue is with the export path or model contents, not with Hub-specific integration.

Be Careful with Caches and Temporary Directories

Hub downloads and caches modules under internal cache directories. If you manually move or partially copy those files, it is easy to end up with an incomplete structure.

A safer pattern is:

  • let Hub download the module from the official handle directly
  • or export and load from a clean local directory you control

Half-managed cache directories are a common source of this error.

Common Pitfalls

The biggest mistake is pointing Hub at the wrong directory level. The handle must resolve to the SavedModel root itself.

Another issue is passing an archive file or incomplete extraction result instead of a fully unpacked SavedModel directory.

A third problem is assuming every TensorFlow model directory is automatically compatible with hub.KerasLayer usage without checking the export format.

Summary

  • TensorFlow Hub expects a valid remote handle or a local directory containing a real SavedModel.
  • Check for saved_model.pb and the variables directory at the exact path you pass in.
  • Distinguish clearly between a remote module handle and a local filesystem path.
  • Test the same path with tf.saved_model.load if you are unsure whether the export is valid.
  • Most cases of this error come from a wrong or incomplete path, not from Hub itself.

Course illustration
Course illustration

All Rights Reserved.