日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > pytorch >内容正文

pytorch

深度学习(二)theano学习笔记(1)环境搭建

發布時間:2025/3/21 pytorch 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 深度学习(二)theano学习笔记(1)环境搭建 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

theano學習筆記(1)環境搭建

原文地址:http://blog.csdn.net/hjimce/article/details/46654229

作者:hjimce

搭建theano實屬不易,因為每個人的電腦不一樣,所以安裝過程會有所區別,特別是安裝cuda的時候,很容易驅動沖突。網上教程一大堆,但是我都沒搭建成功,最后根據官網的教程,一步一步的琢磨,總算功夫不負有心人。因此寫一下艱辛的theano安裝歷程

環境:win7+64位系統?

硬件:筆記本電腦, 顯卡型號:GTX 850M

現在假設電腦啥都沒裝,開始從頭到尾進行環境搭建。

1、安裝Anconda

因為如果安裝純凈版python,還需要自己安裝其它的numpy、matpolt等庫,挺麻煩的。所以我直接安裝集成的Anaconda ,這個軟件包含了Ipython,還有許多python的計算庫。下載地址為:http://www.continuum.io/downloads


因為我是64位系統,因此選擇64位的版本,下載后文件為:Anaconda-2.2.0-Windows-x86_64.exe,下載完成后,就直接雙擊開始安裝,全部都選取默認的就可以了,默認會安裝到:C:\Anconda。

安裝完成后,在window開始菜單下,的所有程序中找到已安裝的Anaconda,如下:

打開Anaconda的命令窗口:Anaconda Command Prompt,然后輸入命令:conda list ? ? ?可以查看Anaconda為我們安裝的python相關的包:


里面有非常多的包,如:numpy, nose, pip, python, scipy。

2、安裝mingw、theano

(1)mingw 安裝

有的Anaconda 是有包含mingw的,不過我下載到的版本安裝完以后上面的包列表中并沒有mingw,也就是C:\Anconda文件下沒有MinGW文件夾,因此需要自己在線安裝。這個如果沒有裝好,后面使用theano的時候會提示:g++ no detect,還有g++不是內部命令什么的。總之如果錯誤提示g++問題,就代表mingw沒有安裝或配置好。

我們在Anaconda命令窗口中,輸入mingw的安裝命令:?conda install mingw。

聲明修改:這一步用命令conda install mingw錯了,最后theano安裝完后,輸入命令“import theano”會出現:no module named gof 的錯誤 。需要把mingw的安裝命令改為:?conda install mingw libpython。才不會出現后面的no module named gof 錯誤



因為我已經安裝過了,所以輸入安裝命令后,提示的是:All requested packages already installed。也就是已經安裝完了,如果還沒有安裝的,它會自動鏈接在線安裝。

mingw安裝完后,在C:\Anconda文件下會出現:名為MinGW的文件夾。

(2)theano 安裝

與mingw的安裝類似,直接在anaconda的命令窗口中輸入命令:pip install theano。接著會自動進行在線安裝,如下所示:


最后安裝成功了會提示:successfully installed theano。

(3)配置環境變量

在桌面上我的電腦右鍵-》屬性-》高級系統設置-》環境變量。即可進入環境變量設置界面如下:


步驟一、在系統環境變量中選擇“變量path”,在后面加入值:“c:\Anaconda\MinGW\bin;c:\Anaconda\MinGW\x86_64-mingw32\lib;”(如果操作系統為32位的變量值輸入為“c:\Anaconda\MinGW\bin;c:\Anaconda\MinGW\i686_w64-mingw32\lib;”)(注意要帶分號)

步驟二、新建環境變量。變量名為“PYTHONPATH”,變量值為“C:\Anaconda\Lib\site-packages\theano;”(同樣注意要帶分號)

步驟三、打開C盤-》用戶-》當前用戶(根據你的電腦用戶而定)。因為我的電腦現在所用的是超級管理員用戶Adminstrator,因此打開Adminstrator用戶


用戶目錄


在用戶Adminstrator下面創建文件名為:“.theanorc.txt”,文件內容為:

“[blas]?
ldflags=


[gcc]?
cxxflags = -IC:\Anaconda\MinGW\include”

即:


ok,到了這里我們已經完成了theano配置的上半部分,這個時候theano已經可以用了,接著需要做個測試,測試一下自己上面的配置有沒有問題。

