Disable TensorFlow 2 Debugging Information

Disable TensorFlow 2 Debugging Information

By default, TensorFlow 2 prints debugging information in the terminal. It can be useful if we want to know which CUDA libraries was loaded, GPU compute capability, selected device to run computations and other information.

2020-10-20 05:15:23.768388: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
2020-10-20 05:15:25.763107: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll
2020-10-20 05:15:27.319262: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1402] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 2989 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050, pci bus id: 0000:01:00.0, compute capability: 6.1)
............

We can disable debugging information by using TF_CPP_MIN_LOG_LEVEL environment variable. It can be set before importing TensorFlow.

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1'
import tensorflow as tf

Or manually set this environment variable before running Python script.

SET TF_CPP_MIN_LOG_LEVEL=1
python main.py

TF_CPP_MIN_LOG_LEVEL environment variable supports the following values:

LevelNameDescription
0DEBUGAll messages are logged (default).
1INFOINFO messages are not logged.
2WARNINGINFO and WARNING messages are not logged.
3ERRORINFO, WARNING, and ERROR messages are not logged.

Leave a Comment

Cancel reply

Your email address will not be published.