【tensorflow入门】1、简单的tensorflow小程序+警告 this TensorFlow binary was not compiled to use

这篇博客介绍了如何入门TensorFlow,通过Python代码演示了矩阵乘法操作,并针对出现的'Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2'警告提供了两种解决方案:设置环境变量忽略警告或重新编译TensorFlow源码以兼容AVX。

1、用命令行进入tensorflow的python编程位置

C:\Users\aDreamer>activate tensorflow

(tensorflow) C:\Users\aDreamer>python
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

 

2、输入代码
>>> import tensorflow as tf         #加载tensorflow(导入tensorflow包)
>>> m1=tf.constant([[3,3]])         #定义矩阵常量m1、m2
>>> m2=tf.constant([[2],[3]])     
>>> product=tf.matmul(m1,m2) #创建矩阵乘法op,m1、m2相乘
>>> print(product)                      #打印op
Tensor("MatMul:0", shape=(1, 1), dtype=int32)
>>> sess=tf.Session()               #创建会话
2019-05-27 08:41:23.500628: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
>>> result=sess.run(product)   #在会话中执行product(执行矩阵乘法op)
>>> print(result)                        #打印结果
[[15]]

3、几点说明

1、[[3,3]] x [[2],[3]]=3*2+3*3=15

2、关于警告Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

大概意思是:你的CPU支持AVX扩展,但是你安装的TensorFlow版本无法编译使用。

解决:
<1>. 如果是初学者 或者 没有太大计算速度的需求,在开头加上这两行忽略这个提示即可
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
说明:

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

<2>. 如果需要对CPU进行优化,可以访问下面的github,重新编译tensorflow源码以兼容AVX
https://github.com/lakshayg/tensorflow-build

详情可参考此篇文章:
https://blog.csdn.net/hq86937375/article/details/79696023

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值