Tensorflow Hub : Stuck while importing a model
Asked Answered
B

1

6

Trying to import some models with Tensorflow Hub with this code :

import tensorflow as tf
import tensorflow_hub as hub

elmo_model = hub.Module('https://tfhub.dev/google/elmo/2', trainable=True)

Makes my notebook stuck. The only log line appearing before getting stuck is :

INFO:tensorflow:Using /tmp/tfhub_modules to cache modules.

How to unstuck it and allow me to import models from Tensorflow Hub ?

Breeder answered 23/10, 2018 at 2:14 Comment(0)
B
8

It was simply about privileges : I couldn't access the default directory where Tensorflow Hub store the models (/tmp/tfhub_modules).

To solve it, I just choose a directory to store the models which I can access :

import os
import tensorflow as tf
import tensorflow_hub as hub

os.environ['TFHUB_CACHE_DIR'] = '/home/user/workspace/tf_cache'
elmo_model = hub.Module('https://tfhub.dev/google/elmo/2', trainable=True)
Breeder answered 23/10, 2018 at 2:14 Comment(4)
How did you find out that it was privileges issue?Kanal
I don't remember exactly, I just saw somewhere you could change this directory, and when I saw the default value, it strike me that it was not in my personal folderBreeder
Well done, this is hard to debug error. No error messages whatsoever.Kanal
What's odd for me is that I can write to /tmp and the /tmp/tfhub_modules folder exists. So Tensorflow was able to create the directory it wanted to but it still ended up failing silently down the road. Despite this, I still needed to change the TFHUB_CACHE_DIR to point to somewhere in my home directory for this to workNicobarese

© 2022 - 2024 — McMap. All rights reserved.