Module tensorflow has no attribute contrib

Module tensorflow has no attribute contrib

tf.contrib has moved out of TF starting TF 2.0 alpha.
Take a look at these tf 2.0 release notes
You can upgrade your TF 1.x code to TF 2.x using the tf_upgrade_v2 script

This issue might be helpful for you, it explains how to achieve TPUStrategy, a popular functionality of tf.contrib in TF<2.0.

So, in TF 1.X you could do the following:

resolver = tf.contrib.cluster_resolver.TPUClusterResolver(grpc:// + os.environ[COLAB_TPU_ADDR])
strategy = tf.contrib.distribute.TPUStrategy(resolver)

And in TF>2.0, where tf.contrib is deprecated, you achieve the same by:

tf.config.experimental_connect_to_host(grpc:// + os.environ[COLAB_TPU_ADDR])
resolver = tf.distribute.cluster_resolver.TPUClusterResolver(grpc:// + os.environ[COLAB_TPU_ADDR])
strategy = tf.distribute.experimental.TPUStrategy(resolver) 

Module tensorflow has no attribute contrib

I used google colab to run my models and everything was perfect untill i used inline tesorboard. With tensorboard inline, I had the same issue of Module tensorflow has no attribute contrib.

It was able to run training when rebuild and reinstall the model using folder) after initialising tensorboard.

Leave a Reply

Your email address will not be published. Required fields are marked *