取消打印Tensorflow中的无用信息,如WARNING:tensorflow:AutoGraph could not transform bound method BatchNorm.call of model.BatchNorm object at 0x0000021764BB9F60 and will run it as-is、加载CUDA信息等
- 1.软件环境
- 2.问题描述
* - 2.1.
CUDA
信息以及CPU
指令集不支持AVX2
- 2.2.
Tensorflow 1.0
和Tensorflow 2.0
之间的API
变更等Warning
- 2.3.
Pyinstaller
打包为exe后额外增加的Warning
- 3.解决方法
* - 3.1.取消打印
CUDA
信息以及CPU
指令集不支持AVX2
– - 3.2.取消打印
Tensorflow 2.0
API变更以及Pyinstaller
打包为exe
后额外增加的Warning
– - 4.总结
TensorFlow其他警告信息如何取消:
Python:设置不显示Using TensorFlow backend及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
1.软件环境
Windows10 教育版64位
Tensorflow-GPU 2.3.0
Keras 2.4.3
CUDA 10.1
Pyinstaller 4.10
2.问题描述
在使用 Tensorflow
时,经常会打印一些无用的信息,主要包括如下:
2.1. CUDA
信息以及 CPU
指令集不支持 AVX2
Tensorflow
在成功加载 CUDA
后,会打印 CUDA
相关的信息,真的是一片红~~:
即:
2022-05-25 18:32:09.641749: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
2022-05-25 18:32:16.164069: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll
2022-05-25 18:32:16.186774: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties:
pciBusID: 0000:73:00.0 name: Quadro RTX 6000 computeCapability: 7.5
coreClock: 1.77GHz coreCount: 72 deviceMemorySize: 24.00GiB deviceMemoryBandwidth: 625.94GiB/s
2022-05-25 18:32:16.187080: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
2022-05-25 18:32:16.190454: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cublas64_10.dll
2022-05-25 18:32:16.193652: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll
2022-05-25 18:32:16.194809: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll
2022-05-25 18:32:16.198553: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusolver64_10.dll
2022-05-25 18:32:16.200484: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusparse64_10.dll
2022-05-25 18:32:16.207734: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudnn64_7.dll
2022-05-25 18:32:16.207897: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 0
2022-05-25 18:32:17.342370: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-05-25 18:32:17.351683: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x28cb2077ca0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2022-05-25 18:32:17.351949: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
2022-05-25 18:32:17.352268: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties:
pciBusID: 0000:73:00.0 name: Quadro RTX 6000 computeCapability: 7.5
coreClock: 1.77GHz coreCount: 72 deviceMemorySize: 24.00GiB deviceMemoryBandwidth: 625.94GiB/s
2022-05-25 18:32:17.352595: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
2022-05-25 18:32:17.352746: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cublas64_10.dll
2022-05-25 18:32:17.352907: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll
2022-05-25 18:32:17.353069: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll
2022-05-25 18:32:17.353242: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusolver64_10.dll
2022-05-25 18:32:17.353354: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusparse64_10.dll
2022-05-25 18:32:17.353448: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudnn64_7.dll
2022-05-25 18:32:17.353661: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 0
2022-05-25 18:32:17.881639: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2022-05-25 18:32:17.881807: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263] 0
2022-05-25 18:32:17.881871: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1276] 0: N
2022-05-25 18:32:17.882136: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1402] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 21845 MB memory) -> physical GPU (device: 0, name: Quadro RTX 6000, pci bus id: 0000:73:00.0, compute capability: 7.5)
2022-05-25 18:32:17.885199: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x28ce667ab30 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2022-05-25 18:32:17.885412: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Quadro RTX 6000, Compute Capability 7.5
2.2. Tensorflow 1.0
和 Tensorflow 2.0
之间的 API
变更等 Warning
由于 Tensorflow 1.0
和 Tensorflow 2.0
之间的API变化较大,会打印许多 Warning
信息:
即:
WARNING:tensorflow:From C:\Users\Jayce\Anaconda3\envs\map_scale_gui\lib\site-packages\tensorflow\python\util\deprecation.py:574: calling map_fn_v2 (from tensorflow.python.ops.map_fn) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Use fn_output_signature instead
WARNING:tensorflow:From C:\Users\Jayce\Anaconda3\envs\map_scale_gui\lib\site-packages\tensorflow\python\keras\engine\training_v1.py:2070: Model.state_updates (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.
Instructions for updating:
This property should not be used in TensorFlow 2.0, as updates are applied automatically.
2.3. Pyinstaller
打包为exe后额外增加的 Warning
在使用 Pyinstaller
等软件打包之后,程序还会额外打印一些新的警告:
即:
WARNING:tensorflow:AutoGraph could not transform <bound method BatchNorm.call of <model.BatchNorm object at 0x0000021764BB9F60>> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10
) and attach the full output.
Cause: Unable to locate the source code of <bound method BatchNorm.call of <model.BatchNorm object at 0x0000021764BB9F60>>. Note that functions defined in certain environments, like the interactive Python shell do not expose their source code. If that is the case, you should to define them in a .py source file. If you are certain the code is graph-compatible, wrap the call using @tf.autograph.do_not_convert. Original error: could not get source code
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
WARNING:tensorflow:AutoGraph could not transform <bound method ProposalLayer.call of <model.ProposalLayer object at 0x0000021767932208>> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10
) and attach the full output.
Cause: Unable to locate the source code of <bound method ProposalLayer.call of <model.ProposalLayer object at 0x0000021767932208>>. Note that functions defined in certain environments, like the interactive Python shell do not expose their source code. If that is the case, you should to define them in a .py source file. If you are certain the code is graph-compatible, wrap the call using @tf.autograph.do_not_convert. Original error: could not get source code
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
WARNING:tensorflow:AutoGraph could not transform <bound method PyramidROIAlign.call of <model.PyramidROIAlign object at 0x00000217679A5860>> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10
) and attach the full output.
Cause: Unable to locate the source code of <bound method PyramidROIAlign.call of <model.PyramidROIAlign object at 0x00000217679A5860>>. Note that functions defined in certain environments, like the interactive Python shell do not expose their source code. If that is the case, you should to define them in a .py source file. If you are certain the code is graph-compatible, wrap the call using @tf.autograph.do_not_convert. Original error: could not get source code
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
WARNING:tensorflow:AutoGraph could not transform <bound method DetectionLayer.call of <model.DetectionLayer object at 0x0000021767AB0320>> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10
) and attach the full output.
Cause: Unable to locate the source code of <bound method DetectionLayer.call of <model.DetectionLayer object at 0x0000021767AB0320>>. Note that functions defined in certain environments, like the interactive Python shell do not expose their source code. If that is the case, you should to define them in a .py source file. If you are certain the code is graph-compatible, wrap the call using @tf.autograph.do_not_convert. Original error: could not get source code
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
WARNING:tensorflow:From tensorflow\python\util\deprecation.py:574: calling map_fn_v2 (from tensorflow.python.ops.map_fn) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Use fn_output_signature instead
WARNING:tensorflow:AutoGraph could not transform <function refine_detections_graph.<locals>.nms_keep_map at 0x0000021767AD99D8> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10
) and attach the full output.
Cause: Unable to locate the source code of <function refine_detections_graph.<locals>.nms_keep_map at 0x0000021767AD99D8>. Note that functions defined in certain environments, like the interactive Python shell do not expose their source code. If that is the case, you should to define them in a .py source file. If you are certain the code is graph-compatible, wrap the call using @tf.autograph.do_not_convert. Original error: could not get source code
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
虽然上述信息不会影响我们程序的正常执行,但它有以下缺点:
[En]
Although the above information will not affect the normal execution of our program, it has the following shortcomings:
- 如果你是多进程运行预测的话,上述信息会打印很多遍,这个时候你如果要捕获
CMD
的输出,就会变得非常繁琐; - 如果您的程序本身有需要打印的关键信息,上述输出很容易掩盖您需要查看的关键信息。
[En]
if your program itself has key information that needs to be printed, the above output can easily obscure the key information you need to view.*
- 无用输出过多可能影响程序性能
[En]
too much useless output may affect program performance*
对我们来说,其实上面的信息是 无用
的。那么,有没有办法可以让我们将上述 Tensorflow
中的无用信息屏蔽掉呢?
3.解决方法
3.1.取消打印 CUDA
信息以及 CPU
指令集不支持 AVX2
TensorFlow
中的 Log
共有 DEBUG
、 INFO
、 WARNING
、 ERROR
、 FATAL
5种级别,且通过环境变量 TF_CPP_MIN_LOG_LEVEL
对日志级别进行设置, TF_CPP_MIN_LOG_LEVEL
不同值的含义如下:
LevelLevel for HumansLevel Description0DEBUGall messages are logged (Default)1INFOINFO messages are not printed2WARNINGINFO and WARNING messages are not printed3ERRORINFO, WARNING, and ERROR messages are not printed
因此我们可以通过设置 TF_CPP_MIN_LOG_LEVEL
的值,屏蔽该级别以及更低级别的日志,如:设置为 3
,表示屏蔽 INFO
, WARNING
, ERROR
级别的日志。
3.1.1.具体操作
直接在你的主函数(即你运行的 .py
文件)开头添加如下代码:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
记住一定是 代码开头
,如果你把上面代码放在 import tensorflow as tf
后面,这个时候 tensorflow
都 import
完了才会运行我们的语句,自然设置就不会有效果了。
3.1.2.效果预览
这个时候,我们已经成功取消打印 CUDA
信息以及 CPU
指令集不支持 AVX2
等无用信息,之前界面一大堆红色的警告信息已经消失不见,只剩下 API
变更的警告:
; 3.2.取消打印 Tensorflow 2.0
API变更以及 Pyinstaller
打包为 exe
后额外增加的 Warning
Tensorflow
为了兼容 1.x
和 2.x
的 APIs
,专门提供了 tf.compat
模块:
因此,我们只需要在程序中进行兼容性设置。
[En]
Therefore, we only need to make compatibility settings in the program.
3.2.1.具体操作
直接在 3.1
添加的代码后面继续添加如下代码:
import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
3.2.2.效果预览
这个时候, 3.1
剩下的 API
变更的警告也没有了,控制台只打印我们自己定义的提示信息:
运行
Pyinstaller
打包后的程序也没有多余的警告打印:; 4.总结
如果想完全消除 Tensorflow
本身打印的警告,需要结合 3.1
和 3.2
,即直接在你的主函数(即你运行的 .py
文件)开头添加代码:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
如果只想屏蔽一部分,如只想取消打印 CUDA
信息以及 CPU
指令集不支持 AVX2
,则按 3.1
操作即可;而如果只想取消打印 Tensorflow 2.0
的 API
变更以及 Pyinstaller
打包为 exe
后额外增加的 Warning
,则按 3.2
操作即可。但一定要注意:是在你即将运行的 .py
文件的 开头
添加相应代码。
都看到这里了,还不赶紧 点赞
, 评论
, 收藏
走一波?
Original: https://blog.csdn.net/qq_15969343/article/details/124971292
Author: 任博今天就要毕业
Title: 取消打印Tensorflow中的无用信息,如tensorflow:AutoGraph could not transform <*> and will run it as-is、加载CUDA信息等
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/514076/
转载文章受原作者版权保护。转载请注明原作者出处!