Before we actually start the installation process of the GPU-accelerated Python API of TensorFlow on a Windows platform, we shortly outline what TensorFlow actually is.
What is TensorFlow?
- TensorFlow is an open-source software library for machine learning that was originally invented by Google’s Brain Team but the code was open sourced in November 2015. It comprises a collection of resources for flexibly defining machine learning models, train them with data, and exporting them for further use. In particular, TensorFlow is useful for building and training the different types of neural networks.
- TensorFlow is available on several desktop platforms such as Windows, Linux and macOS as well as on mobile computing platforms.
- TensorFlow can run on multiple CPUs and GPUs (with optional CUDA extensions for general-purpose computing on graphics processing units).
- TensorFlow provides APIs for Python, C++, Haskell, Java, Go, and Rust. Third party packages are available for C#, Julia, R, and Scala.
How to install TensorFlow on Windows?
In this section we sketch how to install the Python API of TensorFlow in Windows using the GPU-acceleration capabilities. We assume that a Nvidia GPU is already installed in the Windows system:
The installation of a GPU is usually straightforward in Windows. We therefore skip this part completely.
TensorFlow’s official installation guideline provides a not that comprehensive description of the installation process. We therefore provide a more elaborated and detailed description, which should be understand as a supplementary to the official guidance.
Microsoft’s Visual C++, Nvidia’s CUDA Development Tools & Nvidia’s cuDNN
well as cuDNN Installation Guide. To this end, I recommend to install the version 8.0 of the CUDA toolkit and version 5.1 of cuDNN as listed below.
- First, we need to get a C++ compiler and an IDE up and running since this is a prerequisite for a working CUDA environment. In this post we are going to install the free Visual Studio 2015 Community edition that comprises a powerful IDE as well as a suitable compiler.According to Table 2 of the official Nvidia CUDA Installation Guide for Microsoft Windows you need to have installed specific compiler versions for specific Visual Studio versions. In our case we need to install the Microsoft Visual C++ 14.0 compiler as we are going to install Visual Studio 2015. If the compiler is already installed it should look like the following:
- Second, the CUDA Development Tools version 8.0 should be installed. I recommend to follow the official Nvidia CUDA Installation Guide for Microsoft Windows and to chose the express full installation including the CUDA samples (which is the default setting). Provided that the installation of the Visual Studio incl. the compiler has been successful, the CUDA Toolkit installation procedure is basically just clicking through. If you have installed the wrong version of the Visual Studio and corresponding compiler you will realize it as a message will pop up in the course of the installation process;
- Third, Nvidia’s cuDNN, version 5.1 (for CUDA toolkit version 8.0) needs to be installed. To this end, you need to sign up and log in to Nvidia’s website.The installation process of cuDNN is to extract the downloaded files, to copy those files into the right folder and to make sure that the corresponding path is known to the operating system;
- Fourth, ensure that the system environment variables such as
CUDA_PATH_V8_0are set correctly:
Please ensure that the path to the file
cudnn64_5.dll(for the cuDNN version 5.1) is set as displayed in the selected variable of exhibit “Path System Environment Variables for CUDA and cuDNN“. In addition, make also sure that “.DLL” files are included in the
- Finally, I highly recommend to validate your C++/CUDA installation.
Click the Windows start symbol and browse through the programs to find the Nvidia Corporation folder. Open the entry that is called Browse CUDA sample. The standard installation path of the CUDA samples is given in the following exhibit.
From there enter the folder
1_Utilities/deviceQueryand double-click the 2015 VC++ Project file named
deviceQuery_vs2015.vcxproj. Since we have already installed Microsoft Visual 2015 in the first step of this post your operating system should be able to open the file. Then build the corresponding exe file and open the file
deviceQuery.exein the corresponding Debug folder which is in our case
C:\ProgramData\NVIDIA Corporation\CUDA Samples\v8.0\bin\win64\Debug\. Open a command box and run this exe file. The output should look like the following:
BTW, you can use this little program to request detailed information about your GPU. For instance, the exact number of CUDA cores, the memory clock rate and the total amount of global memory are listed.
If you would like to chose another suitable program to check your CUDA system feel free to do so. There is, for instance, a folder
0_Simple\simpleMultiGPUthat you can also build and execute to double-check the CUDA installation.
You should also call
nvcc -Vcommand in a prompt. This command provides you with the installed version of the toolkit:
One possibility how to validate the cuDNN installation is described in this stack-overflow post.
After the long preparation phase we can finally install Python on Windows. There are several ways to install Python. I recommend to install the latest version of Anaconda Python framework.
Even though the installation of Anaconda via the installation routine may be straightforward, I suggest to double-check whether the
PATH variable (please see above) is set correctly. You can double-check this by executing
python in a command prompt.
After the installation of Anaconda, we first create a new Python environment to encapsulate the installation from other Python projects. This can be either done via Conda commands (
conda create -n tensorflow-gpu python=X.Y.Z) or via the graphical interface of Anaconda. Second, we need to install the package
In order to create a new Python environment using Anaconda Navigator we simply need to click the “Create” button and name the new environment. The respective button is highlighted in the exhibit above. Alternatively, we could also use the command box executing
conda install tensorflow-gpu.
We can activate an environment by clicking the symbol on the right of the environment.
Then we select the tensorflow-gpu package on the right-hand side of the Anaconda Navigator and install it as sketched in the following:
After pressing the “Apply” button the respective packages will be installed. Alternatively, we could also use the command prompt executing
conda install tensorflow-gpu.
Now, your TensorFlow should be up and running. In order to validate this, use the command prompt and enter the following:
import tensorflow as tf # Creates a graph. with tf.device('/gpu:0'): a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a') b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b') c = tf.matmul(a, b) # Creates a session with log_device_placement set to True. sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) # Runs the op. print(sess.run(c))
You should be good to go!
Kabla ya sisi kweli kuanza mchakato wa ufungaji wa GPU-accelerated Python API ya TensorFlow juu ya jukwaa la Windows, sisi kwa ufupi maelezo ya chini nini TensorFlow kweli ni. TensorFlow ni nini? TensorFlow ni maktaba ya programu ya chanzo wazi kwa ajili ya kujifunza mashine ambayo awali ilibuniwa na Google Brain Team lakini code ilikuwa wazi chanzo katika Novemba 2015. Inajumuisha mkusanyiko wa rasilimali kwa ajili ya kubadilika kufafanua mifano ya kujifunza mashine, mafunzo yao na data, na kuuza nje yao kwa ajili ya matumizi zaidi. Hasa, TensorFlow ni muhimu kwa ajili ya kujenga na mafunzo ya aina tofauti ya mitandao ya neva. TensorFlow inapatikana kwenye majukwaa kadhaa ya desktop kama vile Windows, Linux na macOS na pia kwenye majukwaa ya kompyuta ya rununu. TensorFlow inaweza kukimbia juu ya CPUs nyingi na GPUs (na hiari CUDA upanuzi kwa ajili ya matumizi ya jumla ya kompyuta juu ya vitengo vya usindikaji wa picha). - TensorFlow hutoa APIs kwa Python, C ++, Haskell, Java, Go, na Rust. Vifurushi vya chama cha tatu zinapatikana kwa C #, Julia, R, na Scala. Jinsi ya kufunga TensorFlow kwenye Windows? Katika sehemu hii sisi sketch jinsi ya kufunga Python API ya TensorFlow katika Windows kutumia GPU-kuharakisha uwezo. Nvidia GPU imewekwa kwenye mfumo wa Windows, na kwa kawaida ni rahisi kuanzisha GPU. Kwa hiyo tunaruka sehemu hii kabisa. TensorFlow rasmi ufungaji mwongozo hutoa si kwamba maelezo ya kina ya mchakato wa ufungaji. Kwa hiyo tunatoa maelezo zaidi na ya kina, ambayo inapaswa kueleweka kama nyongeza ya mwongozo rasmi. Microsoft Visual C ++, Nvidia's CUDA Development Tools na Nvidia's cuDNN pamoja na Mwongozo wa Usanidi wa cuDNN. Kwa hivyo, tunapendekeza kuanzisha toleo la 8.0 la seti ya zana ya CUDA na toleo la 5.1 la cuDNN kama ilivyoorodheshwa hapa chini. - Kwanza, tunahitaji kupata C ++ compiler na IDE juu na mbio tangu hii ni sharti la kwanza kwa ajili ya kazi CUDA mazingira. Kwa mfano, kwa mfano, Visual Studio 2015 Community Edition, ambayo ni pamoja na programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu ya programu. Kwa mfano, kwa mfano, tunahitaji kuanzisha programu ya Microsoft Visual C ++ 14.0 ili kuanzisha Visual Studio 2015. Ikiwa compiler tayari imewekwa inapaswa kuonekana kama ifuatavyo: - Pili, CUDA Development Tools toleo 8.0 inapaswa kuwekwa. Kufuata Nvidia CUDA Installation Guide kwa Microsoft Windows na kuchagua Express Full Installation pamoja na sampuli za CUDA ni chaguo la msingi. Kwa hivyo, kwa sababu ya kuunganisha Visual Studio, Kwa kuwa programu ya kuhariri imepita kwa muda mrefu, mchakato wa kuanzisha CUDA Toolkit ni rahisi na rahisi. Ikiwa umeweka toleo lisilofaa la Visual Studio na compiler inayolingana utagundua kama ujumbe utaibuka wakati wa mchakato wa usakinishaji; - Tatu, Nvidia's cuDNN, toleo la 5.1 (kwa CUDA toolkit toleo la 8.0) inahitaji kuwekwa. Kuanzisha na kuanzisha tovuti ya NVIDIA, unahitaji kuanzisha mchakato wa kuanzisha na kuanzisha faili ya NVIDIA, na kuhakikisha kuwa njia inayofaa inajulikana kwa mfumo wa uendeshaji. - Kuimarisha kwamba vigezo vya mazingira ya mfumo kama vile CUDA_PATH_V8_0 ni sahihi: Tafadhali kuhakikisha kwamba njia ya faili ya NVIDIA CUDN645.DLL (kwa ajili ya toleo la cuDN 5.1) ni kama inavyoonyeshwa katika vigezo vya mazingira vya kuonyesha. Aidha, pia kuhakikisha kwamba <unk>.DLL<unk> faili ni pamoja na katika - Hatimaye, mimi sana kupendekeza kuthibitisha C ++ yako <unk> CUDA ufungaji. Bonyeza ishara ya kuanza Windows na kuvinjari kupitia programu kupata folda Nvidia Corporation. "Kuchunguza ""Browse CUDA sampuli""" Njia ya kawaida ya ufungaji wa sampuli za CUDA hutolewa katika maonyesho yafuatayo. Kuanzia hapo, ingiza folda 1_Utilities_DeviceQuery na bonyeza mara mbili faili ya mradi wa 2015 VC++ inayoitwa deviceQuery_vs2015.vcxproj. Kwa kuwa tayari tumeweka Microsoft Visual 2015 katika hatua ya kwanza ya chapisho hili, mfumo wako wa uendeshaji unapaswa kuwa na uwezo wa kufungua faili. "Kisha fanya kazi na faili ya ""Debug"" na ufungue faili ya ""Device.exe"" na folda ya ""Debug"" ambayo katika kesi yetu ni C: ""ProgramData"" na ""NVIDIA Corporation"" na ""CUDA Samples"" na ""V8.0"" na ""Win64"" na ""Debug.""" Fungua sanduku la amri na kukimbia faili hii exe. Kwa mfano, unaweza kutumia programu hii ndogo ili kuomba habari za kina kuhusu GPU yako. Kwa mfano, idadi halisi ya CUDA cores, kumbukumbu clock kasi na kiasi cha jumla ya kumbukumbu ya kimataifa ni waliotajwa. Kama unataka kuchagua programu nyingine inayofaa kuangalia mfumo wako CUDA kujisikia huru kufanya hivyo. Kwa mfano, kuna folda 0_SimpleMultiGPU ambayo unaweza pia kujenga na kutekeleza mara mbili kuangalia ufungaji CUDA. Unapaswa pia wito nvcc -Vcommand katika haraka. Amri hii inatoa wewe na imewekwa toleo la toolkit: Moja ya uwezekano jinsi ya kuthibitisha kuanzisha cuDNN ni ilivyoelezwa katika hii stack-overflow post. Baada ya awamu ya muda mrefu ya maandalizi tunaweza hatimaye kufunga Python juu ya Windows. Kuna njia kadhaa za kufunga Python. Mimi kupendekeza kufunga toleo la hivi karibuni la Anaconda Python mfumo. Hata ingawa ufungaji wa Anaconda kupitia utaratibu wa ufungaji inaweza kuwa moja kwa moja, mimi kupendekeza mara mbili kuangalia kama PATH variable (tafadhali angalia juu) ni kuweka kwa usahihi. Unaweza mara mbili kuangalia hii kwa kutekeleza python katika amri ya haraka. Baada ya ufungaji wa Anaconda, sisi kwanza kuunda mazingira mapya Python encapsulate ufungaji kutoka miradi mingine Python. Hii inaweza kufanyika ama kupitia amri Conda ( conda kuunda -n tensorflow-gpu python=X.Y.Z) au kupitia interface graphical ya Anaconda. Pili, tunahitaji kufunga mfuko Ili kuunda mazingira mapya ya Python kwa kutumia Anaconda Navigator tunahitaji tu kubonyeza kitufe cha <unk>Create<unk> na jina mazingira mapya. kifungo husika ni highlighted katika maonyesho juu. Vinginevyo, tunaweza pia kutumia command box kutekeleza conda kufunga tensorflow-gpu. Tunaweza kuamsha mazingira kwa kubonyeza ishara upande wa kulia wa mazingira. Kisha sisi kuchagua tensorflow-gpu mfuko juu ya upande wa kulia wa Anaconda Navigator na kufunga kama sketched katika zifuatazo: Baada ya kubonyeza <unk>Apply<unk> kifungo vifurushi husika itakuwa imewekwa. Vinginevyo, tunaweza pia kutumia amri prompt kutekeleza conda kufunga tensorflow-gpu. Sasa, TensorFlow yako inapaswa kuwa juu na mbio. Ili kuthibitisha hii, kutumia amri prompt na kuingia zifuatazo: kuagiza tensorflow kama tf # Inaunda grafu. "Kama ""Tf"" (Tf = constant, ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant,"" ""Tf = constant, ""Tf = constant,"" ""Tf = constant, ""Tf""" "Tf: ""Session"" (config = ""Tf: ConfigProto"" (log_device_placement = ""True"")" print(sess.run(c)) Unapaswa kuwa mzuri kwenda!