在原生Windows安裝Keras


既然要深入學習,就不能和時代脫節,所以選擇了keras,資源相對比較豐富。由於Windows飽受歧視,各種文檔都不推薦使用。但我又沒有換系統的成本,所以還是湊合下,畢竟他們給出了方法,稍微折騰一下還是可以的。參考整合了鏈接[1-2]的tensorflow安裝教程和鏈接[4]的keras安裝教程,感謝原作者!

一、python。

單純的肯定不方便:所以先裝上anaconda。集成度很高,非常給力,不然各種scipy啥的會搞得很麻煩。注意版本的選擇,python 3.5~3.6可以,因為tensorflow只支持3.5+的。

二、cuda/cudnn。(CPU版本TensorFlow忽略)

TensorFlow分為CPU版和GPU版,如果你打算安裝GPU版,請先安裝如下兩個驅動:

1、CUDA安裝:https://developer.nvidia.com/cudnn(要注冊Nvidia用戶,並加入CuDNN開發組,填若干問卷就可以下載了)選擇下載版本時要注意和Cuda版本匹配。解壓后覆蓋至CUDA的安裝目錄下

例如:C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\

三、pip。

需要切換到國內的鏡像,過會才能提高安裝的速度和成功率。win7在user目錄中創建一個pip目錄,如:C:\Users\xx\pip,創建pip.ini,寫入以下內容:

    [global]  
    index-url = http://mirrors.aliyun.com/pypi/simple/  
    [install]  
    trusted-host=mirrors.aliyun.com 

上面是阿里雲,其它的國內鏡像還有以下,其他設置詳見文后鏈接[3]:

清華:https://pypi.tuna.tsinghua.edu.cn/simple

阿里雲:http://mirrors.aliyun.com/pypi/simple/

中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/

華中理工大學:http://pypi.hustunique.com/

山東理工大學:http://pypi.sdutlinux.org/ 

豆瓣:http://pypi.douban.com/simple/

四、tensorflow。

官方說明鏈接[1]給出了安裝最新tf的方法,如果遇到問題可以參考。但他用conda命令,所以我們用pip快點。打開anaconda prompt輸入pip install --upgrade tensorflow回車。如果是GPU版本,輸入pip install --upgrade tensorflow-gpu即可。裝完了測試下(IPython中),能輸出結果32就是成功的。

>>>import tensorflow as tf  
>>>sess = tf.Session()  
>>>a = tf.constant(10)  
>>>b = tf.constant(22)  
>>>print(sess.run(a + b)) 

五、keras。

文檔給的方法是輸入pip install keras -U --pre,可是我試了多次失敗,后來去掉參數-U可以了,因為-U會強制更新相關的包,有時候就怎么都裝不好了。我下的最新anaconda,里面的包應該不需要強制更新,所以用pip install keras --pre即可安裝。裝完了測試下,能正常運行就是成功,他給的示例數據下載的比較慢,需要開啟科學上網才行:

>>> conda install git
>>> git clone https://github.com/fchollet/keras.git
>>> cd keras/examples/
>>> python mnist_mlp.py

附上anaconda添加國內鏡像的方法:

>>>conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
>>>conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
>>>conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/

add改成remove可以刪除。順便可以開啟地址顯示

>>>conda config --set show_channel_urls yes

上海大學的鏡像也開通了,見[5]。

推薦鏈接:

[1]https://www.tensorflow.org/install/install_windows

[2]http://blog.csdn.net/include1224/article/details/53452824

[3]http://www.cnblogs.com/microman/p/6107879.html

[4]http://keras-cn.readthedocs.io/en/latest/for_beginners/keras_windows/

[5]https://www.v2ex.com/t/407892


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM