1、Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2问题
错误提醒:
2019-03-25 16:33:29.066658: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
第一个问题Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
可以参考:
https://blog.csdn.net/hq86937375/article/details/79696023
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
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
2、版本警告问题
警告提醒:
WARNING:tensorflow:From C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\ops\resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
意思是下一个版本TensorFlow将会将此方法删除:
因此,该方法colocate_with是一个上下文管理器,用于确保您要创建的操作或张量将放置在引用操作所在的同一设备上。但是,您的警告说它将被弃用,并且从现在开始将自动处理。从tensorflow的下一个版本开始,此方法将被删除,因此您必须立即更新代码(将在当前运行)或更晚(当您将tensorflow的版本更新到下一个时,此代码将不再可运行因为该方法将被删除)
解决方法
先进行版本卸载在重新安装指定版本的tensorflow我的python是3.6.8:
查找版本对应地址:
https://www.tensorflow.org/install/source_windows#cpu
pip uninstall tensorflow
pip install tensorflow==1.11.0
问题解决结果中没有了警告:
3、ImportError: cannot import name ‘ops’
错误原内容:
Using TensorFlow backend.
Traceback (most recent call last):
File "D:/zjf_workspace/自己测试用的/005imageai模块/imageai_study/demo_02_photo_search/demo-1.py", line 1, in <module>
from imageai.Detection import ObjectDetection
File "D:\tools\Python3.6\lib\site-packages\imageai\Detection\__init__.py", line 3, in <module>
from imageai.Detection.keras_retinanet.models.resnet import resnet50_retinanet
File "D:\tools\Python3.6\lib\site-packages\imageai\Detection\keras_retinanet\models\resnet.py", line 19, in <module>
import keras
File "D:\tools\Python3.6\lib\site-packages\keras\__init__.py", line 3, in <module>
from . import utils
File "D:\tools\Python3.6\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
from . import conv_utils
File "D:\tools\Python3.6\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
from .. import backend as K
File "D:\tools\Python3.6\lib\site-packages\keras\backend\__init__.py", line 89, in <module>
from .tensorflow_backend import *
File "D:\tools\Python3.6\lib\site-packages\keras\backend\tensorflow_backend.py", line 6, in <module>
from tensorflow.python.framework import ops as tf_ops
ImportError: cannot import name 'ops'
问题我也是找了好久,定位到最终问题是导入下面这个模块的问题,
from tensorflow.python.framework import ops as tf_ops
最后还是通过Google搜索到,最终解决。意思好像就是tensorflow和keras俩个模块不支持当前的python版本。
我最终找到解决参考连接(好像需要翻墙):https://stackoverflow.com/questions/51076277/cannot-import-name-ops-python
解决方法:
pip install tensorflow --upgrade
pip install keras --upgrade
4、TensorFlow模块导入出现ImportError: DLL load failed: 找不到指定的模块。
当我使用imageai模块的时候给我报错,错误指向TensorFlow,我就很奇怪,然后进行Google搜索,前进加速TensorFlow进行搜索,可以搜到相关的,最后我只写一个import TensorFlow 也会报这个错误,最终确定是python版本和TensorFlow版本的不兼容问题。最后我找了快1个小时最终找到一个版本对应关系,所以我又把我的python3.7换成3.6.8版本的,没有找到和3.7对应版本的TensorFlow,所以和我一样老是升级的强迫症以后注意了,浪费不少精力。
版本对应链接:
https://www.tensorflow.org/install/source_windows#cpu
安装指定版本命令
然后我命令安装对应版本:
pip install tensorflow-gpu==1.5.0
pip install tensorflow==1.5
如果你的python有对应的,可以先卸载再安装,pip卸载命令:
pip uninstall tensorflow
pip uninstall tensorflow-gpu