一、安裝cuda和cudnn
1、安裝cuda之前先打開英偉達控制面板查看自己的顯卡信息
2、“幫助”—>“系統信息”—>“組件”,然后看第三行的信息“Nvidia CUDA 12.4”
3、進入英偉達官網“CUDA Toolkit Archive | NVIDIA Developer”,我的是12.4
下載完成后nvcc -V檢查一下是否安裝正確
nvcc -V
查看是否配置環境變量
二、下載CUDNN
cuDNN Archive | NVIDIA Developer
下載好了過后把解壓出來放到CUDAv12.4安裝目錄下
然后配置環境變量
D:\daima\CUDAv12.4\bin
D:\daima\CUDAv12.4\extras\CUPTI\lib64
三、安裝pytorch(帶GPU)
PyTorch
1、
2、
3、找到這個,我的是12.4,安裝12.1的也行
4、安裝ultralytics
pip install ultralytics
5、因為ultralytics自帶是cpu的我們需要卸載cpu版本的pytorch
pip uninstall torch
6、安裝第三步復制的內容
conda install pytorch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 pytorch-cuda=12.1 -c pytorch -c nvidia
7、可以測試一下了(如果不行看最下面)
import ultralytics
ultralytics.checks()
import torch
print(torch.__version__)
print(torch.cuda.is_available())
print(torch.cuda.device_count())
OK
安裝后報錯:ImportError: cannot import name 'COMMON_SAFE_ASCII_CHARACTERS' from 'charset_normalizer.constant' (D:\daima\anaconda3\yolo\lib\site-packages\charset_normalizer\constant.py)
pip install chardet
安裝后報錯:
? ? raise RuntimeError('''
RuntimeError:?
? ? ? ? An attempt has been made to start a new process before the
? ? ? ? current process has finished its bootstrapping phase.
? ? ? ? This probably means that you are not using fork to start your
? ? ? ? child processes and you have forgotten to use the proper idiom
? ? ? ? in the main module:
? ? ? ? ? ? if __name__ == '__main__':
? ? ? ? ? ? ? ? freeze_support()
? ? ? ? ? ? ? ? ...
? ? ? ? The "freeze_support()" line can be omitted if the program
? ? ? ? is not going to be frozen to produce an executable.
需要拿 if __name__ == '__main__':包起來
其它報錯:建議測試把works調成1
YOLO5模型訓練過程_mac訓練yolov5-CSDN博客
YOLO5 6.1版本報錯解決_ranges = np.round(np.linspace(8, 4, 10), 0).astype-CSDN博客