SavedModel file does not exist when using Tensorflow hub
Asked Answered
T

4

24

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}
Thresathresh answered 24/7, 2020 at 17:33 Comment(0)
T
54

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

Thresathresh answered 26/7, 2020 at 22:42 Comment(6)
See also: github.com/tensorflow/hub/issues/575#issuecomment-635769037Authorized
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" .Kutzenco
I think he refers to delete the entire folder ".../tfhub_modules/063d866c06683311b44b4992fd46003be952409c".Puffball
Thanks, this worked for me. I deleted folder like "063d866c06683311b44b4992fd46003be952409c"Flyer
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.Commons
Is there a way to avoid this issue in general? Has it been resolved? It still occurs for me with tensorflow '2.13.0' and tensorflow hub '0.14.0'Carin
A
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/")

Astromancy answered 28/9, 2020 at 6:15 Comment(0)
T
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.

Trinitarianism answered 24/5, 2021 at 21:29 Comment(0)
H
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 .

Heterophyte answered 21/1, 2022 at 18:33 Comment(1)
yes just we can delete the folder inside tfhub_modules folderOralla

© 2022 - 2025 — McMap. All rights reserved.