This tutorial will show you how to install TensorFlow with GPU support on Windows. You will need an NVIDIA graphics card that supports CUDA, as TensorFlow still only officially supports CUDA (see here: https://www.tensorflow.org/install/gpu).
If you are on Linux or macOS, you can likely install a pre-made Docker image with GPU-supported TensorFlow. This makes life much easier. See here for details (this article is about a year old, so a few things might be out of date). However, for those of us on Windows, we need to do things the hard way, as there is no NVIDIA Docker support on Windows.
See this article if you would like to install TensorFlow on Windows without GPU support.
Prerequisites
Install Tensorflow (CPU) in PyCharm in Windows, click Create New Project, give the folder a name (ex. Go to File - Settings, search for Porject Interpreter, ensure that corresponding python version is used as the To install tensorflow, use pip. Updated for 2019! This video walks you through a complete Python 3.7 and TensorFlow install. You will be shown the difference between Anaconda and Miniconda, and how to create a 3.6 environment inside of Anaconda for TensorFlow. Also discusses some of the ramifications coming with TensorFlow 2.0.
To start, you need to play the version tracking game. First, make sure your graphics card can support CUDA by finding it on this list: https://developer.nvidia.com/cuda-gpus.
For example, my laptop has a GeForce GTX 1060, which supports CUDA and Compute Capability 6.1.
You can find the model of your graphics card by clicking in the Windows search bar and entering “dxdiag.” This tool will identify your system’s hardware. The Display tab should list your graphics card (if present on your computer).
Install Tensorflow Python 3.7 Windows 10
Then, we need to work backwards, as TensorFlow usually does not support the latest CUDA version (note that if you compile TensorFlow from source, you can likely enable support for the latest CUDA, but we won’t do that here). Download torrent for mac pro download. Take a look at this chart to view the required versions of CUDA and cuDNN.
Install Tensorflow Python 3.7 Windows Xp
At the time of writing, this is the most recent TensorFlow version and required software:
Version | Python version | Compiler | Build tools | cuDNN | CUDA |
---|---|---|---|---|---|
tensorflow_gpu-2.2.0 | 3.5-3.8 | MSVC 2019 | Bazel 2.0.0 | 7.4 | 10.1 |
Take a note of the particular required software versions listed for the particular TensorFlow version you wish to use. While you could compile TensorFlow from source to support newer versions, it’s much easier to install the specific versions listed here so we can install TensorFlow using pip.
Install Microsoft Visual C++ Compiler
The CUDA Toolkit uses the Microsoft Visual C++ (MSVC) compiler. The easiest way to install it is through Microsoft Visual Studio.
Download and install Visual Studio Community (which is free) from this site: https://visualstudio.microsoft.com/vs/community/. Yes, it’s a full IDE that we won’t use–we just need the compiler that comes with it.
Install CUDA Toolkit
Navigate to the CUDA Toolkit site. Note the CUDA version in the table above, as it’s likely not the latest CUDA release. So, you’ll need to click on Legacy Releases. Download the CUDA Toolkit version that is required for the TensorFlow version you wish to install. For me, that would be CUDA Toolkit 10.1 update2.
Download the installer for your operating system (which is probably Windows 10). I used the exe (network) installer so that it downloads only the required components.
Run the installer. It will take a few minutes to scan your system. Once scanning is done, accept the license agreement and select Custom (Advanced) install.
Deselect the components you don’t need. For example, we likely won’t be developing custom CUDA kernels, so deselect Nsight Compute and Nsight Systems. I don’t have a 3D monitor, so I’ll deselect 3D Vision. I’ll keep PhysX selected for gaming, but feel free to deselect it, as it’s not needed by TensorFlow. You can leave everything else selected.
Click Next. Leave the installation directories as default (if you wish) and click Next again to download and install all of the drivers and toolkit. This will take a few minutes. Close the installer when it finishes.
Install cuDNN
GPU-accelerated TensorFlow relies on NVIDIA cuDNN, which is a collection of libraries used to run neural networks with CUDA.
Head to https://developer.nvidia.com/rdp/cudnn-download. Create an NVIDIA Developer account (or login if you already have one). Ignore the cuDNN version listed in the TensorFlow version table (in the Prerequisites section). Instead, download the version that corresponds to the CUDA version you just installed.
For example, I just installed CUDA 10.1, so I’m going to download cuDNN 7.6.5.
When you click the cuDNN link, you’ll be asked to select your operating system, which is probably Windows 10.
The next part is a bizarre and seemingly old-fashioned method of installing a library. The full instructions can be found on this NVIDIA page (see section 3: Installing cuDNN on Windows).
Unzip the downloaded archive. Navigate into the unzipped directory and copy the following files into the CUDA installation directory (* being any files found with the listed file extension, and vxx.x is the CUDA version you installed).
Copy <cuDNN directory>cudabin*.dll to C:Program FilesNVIDIA GPU Computing ToolkitCUDAvxx.xbin
Copy <cuDNN directory>cudainclude*.h to C:Program FilesNVIDIA GPU Computing ToolkitCUDAvxx.xinclude
Torrent for mac download free. Copy <cuDNN directory>cudalibx64*.lib to C:Program FilesNVIDIA GPU Computing ToolkitCUDAvxx.xlibx64
Next, we need to update our environment variables. Open Control Panel > System and Security > System > Advanced System Settings.
Click Environment Variables at the bottom of the window.
In the new window and in the System variables pane, select the Path variable and click Edit in the System variables pane.
You should see two CUDA entries already listed.
If you do not see these listed, add the following directories to this Path list (where vxx.x is your CUDA version number):
- C:Program FilesNVIDIA GPU Computing ToolkitCUDAvxx.xbin
- C:Program FilesNVIDIA GPU Computing ToolkitCUDAvxx.xlibnvvp
Click OK on the three pop-up windows to close out of the System Properties.
Install TensorFlow
You can install TensorFlow any way you wish, but I highly recommend doing so through Anaconda. It makes installing Python, various packages, and managing environments much easier.
Head to anaconda.com. Download the Individual Edition for your operating system (Windows x64). Anaconda comes pre-packaged with Python set at a particular version, so you will need to note the version of Python required by TensorFlow in the Prerequisites section. For me, I need something between 3.5-3.8. As a result, Python 3.7 that comes with Anaconda (at the time of writing) works fine.
Run the Anaconda installer, accepting all the defaults.
When it’s done, run the Anaconda Prompt (anaconda3).
In the terminal, we’ll create a new Python environment, which will help us keep this version of TensorFlow separate from the non-GPU version. Enter the following commands:
Enter the following command to make sure that you are working with the version of Python you expect:
Install Tensorflow Anaconda Windows Python 3.7
If you wish to use a different version of Python, you can enter the following command (where x.x is the version of Python you want, such as 3.7):
Don’t forget to check to make sure the version of TensorFlow you wish to install supports that version of Python.
If you wish to also install Jupyter Notebook, you can do that with:
Rather than let pip try to figure out which version of TensorFlow you want (it will likely be wrong), I recommend finding the exact .whl file from TensorFlow’s site. Head to the TensorFlow Pip Installer page and look at the Package Location list.
Look under the Windows section for the wheel file installer that supports GPU and your version of Python. For me, this will be the wheel file listed with Python 3.7 GPU support. Note that GPU support (_gpu), TensorFlow version (-2.2.0), and supported Python version (-cp37) are listed in the filename. Highlight and copy the URL with the .whl file you want.
In Anaconda, enter the following command, replacing <wheel_url> with the URL that you copied in the previous step (i.e. paste it in).
Press ‘enter’ and let this run. It will take a few minutes.
When that’s done, go into the Python command line interface:
From there, enter the following commands (one at a time):
Install Tensorflow Windows Python 3.7
These will tell you if TensorFlow is capable of running on your graphics card. The first line imports TensorFlow, the second line makes sure it can work with CUDA (it should output “True”), and the third line should list the GPUs available to TensorFlow.
Note that if you see any weird errors about missing Windows DLL files (whether in the Anaconda prompt, within Python, or in Jupyter Notebook), try the following from within Anaconda:
Close the Anaconda prompt.
Running TensorFlow
Install Tensorflow Python 3.7 Windows 7
When you’re ready to do some machine learning stuff, open the Anaconda Prompt and enter the following:
From there, you can use Python in Anaconda or start a Jupyter Notebook session (see here for a good overview of how to work with Jupyter Notebook):
If you wish to install a new Python package, like matplotlib, you can enter the following into the Anaconda Prompt (make sure you are in your environment, tensorflow-gpu, and exit Jupyter Notebook by pressing ctrl+c):
Alternatively, you can install a package from within Jupyter Notebook by running the following command in a cell:
For example, here is how I installed matplotlib:
Going Further
Install Tensorflow Python 3.7 Windows 10
I hope this helps you get started using TensorFlow on your GPU! Thanks to Anaconda, you can install non-GPU TensorFlow in another environment and switch between them with the conda activate
command. If the GPU version starts giving you problems, simply switch to the CPU version.
See the following videos if you are looking to get started with TensorFlow and TensorFlow Lite: