'Tensorflow initializing in Python without being imported

Ever since I installed Tensorflow, it keeps initializing every time I run a Python file, even if Tensorflow is not imported in it. I only know that because it always shows this error on Terminal:

W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found 2022-03-31 20:33:35.230201: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

The problem is it takes some time before it starts running the actual file, which can be a pain in the bottom when you want to keep testing and running a file multiple times.

Can anyone help me with this?

Much appreciated!



Solution 1:[1]

A library dynamically searches for the correct CUDA version in tensorflow and, if it doesn't find it, emits the warning (The W in the beginning stands for warnings, errors have an E (or F for fatal errors) and falls back to CPU-only mode. This is also written in the log as an info message right after the warning.

  • If you don't have a CUDA-enabled GPU on your machine, or if you don't care about not having GPU acceleration, no need to worry.

  • If, on the other hand, you installed tensorflow and wanted GPU acceleration, check if your CUDA version is compatible with the tensorflow version from here.

If you just want to suppress warnings, you can do it with the code below:

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

With the help of os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' all the INFO and WARNING messages will not be printed.

0 = all messages are logged (default behavior)
1 = INFO messages are not printed
2 = INFO and WARNING messages are not printed
3 = INFO, WARNING, and ERROR messages are not printed

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tfer3