keras 抑制tensorflow-metal初始化消息

4bbkushb  于 2023-05-29  发布在  其他
关注(0)|答案(1)|浏览(155)

我有一台macbook pro m1 max,通过tensowflow-apple-download安装了tensorflow。
每次运行使用keras或tensorflow的脚本时,我都会得到以下日志:

>>>  python script.py
Metal device set to: Apple M1 Max

systemMemory: 32.00 GB
maxCacheSize: 10.67 GB

2022-09-06 02:35:38.603010: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2022-09-06 02:35:38.603133: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)
2022-09-06 02:35:38.659578: W tensorflow/core/platform/profile_utils/cpu_utils.cc:128] Failed to get CPU frequency: 0 Hz
2022-09-06 02:35:38.684142: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:113] Plugin optimizer for device_type GPU is enabled.

大多数日志都是不相关的,我能够通过以下方式抑制一些日志:

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

但是,我无法禁用这些日志记录信息:

>>>  python script.py
Metal device set to: Apple M1 Max

systemMemory: 32.00 GB
maxCacheSize: 10.67 GB

有没有办法让keras和tensorflow-metal静音?我不想要这些木头。
我已经尝试过了,但没有成功:

import tensorflow as tf
tf.get_logger().setLevel('ERROR')
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
tf.autograph.set_verbosity(2)

import logging
logging.getLogger('tensorflow').setLevel(logging.ERROR)

注意:卸载tensorflow-metal似乎会抑制日志信息,但解决方案并不是最佳的,因为tensorflow将在CPU而不是GPU上运行。

>>> pip uninstall tensorflow-metal

我认为现在出现的日志记录是由于调用keras Sequential()

from keras.models import Sequential

model = Sequential()
tv6aics1

tv6aics11#

我可以使用下面的代码抑制这些警告(W)和信息(I)消息:

import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

import tensorflow as tf

请在导入TensorFlow之前将这些代码放在整个代码的第一行,然后重试。

不使用环境变量(TF_CPP_MIN_LOG_LEVEL):

使用环境变量(TF_CPP_MIN_LOG_LEVEL='2')后:

**注意:**如果将环境变量设置为3,则代码执行过程中不会记录所有消息(1 - informational(I), 2 - warnings(W) and 3- errors(E))

建议您在系统中使用最新的python和TensorFlow版本。

相关问题