1

I was trying to fit my model into history, but my code didn't work. The initial error was

"Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
     [[node sequential/conv2d/Conv2D (defined at <ipython-input-10-fe8518c345fd>:1) ]] [Op:__inference_train_function_675]" 

Then I tried using this code to reduce the memory

from keras.backend.tensorflow_backend import set_session
physical_devices = tf.config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
config = tf.config.experimental.set_memory_growth(physical_devices[0], True)
sess = tf.Session(config=config)
set_session(sess)

Then I got

ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context' (C:\Users\USER\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\eager\context.py)

Please help, I've been stuck in this hell for so long.

Version I am using:

python 3.8

tensorflow-gpu 2.4.1

cuda_11.2.2_461.33_win10

cudnn-11.2-windows-x64-v8.1.1.33

talonmies
  • 70,661
  • 34
  • 192
  • 269
exius
  • 11
  • 1
  • 4
  • First of all there is no concept of `session` in `TF2.x`. Can you try as `physical_devices = tf.config.experimental.list_physical_devices('GPU'); assert len(physical_devices) > 0, "Not enough GPU hardware devices available"; config = tf.config.experimental.set_memory_growth(physical_devices[0], True)` and let us know? –  Apr 07 '21 at 12:20
  • @TFer2 I'm sorry, I tried that and still got the same problem. I ended up with avoiding the entire library import that made the error and working around it with other libraries. Sorry for the late reply. – exius Apr 14 '21 at 04:25
  • [I tried this and it worked for me. ](https://stackoverflow.com/a/67618073/2702034) – lifelonglearner_rohit May 20 '21 at 09:59

1 Answers1

0

You are trying to run Tensorflow 1.x code in Tensorflow 2.x, which is causing this error.

You need to install Tensorflow 1.x in your system along with the compatible python version 3.7 as per this Tested build configurations to run the above code.

You can install Tensorflow 1.x using the code below and restart the runtime(kernel).

!pip install tensorflow==1.15

import tensorflow as tf
print(tf.__version__)

Also, make sure you are importing keras components set_session correctly along with prefix tensorflow.keras.

Fixed code:

from tensorflow.keras.backend import set_session
physical_devices = tf.config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
config = tf.config.experimental.set_memory_growth(physical_devices[0], True)
sess = tf.Session(config=config)
set_session(sess)

Attached a gist for your reference.