backprop64 / DAMM

A codebase for tracking laboratory mice in videos
10 stars 1 forks source link

Local Windows Installation Using WSL2 #3

Closed matiasandina closed 1 month ago

matiasandina commented 7 months ago

We finally managed to install DAMM on windows using WSL. A nice thing was that we could install cuda 11.3 even though our windows box has cuda 12.2. This made it much easier to deal with the requirement installation (we just followed pip install -r requirements-gpu.txt). Here's a re-cap of what we did. This might not be reproducible in another machine, but it's as close as we could get to make it reproducible on our end.

Check the cuda version on the windows side. This cuda version does not match the required by DAMM. We will attempt to install different cuda in WSL first

C:\Users\dlc>nvidia-smi                                                                                             
 Fri Mar 22 13:28:44 2024                                                                                         
+---------------------------------------------------------------------------------------+                            
| NVIDIA-SMI 536.23                 Driver Version: 536.23       CUDA Version: 12.2     |                            
|-----------------------------------------+----------------------+----------------------+                            
| GPU  Name                     TCC/WDDM  | Bus-Id        Disp.A | Volatile Uncorr. ECC |                            
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |                            
|                                         |                      |               MIG M. |                            
|=========================================+======================+======================|                            
|   0  NVIDIA GeForce RTX 3080 Ti   WDDM  | 00000000:01:00.0  On |                  N/A |                            
|  0%   38C    P8              24W / 370W |   2161MiB / 12288MiB |      3%      Default |                            
|                                         |                      |                  N/A |                            
+-----------------------------------------+----------------------+----------------------+ 
+---------------------------------------------------------------------------------------+                            
| Processes:                                                                            |                            
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |                            
|        ID   ID                                                             Usage      |                            
|=======================================================================================|                            
|    0   N/A  N/A      2344    C+G   ...on\122.0.2365.80\msedgewebview2.exe    N/A      |                            
|    0   N/A  N/A      7400    C+G   C:\Windows\explorer.exe                   N/A      |                            
|    0   N/A  N/A      8596    C+G   ...crosoft\Edge\Application\msedge.exe    N/A      |                            
|    0   N/A  N/A      9372    C+G   ...2txyewy\StartMenuExperienceHost.exe    N/A      |                            
|    0   N/A  N/A      9728    C+G   ....Search_cw5n1h2txyewy\SearchApp.exe    N/A      |                            
|    0   N/A  N/A     10328    C+G   ...CBS_cw5n1h2txyewy\TextInputHost.exe    N/A      |                            
|    0   N/A  N/A     10956    C+G   ...ekyb3d8bbwe\PhoneExperienceHost.exe    N/A      |                            
|    0   N/A  N/A     10992    C+G   ...t.LockApp_cw5n1h2txyewy\LockApp.exe    N/A      |                            
|    0   N/A  N/A     12596    C+G   ...5n1h2txyewy\ShellExperienceHost.exe    N/A      |                            
|    0   N/A  N/A     12716    C+G   ...siveControlPanel\SystemSettings.exe    N/A      |                            
|    0   N/A  N/A     13952    C+G   ...oogle\Chrome\Application\chrome.exe    N/A      |                            
|    0   N/A  N/A     14208    C+G   ....Search_cw5n1h2txyewy\SearchApp.exe    N/A      |                            
|    0   N/A  N/A     14572    C+G   ...cal\Microsoft\OneDrive\OneDrive.exe    N/A      |                            
|    0   N/A  N/A     15172    C+G   ...Brain Explorer 2\BrainExplorer2.exe    N/A      |                            
+---------------------------------------------------------------------------------------+       

Make sure wsl is WSL2

You might have wsl version 1 installed. If that's the case, to upgrade your WSL from version 1 to version 2, you'll need to follow this series of steps. WSL 2 offers significant improvements over WSL 1, including full system call compatibility, and is required for running Docker and GPU-accelerated applications. Here’s how you can upgrade:

