ele_coder
ele_coder

Reputation: 11

Unable to import TensorFlow_hub, getting "AttributeError: module 'tensorflow' has no attribute 'flags'" message

I am trying to import TensorFlow hub in my local jupyter notebook but unable to do so. I have created a local conda environment installed all packages. Current tf version: Tensorflow 2.0 and local tf hub version : tensorflow-hub 0.1.1. when I run the "import tensorflow_hub as hub" code i get the below error.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-86-5c017171c13e> in <module>
----> 1 import tensorflow_hub as hub

~\Anaconda3\Anaconda33\envs\myPython\lib\site-packages\tensorflow_hub\__init__.py in <module>
     23 from tensorflow_hub.estimator import LatestModuleExporter
     24 from tensorflow_hub.estimator import register_module_for_export
---> 25 from tensorflow_hub.feature_column import image_embedding_column
     26 from tensorflow_hub.feature_column import text_embedding_column
     27 from tensorflow_hub.image_util import get_expected_image_size

~\Anaconda3\Anaconda33\envs\myPython\lib\site-packages\tensorflow_hub\feature_column.py in <module>
     23 import tensorflow as tf
     24 from tensorflow_hub import image_util
---> 25 from tensorflow_hub import module
     26 
     27 # TODO(b/73987364): It is not possible to extend feature columns without

~\Anaconda3\Anaconda33\envs\myPython\lib\site-packages\tensorflow_hub\module.py in <module>
     21 import tensorflow as tf
     22 from tensorflow_hub import module_spec
---> 23 from tensorflow_hub import native_module
     24 from tensorflow_hub import tensor_info
     25 

~\Anaconda3\Anaconda33\envs\myPython\lib\site-packages\tensorflow_hub\native_module.py in <module>
     24 import tensorflow as tf
     25 
---> 26 from tensorflow_hub import compressed_module_resolver
     27 from tensorflow_hub import module_def_pb2
     28 from tensorflow_hub import module_impl

~\Anaconda3\Anaconda33\envs\myPython\lib\site-packages\tensorflow_hub\compressed_module_resolver.py in <module>
     33 import tensorflow as tf
     34 
---> 35 from tensorflow_hub import resolver
     36 
     37 

~\Anaconda3\Anaconda33\envs\myPython\lib\site-packages\tensorflow_hub\resolver.py in <module>
     32 from tensorflow_hub import tf_utils
     33 
---> 34 FLAGS = tf.flags.FLAGS
     35 
     36 tf.flags.DEFINE_string(

AttributeError: module 'tensorflow' has no attribute 'flags'

Upvotes: 1

Views: 3673

Answers (1)

user11530462
user11530462

Reputation:

Since TensorFlow Hub's initial support for Tensorflow 2.0 started from TensorFlow Hub 0.3.0 version, the issue is in the version of TensorFlow Hub(0.1.1) you are using which only supports Tensorflow 1.x versions.

Upgrade your TensorFlow Hub to latest( 0.8.0 as of today) using below command.

pip install --upgrade tensorflow-hub  

As you can see in the error log, the tensorflow hub internally trying to assign FLAGS = tf.flags.FLAGS.
In Tensorlow 2.x tf.flags.FLAGS has been moved to tf.compat.flags.Flag which is not addressed in Tensorflow Hub 0.1.1.

Now in the latest Tensorflow Hub(0.8.0) they are using flags like below.

from absl import flags
FLAGS = flags.FLAGS 

Upgrading Tensorflow Hub should resolve your issue.

Upvotes: 2

Related Questions