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

I import tensorflow (version 1.13.1) and need ConfigProto:

import tensorflow as tf

config = tf.ConfigProto(intra_op_parallelism_threads=8,
    inter_op_parallelism_threads=8,
    allow_soft_placement=True,device_count = {'CPU' : 1, 'GPU' : 1})

I get this error:

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

How do I resolve this?


ConfigProto disappeared in tf 2.0, so an elegant solution is:

import tensorflow as tf

and then replace:

tf.ConfigProto by tf.compat.v1.ConfigProto

In fact, the compatibility built in 2.0 to get tf 1.XX: tf.compat.v1 is really helpful.

Useful link: Migrate your tensorflow 1. code to tensorflow 2.: https://www.tensorflow.org/guide/migrate


I had similar issues, when upgraded to Python 3.7 & Tensorflow 2.0.0 (from Tensorflow 1.2.0)

This is an easy one and works!

If you don't want to touch your code, just add these 2 lines in the main.py file w/ Tensorflow code:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

And that's it!!
NOW Everything should run seamlessly :)


Just an addition to others looking for an answer for Tensorflow v2

As the others have mentioned, you can use the back-compatability to v1. But Tensorflow v2 does actually come with its own implementation of this. It is just a hidden experimental feature.

This is how to allow the GPU to grow in memory in Tensorflow v2:

# Allow memory growth for the GPU
physical_devices = tf.config.experimental.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0], True)

More info found @Tensorflow


If using tensorflow version > 2.0:

config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth=True
sess = tf.compat.v1.Session(config=config)