停止 TensorFlow 打印警告消息
Stop TensorFlow from printing warning message
我正在使用 Kaggle 笔记本,每当我 运行 一个完全引用 TensorFlow 模块的单元格时,它都会打印出关于某种设置的巨大警告,但仍然有效。我查找了如何抑制来自 TensorFlow 的警告,我发现的所有内容都说要执行以下操作:
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" # Or "3", either one should work and I've tried both
我曾尝试在导入 TensorFlow 之前和之后放置它,但无济于事。该消息仍然打印出来。这是我收到的消息:
User settings:
KMP_AFFINITY=granularity=fine,verbose,compact,1,0
KMP_BLOCKTIME=0
KMP_SETTINGS=1
KMP_WARNINGS=0
Effective settings:
KMP_ABORT_DELAY=0
KMP_ADAPTIVE_LOCK_PROPS='1,1024'
KMP_ALIGN_ALLOC=64
KMP_ALL_THREADPRIVATE=128
KMP_ATOMIC_MODE=2
KMP_BLOCKTIME=0
KMP_CPUINFO_FILE: value is not defined
KMP_DETERMINISTIC_REDUCTION=false
KMP_DEVICE_THREAD_LIMIT=2147483647
KMP_DISP_NUM_BUFFERS=7
KMP_DUPLICATE_LIB_OK=false
KMP_ENABLE_TASK_THROTTLING=true
KMP_FORCE_REDUCTION: value is not defined
KMP_FOREIGN_THREADS_THREADPRIVATE=true
KMP_FORKJOIN_BARRIER='2,2'
KMP_FORKJOIN_BARRIER_PATTERN='hyper,hyper'
KMP_GTID_MODE=3
KMP_HANDLE_SIGNALS=false
KMP_HOT_TEAMS_MAX_LEVEL=1
KMP_HOT_TEAMS_MODE=0
KMP_INIT_AT_FORK=true
KMP_LIBRARY=throughput
KMP_LOCK_KIND=queuing
KMP_MALLOC_POOL_INCR=1M
KMP_NUM_LOCKS_IN_BLOCK=1
KMP_PLAIN_BARRIER='2,2'
KMP_PLAIN_BARRIER_PATTERN='hyper,hyper'
KMP_REDUCTION_BARRIER='1,1'
KMP_REDUCTION_BARRIER_PATTERN='hyper,hyper'
KMP_SCHEDULE='static,balanced;guided,iterative'
KMP_SETTINGS=true
KMP_SPIN_BACKOFF_PARAMS='4096,100'
KMP_STACKOFFSET=64
KMP_STACKPAD=0
KMP_STACKSIZE=8M
KMP_STORAGE_MAP=false
KMP_TASKING=2
KMP_TASKLOOP_MIN_TASKS=0
KMP_TASK_STEALING_CONSTRAINT=1
KMP_TEAMS_THREAD_LIMIT=4
KMP_TOPOLOGY_METHOD=all
KMP_USE_YIELD=1
KMP_VERSION=false
KMP_WARNINGS=false
OMP_AFFINITY_FORMAT='OMP: pid %P tid %i thread %n bound to OS proc set {%A}'
OMP_ALLOCATOR=omp_default_mem_alloc
OMP_CANCELLATION=false
OMP_DEFAULT_DEVICE=0
OMP_DISPLAY_AFFINITY=false
OMP_DISPLAY_ENV=false
OMP_DYNAMIC=false
OMP_MAX_ACTIVE_LEVELS=1
OMP_MAX_TASK_PRIORITY=0
OMP_NESTED: deprecated; max-active-levels-var=1
OMP_NUM_THREADS: value is not defined
OMP_PLACES: value is not defined
OMP_PROC_BIND='intel'
OMP_SCHEDULE='static'
OMP_STACKSIZE=8M
OMP_TARGET_OFFLOAD=DEFAULT
OMP_THREAD_LIMIT=2147483647
OMP_WAIT_POLICY=PASSIVE
KMP_AFFINITY='verbose,warnings,respect,granularity=fine,compact,1,0'
有什么方法可以阻止它打印吗?
编辑:重现此消息的代码:
import tensorflow as tf
tf.constant(())
编辑:env
的输出:
{'SHELL': '/bin/bash',
'KMP_WARNINGS': '0',
'DL_ANACONDA_HOME': '/opt/conda',
'KAGGLE_DATA_PROXY_TOKEN': '<hidden>',
'KAGGLE_URL_BASE': 'https://www.kaggle.com',
'KAGGLE_KERNEL_INTEGRATIONS': '',
'CONTAINER_NAME': 'tf2-cpu/2-6',
'PWD': '/kaggle/working',
'TESSERACT_PATH': '/usr/bin/tesseract',
'TENSORFLOW_VERSION': '2.6.0',
'HOME': '/root',
'LANG': 'C.UTF-8',
'KMP_SETTINGS': '1',
'JAX_VERSION': '0.2.19',
'CONTAINER_URL': 'gcr.io/deeplearning-platform-release/tf-cpu.2-6:nightly-2021-11-17',
'ANACONDA_PYTHON_VERSION': '3.7',
'PYTHONPATH': '/kaggle/lib/kagglegym:/kaggle/lib:/kaggle/input/tensorflow-great-barrier-reef',
'KMP_BLOCKTIME': '0',
'KAGGLE_DATA_PROXY_PROJECT': 'kaggle-161607',
'KAGGLE_USER_SECRETS_TOKEN': '<hidden>',
'SHLVL': '1',
'KAGGLE_KERNEL_RUN_TYPE': 'Interactive',
'PROJ_LIB': '/opt/conda/share/proj',
'MPLBACKEND': 'agg',
'LD_LIBRARY_PATH': '/usr/local/cuda/lib64:/usr/local/cuda/lib:/usr/local/lib/x86_64-linux-gnu:/usr/local/nvidia/lib:/usr/local/nvidia/lib64:',
'KMP_AFFINITY': 'granularity=fine,verbose,compact,1,0',
'MKL_THREADING_LAYER': 'GNU',
'LC_ALL': 'C.UTF-8',
'PATH': '/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
'PYTHONUSERBASE': '/root/.local',
'KAGGLE_DATA_PROXY_URL': 'https://dp.kaggle.net',
'_': '/opt/conda/bin/jupyter',
'GIT_PYTHON_REFRESH': 'quiet',
'PYDEVD_USE_FRAME_EVAL': 'NO',
'JPY_PARENT_PID': '9',
'TERM': 'xterm-color',
'CLICOLOR': '1',
'PAGER': 'cat',
'GIT_PAGER': 'cat',
'TF_CPP_MIN_LOG_LEVEL': '2',
'TF2_BEHAVIOR': '1'}
所以我设法通过以下行解决了问题:
os.environ["KMP_SETTINGS"] = "false"
我正在使用 Kaggle 笔记本,每当我 运行 一个完全引用 TensorFlow 模块的单元格时,它都会打印出关于某种设置的巨大警告,但仍然有效。我查找了如何抑制来自 TensorFlow 的警告,我发现的所有内容都说要执行以下操作:
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" # Or "3", either one should work and I've tried both
我曾尝试在导入 TensorFlow 之前和之后放置它,但无济于事。该消息仍然打印出来。这是我收到的消息:
User settings:
KMP_AFFINITY=granularity=fine,verbose,compact,1,0
KMP_BLOCKTIME=0
KMP_SETTINGS=1
KMP_WARNINGS=0
Effective settings:
KMP_ABORT_DELAY=0
KMP_ADAPTIVE_LOCK_PROPS='1,1024'
KMP_ALIGN_ALLOC=64
KMP_ALL_THREADPRIVATE=128
KMP_ATOMIC_MODE=2
KMP_BLOCKTIME=0
KMP_CPUINFO_FILE: value is not defined
KMP_DETERMINISTIC_REDUCTION=false
KMP_DEVICE_THREAD_LIMIT=2147483647
KMP_DISP_NUM_BUFFERS=7
KMP_DUPLICATE_LIB_OK=false
KMP_ENABLE_TASK_THROTTLING=true
KMP_FORCE_REDUCTION: value is not defined
KMP_FOREIGN_THREADS_THREADPRIVATE=true
KMP_FORKJOIN_BARRIER='2,2'
KMP_FORKJOIN_BARRIER_PATTERN='hyper,hyper'
KMP_GTID_MODE=3
KMP_HANDLE_SIGNALS=false
KMP_HOT_TEAMS_MAX_LEVEL=1
KMP_HOT_TEAMS_MODE=0
KMP_INIT_AT_FORK=true
KMP_LIBRARY=throughput
KMP_LOCK_KIND=queuing
KMP_MALLOC_POOL_INCR=1M
KMP_NUM_LOCKS_IN_BLOCK=1
KMP_PLAIN_BARRIER='2,2'
KMP_PLAIN_BARRIER_PATTERN='hyper,hyper'
KMP_REDUCTION_BARRIER='1,1'
KMP_REDUCTION_BARRIER_PATTERN='hyper,hyper'
KMP_SCHEDULE='static,balanced;guided,iterative'
KMP_SETTINGS=true
KMP_SPIN_BACKOFF_PARAMS='4096,100'
KMP_STACKOFFSET=64
KMP_STACKPAD=0
KMP_STACKSIZE=8M
KMP_STORAGE_MAP=false
KMP_TASKING=2
KMP_TASKLOOP_MIN_TASKS=0
KMP_TASK_STEALING_CONSTRAINT=1
KMP_TEAMS_THREAD_LIMIT=4
KMP_TOPOLOGY_METHOD=all
KMP_USE_YIELD=1
KMP_VERSION=false
KMP_WARNINGS=false
OMP_AFFINITY_FORMAT='OMP: pid %P tid %i thread %n bound to OS proc set {%A}'
OMP_ALLOCATOR=omp_default_mem_alloc
OMP_CANCELLATION=false
OMP_DEFAULT_DEVICE=0
OMP_DISPLAY_AFFINITY=false
OMP_DISPLAY_ENV=false
OMP_DYNAMIC=false
OMP_MAX_ACTIVE_LEVELS=1
OMP_MAX_TASK_PRIORITY=0
OMP_NESTED: deprecated; max-active-levels-var=1
OMP_NUM_THREADS: value is not defined
OMP_PLACES: value is not defined
OMP_PROC_BIND='intel'
OMP_SCHEDULE='static'
OMP_STACKSIZE=8M
OMP_TARGET_OFFLOAD=DEFAULT
OMP_THREAD_LIMIT=2147483647
OMP_WAIT_POLICY=PASSIVE
KMP_AFFINITY='verbose,warnings,respect,granularity=fine,compact,1,0'
有什么方法可以阻止它打印吗?
编辑:重现此消息的代码:
import tensorflow as tf
tf.constant(())
编辑:env
的输出:
{'SHELL': '/bin/bash',
'KMP_WARNINGS': '0',
'DL_ANACONDA_HOME': '/opt/conda',
'KAGGLE_DATA_PROXY_TOKEN': '<hidden>',
'KAGGLE_URL_BASE': 'https://www.kaggle.com',
'KAGGLE_KERNEL_INTEGRATIONS': '',
'CONTAINER_NAME': 'tf2-cpu/2-6',
'PWD': '/kaggle/working',
'TESSERACT_PATH': '/usr/bin/tesseract',
'TENSORFLOW_VERSION': '2.6.0',
'HOME': '/root',
'LANG': 'C.UTF-8',
'KMP_SETTINGS': '1',
'JAX_VERSION': '0.2.19',
'CONTAINER_URL': 'gcr.io/deeplearning-platform-release/tf-cpu.2-6:nightly-2021-11-17',
'ANACONDA_PYTHON_VERSION': '3.7',
'PYTHONPATH': '/kaggle/lib/kagglegym:/kaggle/lib:/kaggle/input/tensorflow-great-barrier-reef',
'KMP_BLOCKTIME': '0',
'KAGGLE_DATA_PROXY_PROJECT': 'kaggle-161607',
'KAGGLE_USER_SECRETS_TOKEN': '<hidden>',
'SHLVL': '1',
'KAGGLE_KERNEL_RUN_TYPE': 'Interactive',
'PROJ_LIB': '/opt/conda/share/proj',
'MPLBACKEND': 'agg',
'LD_LIBRARY_PATH': '/usr/local/cuda/lib64:/usr/local/cuda/lib:/usr/local/lib/x86_64-linux-gnu:/usr/local/nvidia/lib:/usr/local/nvidia/lib64:',
'KMP_AFFINITY': 'granularity=fine,verbose,compact,1,0',
'MKL_THREADING_LAYER': 'GNU',
'LC_ALL': 'C.UTF-8',
'PATH': '/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
'PYTHONUSERBASE': '/root/.local',
'KAGGLE_DATA_PROXY_URL': 'https://dp.kaggle.net',
'_': '/opt/conda/bin/jupyter',
'GIT_PYTHON_REFRESH': 'quiet',
'PYDEVD_USE_FRAME_EVAL': 'NO',
'JPY_PARENT_PID': '9',
'TERM': 'xterm-color',
'CLICOLOR': '1',
'PAGER': 'cat',
'GIT_PAGER': 'cat',
'TF_CPP_MIN_LOG_LEVEL': '2',
'TF2_BEHAVIOR': '1'}
所以我设法通过以下行解决了问题:
os.environ["KMP_SETTINGS"] = "false"