TensorFlow的幾個問題

 

https://blog.csdn.net/weixin_42081389/article/details/88799552
文章目錄
1、Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2問題
**錯誤提醒:**
問題解決:
2、版本警告問題
警告提醒:
解決方法
3、ImportError: cannot import name 'ops'
4、TensorFlow模塊導入出現ImportError: DLL load failed: 找不到指定的模塊。
版本對應鏈接:
安裝指定版本命令
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
1
第一個問題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
1
問題解決:
對此問題可以直接在代碼中加入:

import os

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
1
2
3
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.
1
2
3

意思是下一個版本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
1
2
問題解決結果中沒有了警告:


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'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
問題我也是找了好久,定位到最終問題是導入下面這個模塊的問題,

from tensorflow.python.framework import ops as tf_ops
1
最後還是通過Google搜索到,最終解決。意思好像就是tensorflow和keras倆個模塊不支持當前的python版本。

我最終找到解決參考連接(好像需要翻牆):https://stackoverflow.com/questions/51076277/cannot-import-name-ops-python

解決方法:

pip install tensorflow --upgrade
pip install keras --upgrade
1
2
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
1
2
如果你的python有對應的,可以先卸載再安裝,pip卸載命令:

pip uninstall tensorflow
pip uninstall tensorflow-gpu
1
2
點贊 5
————————————————
版權聲明:本文爲CSDN博主「奮鬥吧-皮卡丘」的原創文章,遵循 CC 4.0 BY 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/weixin_42081389/java/article/details/88799552

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章