CPU版本运行TensorFlow添加os.environ[‘TF_CPP_MIN_LOG_LEVEL‘]无效

报错

运行TensorFlow时,每次都会一堆爆红,虽然不影响,但是看那种很不舒服
W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library ‘cudart64_110.dll’; dlerror: cudart64_110.dll not found
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.
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-UU5OMQ5
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-UU5OMQ5
I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
CPU版本运行TensorFlow添加os.environ[‘TF_CPP_MIN_LOG_LEVEL‘]无效_第1张图片

解决办法

由于使用的是CPU版本,用不到GPU的文件,搜到很多最直接的解决办法是添加以下语句忽略这些信息:

#加入忽略
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = '2'

注意:第一次添加后还是报错,最终发现是添加的顺序不对,以上语句一定要放在import TensorFlow之前。

CPU版本运行TensorFlow添加os.environ[‘TF_CPP_MIN_LOG_LEVEL‘]无效_第2张图片

解释

os.environ["TF_CPP_MIN_LOG_LEVEL"] = '1' # 默认,显示所有信息 
os.environ["TF_CPP_MIN_LOG_LEVEL"] = '2' # 只显示 warning 和 Error
os.environ["TF_CPP_MIN_LOG_LEVEL"] = '3' # 只显示 Error

你可能感兴趣的:(bug笔记,tensorflow,python)