TensorFlow.js:如何避免使用“您的CPU支持指令... AVX AVX2”?

时间:2018-09-09 09:40:22

标签: javascript tensorflow

环境:

  • Windows 10 x64,
  • Node.js v10,
  • @ tensorflow / tfjs-node v0.1.15

我正在尝试在Node.js上使用tensorflow.js。

我安装了tfjs-node,并成功自动构建(node-gyp),但是运行时出现以下错误:

tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2

可以在以下位置找到类似的Python版本问题:

Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2

当前,我不在乎性能,因此我只想禁用警告,而不启用AVX / FMA。在JavaScript中,我该怎么办?

2 个答案:

答案 0 :(得分:3)

在运行之前设置环境变量。

Windows:

$ set TF_CPP_MIN_LOG_LEVEL=2

Linux / MacOS:

$ export TF_CPP_MIN_LOG_LEVEL=2

答案 1 :(得分:1)

首先使用“ conda list”命令列出您拥有的软件包(tensorflow和相关软件包)。

>> conda list
This command output with below tensorflow version
tblib                     1.3.2            py36h30f5020_0
tensorboard               1.13.1                    <pip>
tensorflow                1.13.1                    <pip>
tensorflow-estimator      1.13.0                    <pip>

注意:我已经省略了一些不必要的软件包清单

Installing collected packages: tensorflow Successfully installed tensorflow-1.13.1
You are using pip version 18.0, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

(base) C:\Users\shashi>python
Python 3.6.6 |Anaconda custom (64-bit)| (default, Jun 28 2018, 11:27:44) [MSC v.1900 
64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello Tensorflow')
>>> sess = tf.Session()
I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions 
that this TensorFlow binary was not compiled to use: AVX2
>>> import os
>>> import os
>>> os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
>>> hello = tf.constant('Hello Tensorflow')
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello Tensorflow'

设置“ os.environ ['TF_CPP_MIN_LOG_LEVEL'] = 2的值后,代码可以正常工作。 如果Jupyter也抛出错误,请关闭打开的Jupyter笔记本,然后再次重新打开它们。一切都会很好。