环境(ubuntu18.04,python==3.6.5,GCC==7.3.0, tensorflow==1.12.0

tensorflow安装(此处以tensorflow1.12.0为例,非GPU版,如需要安装GPU版请参照tensorflow官方文档):
pip3 install tensorflow==1.12 -i https://mirrors.aliyun.com/pypi/simple

问题:安装完进行测试,出现提示信息如下:
I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
遇到了这个问题,意思是你的 CPU 支持AVX2 FMA(加速CPU计算),但安装的 TensorFlow 版本不支持

解决办法:

一、

如果是初学者 或者 没有太大计算速度的需求,在开头加上这两行忽略这个提示即可

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

PS:

os.environ["TF_CPP_MIN_LOG_LEVEL"] = '1' # 默认,显示所有信息 
os.environ["TF_CPP_MIN_LOG_LEVEL"] = '2' # 只显示 warning 和 Error 
os.environ["TF_CPP_MIN_LOG_LEVEL"] = '3' # 只显示 Error

原文链接:https://blog.csdn.net/zhaohaibo_/article/details/80573676

二、

优化CPU,参照https://github.com/lakshayg/tensorflow-build重新编译tensorflow源码以兼容AVX

苑先森
找到匹配的tensoflow版本,ubuntu版本 以及对应的python版本,选择下载。
然后进行安装:
pip3 install --ignore-installed --upgrade /path/to/binary.whl
其中/path/to/binary.whl指你存放安装文件的路径

由于之前装了numpy1.14.2版本,在进行上面安装后,又自动安装了numpy1.17.2版本,导致测试报错:
ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in ['/home/my-pc/.virtualenvs/ai/lib/python3.6/site-packages/numpy']. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version.

执行pip3 uninstall numpy进行卸载,需要执行两次卸载

卸载后重新安装numpy1.17.2,进行测试,报错如下:

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'.

意思是不同的numpy版本 定义不一样 。那就尝试 降级喽
执行pip3 install numpy==1.16.0

最后进行测试,成功!NICE!
简单测试方法如下:

1.在终端输入命令:python3

2.进入python命令下,测试tensorflow:

import tensorflow as tf

sess = tf.Session()

hello=tf.constant('Hello,World!')

print(sess.run(hello))

3.回车,若在终端下显示 Hello,World! 则表示安装tensorflow成功。

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