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

前端 未结 5 1824
庸人自扰
庸人自扰 2021-01-01 10:16

I\'m working in Pytorch. I can import tensorflow (version 1.13.1) and need ConfigProto:

import tensorflow as tf
config = tf.ConfigProto(intra_op_parallelism         


        
相关标签:
5条回答
  • 2021-01-01 10:27

    Info:

    RTX 2080
    ubuntu 16.04
    cuda 10.0
    cuDNN v7.4.1.5
    Python V 3.5
    

    pip list:

    tensorflow (1.13.1)
    tensorflow-gpu (1.13.1)
    tf-nightly-gpu (1.14.1.dev20190509)
    

    Code:

    import tensorflow as tf
    from tensorflow import keras
    
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    sess = tf.Session(config=config)
    

    output:

    Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7439 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2080, pci bus id: 0000:02:00.0, compute capability: 7.5)

    That works for me !

    0 讨论(0)
  • 2021-01-01 10:28

    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

    0 讨论(0)
  • 2021-01-01 10:35

    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 :)

    0 讨论(0)
  • 2021-01-01 10:36

    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

    0 讨论(0)
  • 2021-01-01 10:45

    I was with a similar error, but i had tensorflow 1.14, ubuntu 18.04 and GTX 1050ti. So a installed properly conda (lastest version - 5.1) even with this the error persisted, so a upgraded tensorflow/tensorflow-gpu to -version tensorflow==2.0.0-beta0 and worked for me.

    0 讨论(0)
提交回复
热议问题