If you have a problem, that python program hangs for about a minute during running of TensorFlow program on GPU, probably this solution is for you.
1. The problem
Let’s suppose that you have a hello-world program like below.
from __future__ import print_function import tensorflow as tf a = tf.constant("Hello World") session = tf.Session() output = session.run(a) print('Output:' + str(output))
While you run it, you can notice that program hangs for about 60 seconds displaying the following log:
D:\__BC\workspace\tensorflow-tutorial\01-hello-world\venv1\Scripts\python.exe D:/__BC/workspace/tensorflow-tutorial/01-hello-world/hello-world.py 2019-05-03 20:35:28.199069: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 2019-05-03 20:35:28.227552: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library nvcuda.dll 2019-05-03 20:35:28.925366: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1467] Found device 0 with properties: name: GeForce GTX 960M major: 5 minor: 0 memoryClockRate(GHz): 1.176 pciBusID: 0000:01:00.0 totalMemory: 4.00GiB freeMemory: 3.34GiB 2019-05-03 20:35:28.925960: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1546] Adding visible gpu devices: 0
2. The solution
Add below lines at the beginning of your python code:
import os os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
In my previous example it may looks like below:
In some cases it is required to restart IDE.
from __future__ import print_function import tensorflow as tf import os os.environ['TF_CPP_MIN_LOG_LEVEL']='2' a = tf.constant("Hello World") session = tf.Session() output = session.run(a) print('Output:' + str(output))
At the end… May I ask you for something?
If I helped you solve your problem, please share this post. Thanks to this, I will have the opportunity to reach a wider group of readers. Thank You