# Install Pytorch on Win11 WSL2 ## [0-Install the GPU driver] https://developer.nvidia.com/cuda/wsl Download and install NVIDIA GeForce Game Ready or NVIDIA RTX Quadro Windows 11 display driver on your system with a compatible GeForce or NVIDIA RTX/Quadro card from https://developer.nvidia.com/cuda/wsl ## [1-Install WSL2 & ...] ``` $ wsl --install -d Ubuntu-18.04 $ sudo add-apt-repository universe $ sudo apt-get update $ sudo apt-get install python3-pip $ sudo pip3 install virtualenv virtualenvwrapper $ sudo rm -rf ~/get-pip.py ~/.cache/pip $ vi ~/.bashrc add 4 lines at the bottom of file # virtualenv and virtualenvwrapper export WORKON_HOME=$HOME/.virtualenvs export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 source /usr/local/bin/virtualenvwrapper.sh $ source ~/.bashrc ``` ## [2-Install Cuda] ``` 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.4.0/local_installers/cuda-repo-wsl-ubuntu-11-4-local_11.4.0-1_amd64.deb sudo dpkg -i cuda-repo-wsl-ubuntu-11-4-local_11.4.0-1_amd64.deb sudo apt-key add /var/cuda-repo-wsl-ubuntu-11-4-local/7fa2af80.pub sudo apt-get update sudo apt-get -y install cuda ``` ### nVidia Version ``` $ nvtop $ nvidia-smi $ nvidia-smi -q $ nvidia-smi -l 1 $ cd /mnt/c/Users/'Nico Huang'/Desktop ``` ## [3-Install Jetson inference files only] ``` $ sudo apt-get update $ sudo apt-get install git cmake libpython3-dev python3-numpy $ git clone --recursive https://github.com/dusty-nv/jetson-inference ``` ## [4-Create pytorch virtual environment named pytorch] ``` $ mkvirtualenv pytorch -p python3 $ workon pytorch // do everytime before training # $ deactivate ``` ## [5-Install PyTorch] https://pytorch.org/get-started/locally/ ### CUDA 11.0 https://pytorch.org/get-started/previous-versions/ ``` pip3 install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html ``` Successfully installed: - dataclasses-0.8 - numpy-1.19.5 - pillow-8.4.0 - torch-1.7.1+cu110 - torchaudio-0.7.2 - torchvision-0.8.2+cu110 - typing-extensions-4.0.0 ### Verifying PyTorch ``` (pytorch) nico@Nico-ZenBook15:~$ python3 Python 3.6.9 (default, Jan 26 2021, 15:33:00) [GCC 8.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import torch >>> print(torch.__version__) 1.7.1+cu110 >>> print('CUDA available: ' + str(torch.cuda.is_available())) CUDA available: True >>> a = torch.cuda.FloatTensor(2).zero_() >>> print('Tensor a = ' + str(a)) Tensor a = tensor([0., 0.], device='cuda:0') >>> b = torch.randn(2).cuda() >>> print('Tensor b = ' + str(b)) Tensor b = tensor([-0.7677, 0.7887], device='cuda:0') >>> c = a + b >>> print('Tensor c = ' + str(c)) Tensor c = tensor([-0.7677, 0.7887], device='cuda:0') >>> >>> import torchvision >>> print(torchvision.__version__) 0.8.2+cu110 ``` ### install image processing libraries including OpenCV (optional) ``` $ pip install opencv-contrib-python $ pip install scikit-image $ pip install pillow $ pip install imutils ``` ## [6-Jetson Re-training on the Cat/Dog Dataset] ``` $ cd jetson-inference/python/training/classification/data $ wget https://nvidia.box.com/shared/static/o577zd8yp3lmxf5zhm38svrbrv45am3y.gz -O cat_dog.tar.gz $ tar xvzf cat_dog.tar.gz $ cd jetson-inference/python/training/classification $ python3 train.py --model-dir=models/cat_dog data/cat_dog $ python3 onnx_export.py --model-dir=models/cat_dog ```
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.