SavedModel file does not exist when using Tensorflow hub

When trying to use the hub.load function from tensorflow_hub, I get an OSError: SavedModel file does not exist at: error.

The weird thing is that it worked a few days ago, so I don't quite understand why I'm getting this error now.

Code to reproduce:

import tensorflow as tf
import tensorflow_hub as hub

URL = 'https://tfhub.dev/google/universal-sentence-encoder/4'
embed = hub.load(URL)

Specific error received:

OSError                                   Traceback (most recent call last)
<ipython-input-11-dfb80f0299b2> in <module>
      1 URL = 'https://tfhub.dev/google/universal-sentence-encoder/4'
----> 2 embed = hub.load(URL)

~/opt/anaconda3/lib/python3.7/site-packages/tensorflow_hub/module_v2.py in load(handle, tags)
    100   if tags is None and is_hub_module_v1:
    101       tags = []
--> 102   obj = tf_v1.saved_model.load_v2(module_path, tags=tags)
    103   obj._is_hub_module_v1 = is_hub_module_v1  # pylint: disable=protected-access
    104   return obj

~/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/saved_model/load.py in load(export_dir, tags)
    576     ValueError: If `tags` don't match a MetaGraph in the SavedModel.
    577   """
--> 578   return load_internal(export_dir, tags)
    579 
    580 

~/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/saved_model/load.py in load_internal(export_dir, tags, loader_cls)
    586     tags = nest.flatten(tags)
    587   saved_model_proto, debug_info = (
--> 588       loader_impl.parse_saved_model_with_debug_info(export_dir))
    589 
    590   if (len(saved_model_proto.meta_graphs) == 1 and

~/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/saved_model/loader_impl.py in parse_saved_model_with_debug_info(export_dir)
     54     parsed. Missing graph debug info file is fine.
     55   """
---> 56   saved_model = _parse_saved_model(export_dir)
     57 
     58   debug_info_path = os.path.join(

~/opt/anaconda3/lib/python3.7/site-packages/tensorflow/python/saved_model/loader_impl.py in parse_saved_model(export_dir)
    111                   (export_dir,
    112                    constants.SAVED_MODEL_FILENAME_PBTXT,
--> 113                    constants.SAVED_MODEL_FILENAME_PB))
    114 
    115 

OSError: SavedModel file does not exist at: /var/folders/77/rvfl368x44s51r8dc3b6l2rh0000gn/T/tfhub_modules/063d866c06683311b44b4992fd46003be952409c/{saved_model.pbtxt|saved_model.pb}

Solution 1:

So, just deleting that folder and running the hub.load() function again solves the issue

Solution 2:

I have tried the above solution, but it didn't work for me...

Here's what worked:

  1. Download the model from tfhub.dev with assets, variables and .pb checkpoint file.
  2. Make sure you import tensorflow_text module!

import tensorflow_text

  1. Specify the downloaded folder path in the hub.load() statement as in:

model = hub.load("/Users/bilguun/Desktop/universal-sentence-encoder-multilingual-large_3/")