Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow Hub : Stuck while importing a model

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 ?

like image 730
Astariul Avatar asked Oct 23 '18 02:10

Astariul


People also ask

What is the difference between TensorFlow hub and a module?

TensorFlow Hub is a library for the publication, discovery, and consumption of reusable parts of machine learning models. A module is a self-contained piece of a TensorFlow graph, along with its weights and assets, that can be reused across different tasks in a process known as transfer learning.

What is savedmodel in TensorFlow 2?

Was this helpful? The SavedModel format of TensorFlow 2 is the recommended way to share pre-trained models and model pieces on TensorFlow Hub. It replaces the older TF1 Hub format and comes with a new set of APIs.

Is Keras hub compatible with TensorFlow 1?

(Typically, hub.KerasLayer is combined with other tf.keras.layers to build a Keras model or the model_fn of a TF2 Estimator.) These APIs can also load the legacy models in TF1 Hub format, within limits, see the compatibility guide. Users of TensorFlow 1 can update to TF 1.15 and then use the same APIs. Older versions of TF1 do not work.

Why is TensorFlow not working on my computer?

The main reason is tensorflow versions are different. As to us, we use a cloud gpu platform to train and save a tensorflow model, the version of tensorflow is 1.14.0 However, the version of tensorflow in our computer is 1.10.0. They are different. How to fix this error? If you are using anaconda, you can install tensorflow 1.14.0 by it.


1 Answers

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)
like image 186
Astariul Avatar answered Sep 29 '22 06:09

Astariul