Step 1: Ensure Your Windows Version Supports WSL 2

WSL 2 requires Windows 10 Version 1903 or higher, with Build 18362 or higher for x64 systems, and Version 2004 or higher with Build 19041 or higher for ARM64 systems.

Check Your Windows Version: Press Win + R, type winver, and press Enter to check your Windows version and build number.

Step 2: Enable WSL and Virtual Machine Platform

Enable WSL: Open PowerShell as Administrator and run:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Enable Virtual Machine Platform: Still in PowerShell, execute:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Restart Your Computer.

Step 3: Set WSL 2 as Your Default Version

Set WSL 2 as Default: Open PowerShell as Administrator and run:

wsl --set-default-version 2

Step 4: Upgrade Your Existing WSL 1 Distributions

Upgrade Your Distro: If you have existing distributions installed under WSL 1, you’ll need to upgrade them individually. You can check your installed distributions and their WSL versions by running:

wsl -l -v
For each distribution that you want to upgrade, execute:
wsl --set-version <distribution name> 2

Replace with the actual name of your distribution, e.g., Ubuntu.

Verify the Upgrade: Use wsl -l -v again to ensure your distributions are now running under WSL 2.

For example

C:\Users\dlc>wsl --set-version Ubuntu 2
Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Conversion complete.

C:\Users\dlc>wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Stopped         2

Get into wsl

C:\Users\dlc>wsl                                                                                                    
 (base) dlc@DESKTOP-2PSHMD4:/mnt/c/Users/dlc$
(base) dlc@DESKTOP-2PSHMD4:/mnt/c/Users/dlc$ conda deactivate # if needed because (base) autostart                

Everything that follows is inside wsl.

Install cuda version in wsl

CAUTION: Notice we will be working under /mnt/c/Users/dlc, that's the Windows partition, not the Ubuntu classical /home/dlc. You can do this anywhere you like but, in order to reproduce the behavior, paths are important (also avoiding to clone the repos in many different places).

Check the compiler. We didn't need to build from source, but if you need to build stuff, you might need gcc to be working.

(damm_env) dlc@DESKTOP-2PSHMD4:/mnt/c/Users/dlc$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0                                                                           Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   

To get cuda toolkit 11.3 (the version needed by DAMM), execute:

wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.3.0/local_installers/cuda-repo-wsl-ubuntu-11-3-local_11.3.0-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-11-3-local_11.3.0-1_amd64.deb
sudo cp /var/cuda-repo-wsl-ubuntu-11-3-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda-toolkit-11-3

Try to check if the cuda version is proper

nvcc --version

Even if the installation went properly, you might get:

dlc@DESKTOP-2PSHMD4:/mnt/c/Users/dlc$ nvcc --version
Command 'nvcc' not found, but can be installed with:
sudo apt install nvidia-cuda-toolkit

Check the install again

# check install
ls /usr/local | grep cuda
cuda                                                                                                                cuda-11                                                                                                             cuda-11.3 

Export paths and check nvcc again.

export PATH=/usr/local/cuda-11.3/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.3/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

dlc@DESKTOP-2PSHMD4:/mnt/c/Users/dlc$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Mar_21_19:15:46_PDT_2021
Cuda compilation tools, release 11.3, V11.3.58
Build cuda_11.3.r11.3/compiler.29745058_0

Create virtual environment for DAMM

conda create --name damm_env python=3.9
conda activate damm_env

If you haven't cloned the repo yet, you can do this inside (damm_env)

git clone https://github.com/backprop64/DAMM.git
cd DAMM
pip install -r requirements-gpu.txt # this will install the requirements for DAMM

Get the network weights

To get the default model weights do:

wget https://www.dropbox.com/s/39a690qldduxawz/DAMM_weights.pth
wget https://www.dropbox.com/s/wegw8l5zq3vqln0/DAMM_config.yaml

Try that the install is running

You can follow the tutorial on colab to get an idea of how to configure the tracker with a video