Install PyTorch development environment on Windows 10 and verify YOLOv8
Recently, I built a Windows machine and planned to install a deep learning development environment on it, and build and deploy YOLOv8 for training and testing;
Environment:
OS: Windows 10
Graphics card: RTX 3090
Install NVIDIA driver
Find the corresponding driver according to the graphics card model and install it
verify
Enter in the terminal: nvidia-smi
check whether it is installed correctly
PS F:\workspace\notebook> nvidia-smi
Tue Aug 15 09:23:21 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 528.24 Driver Version: 528.24 CUDA Version: 12.0 |
|-------------------------------+----------------------+----------------------+
| 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 ... WDDM | 00000000:01:00.0 On | N/A |
| 30% 38C P8 19W / 350W | 782MiB / 24576MiB | 4% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 1620 C+G C:\Windows\System32\dwm.exe N/A |
| 0 N/A N/A 1908 C+G ...ge\Application\msedge.exe N/A |
Install Visual Studio 2019 Community
Install VS2019Visual Studio Community 2019
verify
Install Git, CMake, Anaconda
install git ,
tortoisegit can see file status
Install cmake , used for cross-platform compilation;
Install Anaconda , which integrates many python
development environments
verify
Download and install OpenCV
VC version number | VS corresponding version |
---|---|
vc6 | VC6.0 |
vc7 | VS2002 |
vc7.1 | VS2003 |
vc8 | VS2005 |
vc9 | VS2008 |
vc10 | VS2010 |
vc11 | VS2012 |
vc12 | VS2013 |
vc13 | VS2014 |
vc14 | VS2015 |
vc15 | VS2017 |
vc16 | VS2019 |
Since the above installation is VS 2019, then we install the VC16 version of OpenCV, so as not to compile it by ourselves;
After decompressing and installing, add build
the directory under the directory x64\vc16\bin
to the environment variable.
Install CUDA and CUDNN
Some people here may not know what version of cuda needs to be installed. Because my GPU here is an N card 3090, it is still relatively good, so I can install a relatively high-end version of the software, but it cannot be too new. I will directly refer to which one of the latest version of the framework in PyTorch depends on?
[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-MNJC1PNc-1692070277630)(image.png)]
Ok, then install CUDA 11.8 and the corresponding CUDNN 8;
cudnn download corresponding version
Note: cudnn needs to register an account
After decompression, copy all the folders under the cudnn folder to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\
the directory.
verify
(base) D:\>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:41:10_Pacific_Daylight_Time_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0
Go to the installation directory C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\extras\demo_suite
, run.\deviceQuery.exe
Install PyTorch
conda install
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
pip install
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
verify
(base) D:\>python
Python 3.11.4 | packaged by Anaconda, Inc. | (main, Jul 5 2023, 13:38:37) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
2.0.1
>>> torch.cuda.is_available()
True
>>>
ultralytics/YOLOv8
Create a virtual environment
conda create --name yolov8 --clone base
Activate the virtual environment
conda activate yolov8
Install
pip install ultralytics
Code https://github.com/ultralytics/ultralytics
Weights https://github.com/ultralytics/assets/releases
verify
yolo predict model=yolov8n.pt imgsz=640 conf=0.25
(yolov8) F:\workspace\yolov8>yolo predict model=yolov8n.pt imgsz=640 conf=0.25
WARNING 'source' is missing. Using default 'source=D:\anaconda3\envs\yolov8\Lib\site-packages\ultralytics\assets'.
Ultralytics YOLOv8.0.154 Python-3.11.4 torch-2.0.1 CUDA:0 (NVIDIA GeForce RTX 3090, 24576MiB)
YOLOv8n summary (fused): 168 layers, 3151904 parameters, 0 gradients
image 1/2 D:\anaconda3\envs\yolov8\Lib\site-packages\ultralytics\assets\bus.jpg: 640x480 4 persons, 1 bus, 1 stop sign, 160.2ms
image 2/2 D:\anaconda3\envs\yolov8\Lib\site-packages\ultralytics\assets\zidane.jpg: 384x640 2 persons, 1 tie, 154.0ms
Speed: 41.6ms preprocess, 157.1ms inference, 72.6ms postprocess per image at shape (1, 3, 384, 640)
Results saved to runs\detect\predict
【reference】
Verify that pytorch is the GPU version
YOLOv8 environment construction (Windows11)
YOLOv8 from environment construction to reasoning training