(4)測試配置是否有誤

測試開始前,需要重啟電腦,因為我們上面配置了環境變量,系統的環境變量設置完了需要重啟電腦才能有效果。

測試方法一、

測試代碼:

[python]?view plaincopy
  • import?numpy?as?np??
  • import?time??
  • import?theano??
  • A?=?np.random.rand(1000,10000).astype(theano.config.floatX)??
  • B?=?np.random.rand(10000,1000).astype(theano.config.floatX)??
  • np_start?=?time.time()??
  • AB?=?A.dot(B)??
  • np_end?=?time.time()??
  • X,Y?=?theano.tensor.matrices('XY')??
  • mf?=?theano.function([X,Y],X.dot(Y))??
  • t_start?=?time.time()??
  • tAB?=?mf(A,B)??
  • t_end?=?time.time()??
  • print?"NP?time:?%f[s],?theano?time:?%f[s]?(times?should?be?close?when?run?on?CPU!)"?%(??
  • ???????????????????????????????????????????np_end-np_start,?t_end-t_start)??
  • print?"Result?difference:?%f"?%?(np.abs(AB-tAB).max(),?)??

  • 把上面的代碼拷貝復制一下,然后用python運行一下結果如下:


    如果上面的np time 和theano time 差不多,那就代表你上面的配置沒有問題了,這個有的時候電腦還有其他的任務,也有可能導致運行的時間不一致。

    測試方案二、

    在python命令窗口中輸入:

    [python]?view plaincopy
  • Import?theano??
  • print?theano.config.blas.ldflags??
  • 沒有出錯(沒有返回值)則說明已經配置成功,如下圖所示,就代表成功了:

    測試方案三、驗證BLAS是否安裝成功。由于numpy是依賴BLAS的,如果BLAS沒有安裝成功,雖然numpy亦可以安裝,但是無法使用BLAS的加速。驗證numpy是否真的成功依賴BLAS編譯,用以下代碼試驗:?

    >>> import numpy? >>> id(numpy.dot) == id(numpy.core.multiarray.dot)? False? 結果為False表示成功依賴了BLAS加速,如果是Ture則表示用的是python自己的實現并沒有加速。 結果如下代表成功:

    3、安裝CUDA

    上面的theano配置只是完成了上半部分,這個時候還不能進行gpu加速。這個時候我們可以用如下命令:

    >>import ?theano

    >>theano.test()

    測試看一下結果如下,這個時候會跳出PyCUDA的相關錯誤信息,因為我們還沒有安裝CUDA。


    OK,接著我們要做的就是安裝CUDA了。具體步驟如下:

    (1)安裝vs根據theano官網的安裝教程,到網站:http://go.microsoft.com/?linkid=9709969? 下載到:VS2010Express1.iso,然后用虛擬光驅打開,然后在打開VCExpress文件,雙擊安裝文件:VCExpress\setup.exe ?

    (2)安裝CUDA。

    a、下載合適的cuda版本。這一步很操蛋,因為我一開始是根據官網教程,到這個網站:https://developer.nvidia.com/cuda-toolkit-55-archive? 根據我是筆記本電腦同時是win7 64位系統,最后下載了cuda_5.5.20_winvista_win7_win8_notebook_64.exe。等了一個小時終于下載完了,下載完后進行安裝,結果一安裝就出現如下錯誤:


    告訴我說圖形驅動與顯卡不兼容,如果繼續安裝,即使安裝成功了,也不能使用cuda。于是我就去下載了個高一點的版本:cuda6.5,等了一個小時終于下載完了,結果一運行還是同樣的錯誤。

    最后我下載了最新的版本:cuda_7.0.28_windows.exe ? 終于沒有錯誤了。因此安裝cuda需要根據電腦的顯卡型號確定,因為我的電腦是剛買不久的,所以顯卡比較先進。

    根據上面的步驟,我的電腦找到了合適版本為cuda7.0版本。接著就需要安裝cuda_7.0.28_windows.exe這玩意了?

    b、安裝cuda。下載完后,直接雙擊安裝,選擇自定義安裝,然后把所有包的都勾選上,省的后面出現什么錯誤。這一步有可能會遇到驅動沖突,導致某些包安裝失敗,比如我第一次安裝的時候,結果圖形驅動包就安裝失敗了。


    如果某些包安裝失敗,后面使用theano的時候,會跳出錯誤。像我圖形驅動安裝失敗,運行theano的時候就出現錯誤提示為cuda版本與驅動版本不一致。因此如果你安裝cuda的過程中,有出現安裝失敗的,那么請你接著往下看。安裝失敗一般是驅動沖突的問題,這個時候我的方法是用驅動精靈卸載掉顯卡驅動,然后在進行安裝。如果是筆記本電腦,因為是雙顯卡的,那么就先卸載掉NVIDIA的,另外一個Intel的驅動保留的著。


    然后在進行安裝CUDA ,還有intel驅動最好是官方驅動,不然也有可能沖突,導致安裝失敗。

    ok,安裝完后測試一下是否安裝正確。

    在命令提示符窗口中輸入:nvcc -V,回車查看是否有版本信息。若出現版本信息,則證明nvcc安裝成功,如下圖所示:


    接著我們運行一個cuda自帶的測試例子,名字為:deviceQuery_vs2012.sln ?,這個例子目錄為:C:\Program Files\NVIDIA Corporation\Installer2\CUDASamples_7.0.{E78AE18E-ED3C-4168-AF5B-561BDF7F2BBB}\1_Utilities\deviceQuery 。我用vs2012打開了deviceQuery_vs2012.sln,并編譯運行得到如下結果,代表安裝成功:


    如果有問題,這個例子運行后,會有錯誤提示信息。

    4、下載并安裝Microsoft Visual C++ Compiler for Python 2.7下載到的文件為:VCForPython27.msi。

    接著在dos命令窗口中,cd到VCForPython27.msi所在的目錄,然后輸入安裝命令:?msiexec?/i?VCForPython27.msi?ALLUSERS=1

    接著會進行安裝VCForPython27.msi。其將被安裝到:?C:\Program?Files?(x86)\Common?Files\Microsoft\Visual?C++?for?Python\9.0.目錄下

    安裝完后,可以到這個目錄下看看有沒有上面這個目錄。

    安裝完了以后,我們新建一個文件名為:stdint.h,其文件內容如下:?

    [cpp]?view plaincopy
  • //?ISO?C9x??compliant?stdint.h?for?Microsoft?Visual?Studio??
  • //?Based?on?ISO/IEC?9899:TC2?Committee?draft?(May?6,?2005)?WG14/N1124???
  • //???
  • //??Copyright?(c)?2006-2013?Alexander?Chemeris??
  • //???
  • //?Redistribution?and?use?in?source?and?binary?forms,?with?or?without??
  • //?modification,?are?permitted?provided?that?the?following?conditions?are?met:??
  • //???
  • //???1.?Redistributions?of?source?code?must?retain?the?above?copyright?notice,??
  • //??????this?list?of?conditions?and?the?following?disclaimer.??
  • //???
  • //???2.?Redistributions?in?binary?form?must?reproduce?the?above?copyright??
  • //??????notice,?this?list?of?conditions?and?the?following?disclaimer?in?the??
  • //??????documentation?and/or?other?materials?provided?with?the?distribution.??
  • //???
  • //???3.?Neither?the?name?of?the?product?nor?the?names?of?its?contributors?may??
  • //??????be?used?to?endorse?or?promote?products?derived?from?this?software??
  • //??????without?specific?prior?written?permission.??
  • //???
  • //?THIS?SOFTWARE?IS?PROVIDED?BY?THE?AUTHOR?``AS?IS''?AND?ANY?EXPRESS?OR?IMPLIED??
  • //?WARRANTIES,?INCLUDING,?BUT?NOT?LIMITED?TO,?THE?IMPLIED?WARRANTIES?OF??
  • //?MERCHANTABILITY?AND?FITNESS?FOR?A?PARTICULAR?PURPOSE?ARE?DISCLAIMED.?IN?NO??
  • //?EVENT?SHALL?THE?AUTHOR?BE?LIABLE?FOR?ANY?DIRECT,?INDIRECT,?INCIDENTAL,??
  • //?SPECIAL,?EXEMPLARY,?OR?CONSEQUENTIAL?DAMAGES?(INCLUDING,?BUT?NOT?LIMITED?TO,??
  • //?PROCUREMENT?OF?SUBSTITUTE?GOODS?OR?SERVICES;?LOSS?OF?USE,?DATA,?OR?PROFITS;??
  • //?OR?BUSINESS?INTERRUPTION)?HOWEVER?CAUSED?AND?ON?ANY?THEORY?OF?LIABILITY,???
  • //?WHETHER?IN?CONTRACT,?STRICT?LIABILITY,?OR?TORT?(INCLUDING?NEGLIGENCE?OR??
  • //?OTHERWISE)?ARISING?IN?ANY?WAY?OUT?OF?THE?USE?OF?THIS?SOFTWARE,?EVEN?IF??
  • //?ADVISED?OF?THE?POSSIBILITY?OF?SUCH?DAMAGE.??
  • //???
  • ///??
  • ??
  • #ifndef?_MSC_VER?//?[??
  • #error?"Use?this?header?only?with?Microsoft?Visual?C++?compilers!"??
  • #endif?//?_MSC_VER?]??
  • ??
  • #ifndef?_MSC_STDINT_H_?//?[??
  • #define?_MSC_STDINT_H_??
  • ??
  • #if?_MSC_VER?>?1000??
  • #pragma?once??
  • #endif??
  • ??
  • #if?_MSC_VER?>=?1600?//?[??
  • #include?<stdint.h>??
  • #else?//?]?_MSC_VER?>=?1600?[??
  • ??
  • #include?<limits.h>??
  • ??
  • //?For?Visual?Studio?6?in?C++?mode?and?for?many?Visual?Studio?versions?when??
  • //?compiling?for?ARM?we?should?wrap?<wchar.h>?include?with?'extern?"C++"?{}'??
  • //?or?compiler?give?many?errors?like?this:??
  • //???error?C2733:?second?C?linkage?of?overloaded?function?'wmemchr'?not?allowed??
  • #ifdef?__cplusplus??
  • extern?"C"?{??
  • #endif??
  • #??include?<wchar.h>??
  • #ifdef?__cplusplus??
  • }??
  • #endif??
  • ??
  • //?Define?_W64?macros?to?mark?types?changing?their?size,?like?intptr_t.??
  • #ifndef?_W64??
  • #??if?!defined(__midl)?&&?(defined(_X86_)?||?defined(_M_IX86))?&&?_MSC_VER?>=?1300??
  • #?????define?_W64?__w64??
  • #??else??
  • #?????define?_W64??
  • #??endif??
  • #endif??
  • ??
  • ??
  • //?7.18.1?Integer?types??
  • ??
  • //?7.18.1.1?Exact-width?integer?types??
  • ??
  • //?Visual?Studio?6?and?Embedded?Visual?C++?4?doesn't??
  • //?realize?that,?e.g.?char?has?the?same?size?as?__int8??
  • //?so?we?give?up?on?__intX?for?them.??
  • #if?(_MSC_VER?<?1300)??
  • ???typedef?signed?char???????int8_t;??
  • ???typedef?signed?short??????int16_t;??
  • ???typedef?signed?int????????int32_t;??
  • ???typedef?unsigned?char?????uint8_t;??
  • ???typedef?unsigned?short????uint16_t;??
  • ???typedef?unsigned?int??????uint32_t;??
  • #else??
  • ???typedef?signed?__int8?????int8_t;??
  • ???typedef?signed?__int16????int16_t;??
  • ???typedef?signed?__int32????int32_t;??
  • ???typedef?unsigned?__int8???uint8_t;??
  • ???typedef?unsigned?__int16??uint16_t;??
  • ???typedef?unsigned?__int32??uint32_t;??
  • #endif??
  • typedef?signed?__int64???????int64_t;??
  • typedef?unsigned?__int64?????uint64_t;??
  • ??
  • ??
  • //?7.18.1.2?Minimum-width?integer?types??
  • typedef?int8_t????int_least8_t;??
  • typedef?int16_t???int_least16_t;??
  • typedef?int32_t???int_least32_t;??
  • typedef?int64_t???int_least64_t;??
  • typedef?uint8_t???uint_least8_t;??
  • typedef?uint16_t??uint_least16_t;??
  • typedef?uint32_t??uint_least32_t;??
  • typedef?uint64_t??uint_least64_t;??
  • ??
  • //?7.18.1.3?Fastest?minimum-width?integer?types??
  • typedef?int8_t????int_fast8_t;??
  • typedef?int16_t???int_fast16_t;??
  • typedef?int32_t???int_fast32_t;??
  • typedef?int64_t???int_fast64_t;??
  • typedef?uint8_t???uint_fast8_t;??
  • typedef?uint16_t??uint_fast16_t;??
  • typedef?uint32_t??uint_fast32_t;??
  • typedef?uint64_t??uint_fast64_t;??
  • ??
  • //?7.18.1.4?Integer?types?capable?of?holding?object?pointers??
  • #ifdef?_WIN64?//?[??
  • ???typedef?signed?__int64????intptr_t;??
  • ???typedef?unsigned?__int64??uintptr_t;??
  • #else?//?_WIN64?][??
  • ???typedef?_W64?signed?int???intptr_t;??
  • ???typedef?_W64?unsigned?int?uintptr_t;??
  • #endif?//?_WIN64?]??
  • ??
  • //?7.18.1.5?Greatest-width?integer?types??
  • typedef?int64_t???intmax_t;??
  • typedef?uint64_t??uintmax_t;??
  • ??
  • ??
  • //?7.18.2?Limits?of?specified-width?integer?types??
  • ??
  • #if?!defined(__cplusplus)?||?defined(__STDC_LIMIT_MACROS)?//?[???See?footnote?220?at?page?257?and?footnote?221?at?page?259??
  • ??
  • //?7.18.2.1?Limits?of?exact-width?integer?types??
  • #define?INT8_MIN?????((int8_t)_I8_MIN)??
  • #define?INT8_MAX?????_I8_MAX??
  • #define?INT16_MIN????((int16_t)_I16_MIN)??
  • #define?INT16_MAX????_I16_MAX??
  • #define?INT32_MIN????((int32_t)_I32_MIN)??
  • #define?INT32_MAX????_I32_MAX??
  • #define?INT64_MIN????((int64_t)_I64_MIN)??
  • #define?INT64_MAX????_I64_MAX??
  • #define?UINT8_MAX????_UI8_MAX??
  • #define?UINT16_MAX???_UI16_MAX??
  • #define?UINT32_MAX???_UI32_MAX??
  • #define?UINT64_MAX???_UI64_MAX??
  • ??
  • //?7.18.2.2?Limits?of?minimum-width?integer?types??
  • #define?INT_LEAST8_MIN????INT8_MIN??
  • #define?INT_LEAST8_MAX????INT8_MAX??
  • #define?INT_LEAST16_MIN???INT16_MIN??
  • #define?INT_LEAST16_MAX???INT16_MAX??
  • #define?INT_LEAST32_MIN???INT32_MIN??
  • #define?INT_LEAST32_MAX???INT32_MAX??
  • #define?INT_LEAST64_MIN???INT64_MIN??
  • #define?INT_LEAST64_MAX???INT64_MAX??
  • #define?UINT_LEAST8_MAX???UINT8_MAX??
  • #define?UINT_LEAST16_MAX??UINT16_MAX??
  • #define?UINT_LEAST32_MAX??UINT32_MAX??
  • #define?UINT_LEAST64_MAX??UINT64_MAX??
  • ??
  • //?7.18.2.3?Limits?of?fastest?minimum-width?integer?types??
  • #define?INT_FAST8_MIN????INT8_MIN??
  • #define?INT_FAST8_MAX????INT8_MAX??
  • #define?INT_FAST16_MIN???INT16_MIN??
  • #define?INT_FAST16_MAX???INT16_MAX??
  • #define?INT_FAST32_MIN???INT32_MIN??
  • #define?INT_FAST32_MAX???INT32_MAX??
  • #define?INT_FAST64_MIN???INT64_MIN??
  • #define?INT_FAST64_MAX???INT64_MAX??
  • #define?UINT_FAST8_MAX???UINT8_MAX??
  • #define?UINT_FAST16_MAX??UINT16_MAX??
  • #define?UINT_FAST32_MAX??UINT32_MAX??
  • #define?UINT_FAST64_MAX??UINT64_MAX??
  • ??
  • //?7.18.2.4?Limits?of?integer?types?capable?of?holding?object?pointers??
  • #ifdef?_WIN64?//?[??
  • #??define?INTPTR_MIN???INT64_MIN??
  • #??define?INTPTR_MAX???INT64_MAX??
  • #??define?UINTPTR_MAX??UINT64_MAX??
  • #else?//?_WIN64?][??
  • #??define?INTPTR_MIN???INT32_MIN??
  • #??define?INTPTR_MAX???INT32_MAX??
  • #??define?UINTPTR_MAX??UINT32_MAX??
  • #endif?//?_WIN64?]??
  • ??
  • //?7.18.2.5?Limits?of?greatest-width?integer?types??
  • #define?INTMAX_MIN???INT64_MIN??
  • #define?INTMAX_MAX???INT64_MAX??
  • #define?UINTMAX_MAX??UINT64_MAX??
  • ??
  • //?7.18.3?Limits?of?other?integer?types??
  • ??
  • #ifdef?_WIN64?//?[??
  • #??define?PTRDIFF_MIN??_I64_MIN??
  • #??define?PTRDIFF_MAX??_I64_MAX??
  • #else??//?_WIN64?][??
  • #??define?PTRDIFF_MIN??_I32_MIN??
  • #??define?PTRDIFF_MAX??_I32_MAX??
  • #endif??//?_WIN64?]??
  • ??
  • #define?SIG_ATOMIC_MIN??INT_MIN??
  • #define?SIG_ATOMIC_MAX??INT_MAX??
  • ??
  • #ifndef?SIZE_MAX?//?[??
  • #??ifdef?_WIN64?//?[??
  • #?????define?SIZE_MAX??_UI64_MAX??
  • #??else?//?_WIN64?][??
  • #?????define?SIZE_MAX??_UI32_MAX??
  • #??endif?//?_WIN64?]??
  • #endif?//?SIZE_MAX?]??
  • ??
  • //?WCHAR_MIN?and?WCHAR_MAX?are?also?defined?in?<wchar.h>??
  • #ifndef?WCHAR_MIN?//?[??
  • #??define?WCHAR_MIN??0??
  • #endif??//?WCHAR_MIN?]??
  • #ifndef?WCHAR_MAX?//?[??
  • #??define?WCHAR_MAX??_UI16_MAX??
  • #endif??//?WCHAR_MAX?]??
  • ??
  • #define?WINT_MIN??0??
  • #define?WINT_MAX??_UI16_MAX??
  • ??
  • #endif?//?__STDC_LIMIT_MACROS?]??
  • ??
  • ??
  • //?7.18.4?Limits?of?other?integer?types??
  • ??
  • #if?!defined(__cplusplus)?||?defined(__STDC_CONSTANT_MACROS)?//?[???See?footnote?224?at?page?260??
  • ??
  • //?7.18.4.1?Macros?for?minimum-width?integer?constants??
  • ??
  • #define?INT8_C(val)??val##i8??
  • #define?INT16_C(val)?val##i16??
  • #define?INT32_C(val)?val##i32??
  • #define?INT64_C(val)?val##i64??
  • ??
  • #define?UINT8_C(val)??val##ui8??
  • #define?UINT16_C(val)?val##ui16??
  • #define?UINT32_C(val)?val##ui32??
  • #define?UINT64_C(val)?val##ui64??
  • ??
  • //?7.18.4.2?Macros?for?greatest-width?integer?constants??
  • //?These?#ifndef's?are?needed?to?prevent?collisions?with?<boost/cstdint.hpp>.??
  • //?Check?out?Issue?9?for?the?details.??
  • #ifndef?INTMAX_C?//???[??
  • #??define?INTMAX_C???INT64_C??
  • #endif?//?INTMAX_C????]??
  • #ifndef?UINTMAX_C?//??[??
  • #??define?UINTMAX_C??UINT64_C??
  • #endif?//?UINTMAX_C???]??
  • ??
  • #endif?//?__STDC_CONSTANT_MACROS?]??
  • ??
  • #endif?//?_MSC_VER?>=?1600?]??
  • ??
  • #endif?//?_MSC_STDINT_H_?]??
  • 然后把它放到目錄

    C:\Program?Files?(x86)\CommonFiles\Microsoft\Visual?C++?for?Python\9.0\VC\include\stdint.h 下面。

    5、重新配置文件.theanorc.txt。把步驟2(3)中建立的文件:.theanorc.txt 內容改為如下內容:

    [cpp]?view plaincopy
  • [blas]???
  • ldflags=??
  • ??
  • [global]??
  • device?=?gpu??
  • floatX?=?float32??
  • ??
  • ??
  • [nvcc]??
  • fastmath=True??
  • flags?=-LC:\Anaconda\libs??
  • compiler_bindir=C:\Program?Files?(x86)\Microsoft?Visual?Studio?10.0\VC\bin??
  • ??
  • [gcc]???
  • cxxflags?=?-IC:\Anaconda\MinGW\include??
  • 這樣就完成了theano的GPU配置了。上面的:

    [cpp]?view plaincopy
  • compiler_bindir=C:\Program?Files?(x86)\Microsoft?Visual?Studio?10.0\VC\bin??
  • 這個如果你的電腦是裝vs2012,那么就把10.0改為11.0。也就是說上面的路徑就是你安裝的vs所在的目錄

    6、完整測試。

    測試的python代碼如下:

    [python]?view plaincopy
  • from?theano?import?function,?config,?shared,?sandbox??
  • import?theano.tensor?as?T??
  • import?numpy??
  • import?time??
  • ??
  • vlen?=?10?*?30?*?768??#?10?x?#cores?x?#?threads?per?core??
  • iters?=?1000??
  • ??
  • rng?=?numpy.random.RandomState(22)??
  • x?=?shared(numpy.asarray(rng.rand(vlen),?config.floatX))??
  • f?=?function([],?T.exp(x))??
  • print?f.maker.fgraph.toposort()??
  • t0?=?time.time()??
  • for?i?in?xrange(iters):??
  • ????r?=?f()??
  • t1?=?time.time()??
  • print?'Looping?%d?times?took'?%?iters,?t1?-?t0,?'seconds'??
  • print?'Result?is',?r??
  • if?numpy.any([isinstance(x.op,?T.Elemwise)?for?x?in?f.maker.fgraph.toposort()]):??
  • ????print?'Used?the?cpu'??
  • else:??
  • ????print?'Used?the?gpu'??
  • 運行結果如下:

    (1)GPU測試

    下面是用GPU加速的運行結果:

    如上運行結果可知,用gpu進行計算時間差不多是0.68秒左右。如果想切換成只用cpu的測試的話,我是通過更改文件:.theanorc.txt的內容。如果開啟gpu,那么.theanorc.txt的內容為:

    [python]?view plaincopy
  • [blas]???
  • ldflags=??
  • ??
  • [global]??
  • device?=?gpu??
  • floatX?=?float32??
  • ??
  • ??
  • [nvcc]??
  • fastmath=True??
  • flags?=-LC:\Anaconda\libs??
  • compiler_bindir=C:\Program?Files?(x86)\Microsoft?Visual?Studio?10.0\VC\bin??
  • ??
  • [gcc]???
  • cxxflags?=?-IC:\Anaconda\MinGW\include??

  • (2)CPU測試。如果想關閉gpu,進行cpu測試那么就把.theanorc.txt內容改為:

    [python]?view plaincopy
  • [blas]???
  • ldflags=??
  • ??
  • ??
  • ??
  • [gcc]???
  • cxxflags?=?-IC:\Anaconda\MinGW\include??
  • 還有需要重啟電腦。不知道有沒有更好的在gpu與cpu切換的方法,如果有請不吝指導,因為我這個方法每次都要重啟,下面是測試結果圖:

    測試了結果,只用cpu花了13秒的時間,也就是說對于我的電腦,使用gpu進行加速,這速度提高了近20倍。

    本文地址:http://blog.csdn.net/hjimce/article/details/46654229?? ? 作者:hjimce ? ? 聯系qq:1393852684 ??更多資源請關注我的博客:http://blog.csdn.net/hjimce? ? ? ? ? ? ? ? 原創文章,轉載請保留本行信息。

    參考文獻:

    1、http://deeplearning.net/software/theano/install_windows.html#install-windows

    2、http://blog.163.com/yuyang_tech/blog/static/216050083201469101518900/

    附錄:

    1、在調用theano.test()測試的時候,如果出現:no ?module ?name ?theano 的錯誤,表明要么沒有安裝,theano。如果確保已經安裝了,那么就是你:高級-》環境變量 的路徑沒有設置好。

    上面的環境變量設置:“C:\Anaconda\Lib\site-packages\theano;”查看一下是否有這個目錄。比如我另外一臺電腦安裝的時候,不知怎么回事,theano的安裝目錄竟然是大寫的:Theano,一直不知道錯在哪


    from:?http://blog.csdn.net/hjimce/article/details/46654229

    總結

    以上是生活随笔為你收集整理的深度学习(二)theano学习笔记(1)环境搭建的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。