禁止tensorflow提示warning

本文介绍如何在Python和Linux环境中调整TensorFlow的日志级别,以屏蔽警告信息,包括临时和永久设置方法。

TensorFlow的日志级别分为以下三种:

TF_CPP_MIN_LOG_LEVEL = 1         //默认设置,为显示所有信息                
TF_CPP_MIN_LOG_LEVEL = 2         //只显示error和warining信息                
TF_CPP_MIN_LOG_LEVEL = 3         //只显示error信息
所以,当TensorFlow出现警告信息,又不想让警告信息显示时,可进行如下设置:

方法一
python环境下通过在python文件中添加如下两行代码,设置TensorFlow日志输出级别。
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"

方法二
在linux环境下,我们可以通过linux命令,屏蔽掉TensorFlow的warning:
1、暂时屏蔽warning:
在linux终端中输入命令:export TF_CPP_MIN_LOG_LEVEL=2,当该终端关闭,既失效;
2、永久屏蔽warning:
修改~/.bashrc文件,

gedit ~/.bashrc

在该文件中加入:
export TF_CPP_MIN_LOG_LEVEL=2
但是修改后需要重启系统或者使用source ~/.bashrc命令,使修改后的文件生效。

D:\anaconda3\envs\tf_legacy\lib\site-packages\tensorflow\python\framework\dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint8 = np.dtype([("qint8", np.int8, 1)]) D:\anaconda3\envs\tf_legacy\lib\site-packages\tensorflow\python\framework\dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint8 = np.dtype([("quint8", np.uint8, 1)]) D:\anaconda3\envs\tf_legacy\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint16 = np.dtype([("qint16", np.int16, 1)]) D:\anaconda3\envs\tf_legacy\lib\site-packages\tensorflow\python\framework\dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_quint16 = np.dtype([("quint16", np.uint16, 1)]) D:\anaconda3\envs\tf_legacy\lib\site-packages\tensorflow\python\framework\dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint32 = np.dtype([("qint32", np.int32, 1)]) D:\anaconda3\envs\tf_legacy\lib\site-packages\tensorflow\python\framework\dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. np_resource = np.dtype([("resource", np.ubyte, 1)]) usage: freeze_graph.py [-h] -bert_model_dir BERT_MODEL_DIR -model_dir MODEL_DIR [-model_pb_dir MODEL_PB_DIR] [-max_seq_len MAX_SEQ_LEN] [-n
03-27
W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found 2025-08-16 17:23:58.233691: 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. C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\python\framework\dtypes.py:585: FutureWarning: In the future `np.object` will be defined as the corresponding NumPy scalar. np.object, Traceback (most recent call last): File "e:\神经网络\test1.py", line 3, in <module> from tensorflow import keras File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\__init__.py", line 41, in <module> from tensorflow.python.tools import module_util as _module_util File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\python\__init__.py", line 46, in <module> from tensorflow.python import data File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\python\data\__init__.py", line 25, in <module> from tensorflow.python.data import experimental File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\python\data\experimental\__init__.py", line 97, in <module> from tensorflow.python.data.experimental import service File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\python\data\experimental\service\__init__.py", line 353, in <module> from tensorflow.python.data.experimental.ops.data_service_ops import distribute File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\python\data\experimental\ops\data_service_ops.py", line 26, in <module> from tensorflow.python.data.experimental.ops import compression_ops File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\python\data\experimental\ops\compression_ops.py", line 20, in <module> from tensorflow.python.data.util import structure File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\python\data\util\structure.py", line 26, in <module> from tensorflow.python.data.util import nest File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\python\data\util\nest.py", line 40, in <module> from tensorflow.python.framework import sparse_tensor as _sparse_tensor File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\python\framework\sparse_tensor.py", line 28, in <module> from tensorflow.python.framework import constant_op File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\python\framework\constant_op.py", line 29, in <module> from tensorflow.python.eager import execute File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\python\eager\execute.py", line 27, in <module> from tensorflow.python.framework import dtypes File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\tensorflow\python\framework\dtypes.py", line 585, in <module> np.object, File "C:\Users\Administrator\.conda\envs\env1\lib\site-packages\numpy\__init__.py", line 324, in __getattr__ raise AttributeError(__former_attrs__[attr]) AttributeError: module 'numpy' has no attribute 'object'. `np.object` was a deprecated alias for the builtin `object`. To avoid this error in existing code, use `object` by itself. Doing this will not modify any behavior and is safe. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
最新发布
08-17
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值