GPU DeepLabCut install (Under Windows and with NVIDIA GPU) - LizbethMG/DLC_PoseAnalysis GitHub Wiki
GPU DeepLabCut Installation (Windows and NVIDIA GPU)
At one point, I felt like the stars ⭐ needed to align perfectly to get DeepLabCut installed for GPU usage. Okay, maybe not the stars, but a bunch of other things do need to match up! To save you from this cosmic struggle (and mostly as a self-reminder), I've compiled a list of instructions that have worked for me. While the official website from the Mackenzie Mathis lab provides excellent instructions, I found that I needed additional help for my specific setup. This compilation includes the steps I followed and that worked for me. These steps should also work for you if you're using Windows and have an NVIDIA GPU.
Table of Contents
- I. Introduction
- II. Your GPU
- III. MCVS Install
- IV. CUDA Toolkit
- V. Tensorflow
- VI. DeepLabCut
- VII. Test Your Installation
- VIII. Configuration Examples
I. Introduction
First, some explanation so you understand what you will be doing next:
What is CUDA?
In simple terms, CUDA is a tool from NVIDIA that allows developers to use their graphics cards to perform complex calculations quickly, not just for graphics purposes. Your CUDA installation must match your NVIDIA driver capabilities.
What is MCVS and why do I need it?
MCVS (Microsoft Visual Studio) is an IDE that also includes the Microsoft C++ compiler and other tools. The CUDA toolkit needs it to compile and build CUDA applications on Windows. If you don't have it already installed or if you don't have a compatible version, during CUDA installation you will receive a warning message saying 'No supported version of Visual Studio was found...' and things might not work properly afterward. You need the correct version of MCVS for your CUDA installation.
What is TensorFlow?
TensorFlow is a software library created by Google for building and training machine learning models. It is used by DeepLabCut. Your TensorFlow version needs to match the CUDA version because it relies on CUDA to communicate correctly with the GPU. Luckily, according to DeepLabCut (checked as of May 2024), all TensorFlow versions work with DeepLabCut.
❓ Now, how do I know what versions to install and in what order? The tricky part about the installation process is that certain things have to match ( NVIDIA, CUDA, driver, MCVS, tensorflow) and the they have to be installed in a specific order as explained in the following sections. Please make sure you read the WHOLE guide first, before you start downloading software.
II. Your GPU
If you are here is because your computer has an NVIDIA GPU.
-
Take note of your GPU model.
The easiest way to do this is through the Windows Device Manager. 1.1 Open Device Manager: * Press Win + X to open the Power User menu. * Select "Device Manager" from the list. 1.2 Locate Display Adapters: * In the Device Manager window, find and expand the "Display adapters" section.
-
Take note of your GPU model.
Knowing your GPU model, you can now install the NVIDIA driver from the NVIDIA Website. It's pretty straightforward: select your GPU model, Windows version, download, and install.
III. Microsoft Visual Studio Install
-
Identify your compatible CUDA version.
Take note of your NVIDIA driver version for Windows and the maximum CUDA version it supports. To check the driver version, open the terminal and type
nvidia-smi
This command provides information about the NVIDIA GPU devices installed on your system. The NVIDIA driver version will be displayed at the top of the table (e.g., NVIDIA-SMI 546.12).
This command will also display a CUDA version, which is not necessarily the version installed, but rather the maximum version of CUDA that your installed NVIDIA driver supports.
-
Visual Studio installation.
You might have already installed on your computer MCVS (or not). In any case, make sure you have a compatible version: take a look at this website.
In the first table, look for your driver version for Windows (retrieved in STEP II) and find the matching list of CUDA Toolkit Versions.
Look for the Visual Studio version that you need. For example, if your NVIDIA Driver Version is 546.12, you will see that you can install CUDA versions up to 12.4 (as confirmed in STEP II), and that according to this table Visual Studio 2022 and 2019 support CUDA versions 12.x - 11.8. Therefore, in our example Visual Studio 2022 would be your installation option. ✔You can now go ahead and install Visual Studio Community Edition here and, when installing, select Desktop development with C++.❗ Be aware that Microsoft does not allow older versions of Visual Studio to be downloaded in the Community edition (free version) and only provides the latest version. It is possible to get access by joining Visual Studio Dev Essentials or to rollback to a previously installed version.
IV. CUDA Toolkit
CUDA Installation
-
You can now find the CUDA version you need (identified in step III.1) from the CUDA Toolkit Archive. When installing, choose the Express installation.
-
Add CUDA to Path Press the Windows Key and search for "env". Select "Edit the system environment variables" from the results. Click on "Environment Variables…". In the System variables section, select PATH and click "Edit…". If PATH is not listed, click "New" to create it. Add the following directories to the PATH (replace the version number with the one you installed):
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3\libnvvp
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3\extras\CUPTI\lib64
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3\include
-
Restart your computer.
V. Tensorflow Installation
-
Identify tested tensorflow configurations for your CUDA version.
Knowing your CUDA version (step IV.1) refer to this TensorFlow page to identify the tested build configurations for Windows (TensorFlow, Python, and CUDA versions). If your identified CUDA version does not appear in the table (it's a superior version) then you will probably need to install tensorflow-cpu. Read carefully the next steps.
TensorFlow 2.10 was the last TensorFlow release that supported GPU on native-Windows. Starting with TensorFlow 2.11, you will need to install TensorFlow in WSL2, or install tensorflow-cpu and, optionally, try the TensorFlow-DirectML-Plugin. Tensorflow-directml-plugin isn't supported for version 3.11 and later. More info HERE
V. DeepLabCut installation
IMPORTANT CONSIDERATION: According to your Tensorflow version (STEP IV.2) you will need to follow a specific path:
1. Your required Tensorflow version >= TensorFlow 2.11 & Python version <= 3.10**
Copied from the Tensorflow website (May, 2024):
The next steps assume you have already Anaconda installed. Open Anaconda prompt and copy the commands according to the chosen option.
Option 1 Install with Tensorflow-DirectML-Plugin
conda create -n deeplabcut-gpu python=[replace with version number]
conda activate deeplabcut-gpu
python -m pip install tensorflow-cpu==[replace by your choice version number]
or pip install tensorflow-cpu
for last version
python -m pip install tensorflow-directml-plugin
python -m pip install deeplabcut[gui]
Option 2 Install with in WSL2
TODO: I haven't tested this option but check this LINK
2. Your required Tensorflow version <= TensorFlow 2.10
If this is your case do instead:
conda create -n deeplabcut-gpu python=[replace with version number]
conda activate deeplabcut-gpu
python -m pip install tensorflow==[replace by your version number]
python -m pip install deeplabcut[gui]
VII. Test Your Installation
Follow the video to check your install and open the Task Manager on Windows to monitor at the same time your GPU progress. This step uses a test script (not the GUI).
VII. Run the software
✨Simply activate the environment that you created and run the main script:
conda activate deeplabcut-gpu
python -m deeplabcut
Troubleshooting Errors you might find under Windows and with the original testscript.py:
- FileNotFoundError: File /Users/... .h5 does not exist >>
conda install -c conda-forge ffmpeg
- GPU timeout error >>
pip install tensorflow-directml --upgrade
More info HERE - AttributeError of testscript: module ‘matplotlib.cm’ has no attribute ‘get_cmap’ >>
pip install matplotlib==3.7.3
VIII. Configuration Examples
Configurations I have managed to install following these instructions:
-
Config 1
- GPU model: NVIDIA Quadro P1000
- NVIDIA driver version: 546.12, type DCH
- Operating System: Wndows 10 Professionnel
- Python version: 3.7.10
- Deeplabcut version: 2.2rc1
- Cudatoolkit: 10.2.89 with Visual Studio 2019 previously installed.
- cudnn: 7.6.5.32
-
Config 2
- GPU model: NVIDIA GeForce rtx 4080
- NVIDIA driver version: 552.22
- Operating System: Windows 10 Professionnel
- Python version: 3.9
- Tensorflow: tensorflow-cpu 2.16.1 + tensorflow-directml-plugin
- Deeplabcut version: 2.3.9
- Cudatoolkit: 12.3 with Visual Studio 2022 previously installed.
-
Config 3
- GPU model: NVIDIA Quadro RTX 4000
- NVIDIA driver version: 552.86
- Operating System: Windows 10 Professionnel
- Python version: 3.10
- Tensorflow: tensorflow-cpu 2.16.1 + tensorflow-directml-plugin
- Deeplabcut version: 2.3.10.
- Cudatoolkit: 12.3 with Visual Studio 2022 previously installed.