23

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}
Kevin Sun
  • 1,171
  • 2
  • 8
  • 17

4 Answers4

52

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

Kevin Sun
  • 1,171
  • 2
  • 8
  • 17
  • See also: https://github.com/tensorflow/hub/issues/575#issuecomment-635769037 – maurice Aug 06 '20 at 21:24
  • 1
    Which folder needs to be deleted? My error: SavedModel file does not exist at: /tmp/tfhub_modules/063d866c06683311b44b4992fd46003be952409c/{saved_model.pbtxt|saved_model.pb} I see 2 empty folders named "assets" and "variables" in "/tmp/tfhub_modules/063d866c06683311b44b4992fd46003be952409c" . – FreeSid91 Aug 06 '21 at 20:41
  • 2
    I think he refers to delete the entire folder ".../tfhub_modules/063d866c06683311b44b4992fd46003be952409c". – Adelson Araújo Aug 09 '21 at 15:39
  • 3
    Thanks, this worked for me. I deleted folder like "063d866c06683311b44b4992fd46003be952409c" – Prabath Aug 16 '21 at 14:59
  • Thanks for the solution. This thing wasted half of my Sunday. Had I known to just delete the folder. I delete the folder tfhub_modules and then everything was fine. – George May 15 '23 at 02:54
4

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/")

Bilguun
  • 359
  • 2
  • 7
1

I was using i3d = hub.load(https://tfhub.dev/deepmind/i3d-kinetics-400/1).signatures['default'] as shown here

This method of loading the model worked in that day but after a few days I got the same error: OSError: SavedModel file does not exist at: C:\Users\catal\AppData\Local\Temp\tfhub_modules\092225fb776e28d6d64ac605ab6be03f18dd2027{saved_model.pbtxt|saved_model.pb}

After doing some research, I understood that the saved_model file location (specified in the error) was temporary so even if that folder still exists, there is no more saved_model.pb in it. So I downloaded the model linked here: https://tfhub.dev/deepmind/i3d-kinetics-400/1 and set i3d = hub.load("C:\\absolute_path_to_saved_model_folder").signatures['default'] and it worked.

So using Bilguun's answer really helped in my case.

Catalina
  • 21
  • 4
1

This kind of error happens because the downloaded model is saved in temporary folder created by the application.

Since it is a temporary folder, the model saved in it may gets deleted or even the folder can be deleted.

When calling the hub.load() command, the programme checks for the temporary folder, if the folder is not found, the program will download the data from internet.

But if the folder is found and the data(or model) is not there, instead of downloading from the internet, it raises an error.

It can be resolved by deleting the temporary folder completely.

In Mac the temporary folder can be accessed by the command "open $TMPDIR" on the terminal( reference : https://osxdaily.com/2018/08/17/where-temp-folder-mac-access/). The name of the folder can be get from the raised error and can be deleted easily .

Bian
  • 11
  • 2