如何消除Tensorflow的警告?其他解决方案不起作用

如何消除Tensorflow的警告?其他解决方案不起作用,tensorflow,tensorflow-gpu,Tensorflow,Tensorflow Gpu,例如,如果我运行这段代码: import tensorflow as tf a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a') b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b') c = tf.matmul(a, b) # Creates a session with log_device_placement se

例如,如果我运行这段代码:

import tensorflow as tf
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))
然后我会得到这个:

    2017-06-24 10:20:57.441289: W c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.
2017-06-24 10:20:57.442069: W c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-24 10:20:57.443010: W c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-24 10:20:57.444615: W c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-24 10:20:57.445662: W c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-24 10:20:57.446273: W c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-06-24 10:20:57.447475: W c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-24 10:20:57.448190: W c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
2017-06-24 10:21:01.548276: I c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:940] Found device 0 with properties: 
name: GeForce GTX 1060
major: 6 minor: 1 memoryClockRate (GHz) 1.6705
pciBusID 0000:01:00.0
Total memory: 6.00GiB
Free memory: 5.01GiB
2017-06-24 10:21:01.549636: I c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:961] DMA: 0 
2017-06-24 10:21:01.550040: I c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:971] 0:   Y 
2017-06-24 10:21:01.550479: I c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1060, pci bus id: 0000:01:00.0)
Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1060, pci bus id: 0000:01:00.0
2017-06-24 10:21:01.910806: I c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\common_runtime\direct_session.cc:265] Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1060, pci bus id: 0000:01:00.0

MatMul: (MatMul): /job:localhost/replica:0/task:0/gpu:0
b: (Const): /job:localhost/replica:0/task:0/gpu:0
a: (Const): /job:localhost/replica:0/task:0/gpu:0
2017-06-24 10:21:01.918147: I c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\common_runtime\simple_placer.cc:847] MatMul: (MatMul)/job:localhost/replica:0/task:0/gpu:0
2017-06-24 10:21:01.918794: I c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\common_runtime\simple_placer.cc:847] b: (Const)/job:localhost/replica:0/task:0/gpu:0
2017-06-24 10:21:01.919403: I c:\tf_jenkins\home\workspace\release-win\m\windows-gpu\py\35\tensorflow\core\common_runtime\simple_placer.cc:847] a: (Const)/job:localhost/replica:0/task:0/gpu:0
[[ 22.  28.]
 [ 49.  64.]]
警告总是出现,而且非常烦人。我尝试过使用其他解决方案,例如:

import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import tensorflow as tf
但它还是给了我同样的警告。
两件事,我怎样才能摆脱警告?tensorflow是否仅使用GPU?

存在由建筑参数引起的警告。使用参数
bazel build-c opt--copt=-mavx--copt=-mavx2--copt=-mfma--copt=-msse--copt=-msse2--copt=-msse3--copt=-msse4.1--copt=-msse4.2重新编译tensorflow

--copt=-mfpmath=both--config=cuda-k//tensorflow/tools/pip_包:build_pip_包将解决由建筑参数引起的警告问题。使用参数
bazel build-c opt--copt=-mavx--copt=-mavx2--copt=-mfma--copt=-msse--copt=-msse2--copt=-msse3--copt=-msse4.1--copt=-msse4.2重新编译tensorflow

--copt=-mfpmath=both--config=cuda-k//tensorflow/tools/pip_package:build_pip_package
将解决此问题

您将获得此信息转储,因为您将显式启动
会话
,并带有显示它们的指令:

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
log\u device\u placement=True
位专门用于演示在哪些设备上执行哪些操作(例如,演示GPU确实正确使用等)

如果您不想看到此信息,只需启动会话而不使用以下选项:

sess = tf.Session()
但是,使用此位仍然有帮助:

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

因为TF可能会向您显示其他您可能觉得烦人/不必要的警告,所以我建议保留这一行(但根据我的经验,这对Windows没有任何影响,只对Mac和Linux有影响)

您将获得此信息转储,因为您正显式地启动
会话,并按照指示显示它们:

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
log\u device\u placement=True
位专门用于演示在哪些设备上执行哪些操作(例如,演示GPU确实正确使用等)

如果您不想看到此信息,只需启动会话而不使用以下选项:

sess = tf.Session()
但是,使用此位仍然有帮助:

os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
因为TF可能会向您显示其他您可能觉得烦人/不必要的警告,所以我建议保留这一行(但根据我的经验,这对Windows没有任何影响,只对Mac和Linux有影响)

可能重复的